@wezzard/mcp-relay 0.16.0 → 0.17.1

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-relay",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "description": "Runs an agent's code on fresh, isolated VMs, several at once, each run recorded with evidence",
5
5
  "author": {
6
6
  "name": "WeZZard"
package/README.md CHANGED
@@ -7,11 +7,10 @@ it for both Claude Code and pi, the latter loaded through `pi-mcp-adapter`. It
7
7
  is an MCP server: fourteen `relay_*` tools, each with its own schema, title
8
8
  and annotations, and the server's `instructions`. The user command, status,
9
9
  ships as one small command file per host (see "Commands"). There is no skill and no hook. Together they offer recorded,
10
- snapshot-evidenced scripts, commands included as shell scripts, in a fresh, dedicated VM, for any work
11
- the agent chooses to run there; a script drives the desktop or a browser
12
- through the software the image lists, such as cua-driver or Playwright. Nothing here executes local computer-use, spawns
13
- subagents, targets physical machines, records video, or attaches to existing
14
- browsers.
10
+ snapshot-evidenced scripts, commands included as shell scripts, in a fresh, dedicated VM or on a
11
+ durable machine, a real Mac leased whole, for any work the agent chooses to run there; a script drives the desktop or a browser
12
+ through the software the image lists, such as cua-driver or Playwright. Nothing here executes local computer-use on the relay's own host, spawns
13
+ subagents, records video, or attaches to existing browsers.
15
14
 
16
15
  The project was named mcp-vm-relay before v0.12.0. The npm package is now
17
16
  `@wezzard/mcp-relay`, the plugin and its marketplace are `mcp-relay`, and every
@@ -302,6 +301,26 @@ Failed or uncertain launches retain ownership; resolve or cancel the attempt
302
301
  rather than replaying it. Console tests use mocked backends; no live viewer,
303
302
  installation or platform acceptance is claimed here.
304
303
 
304
+ ## Durable machines
305
+
306
+ `relay_acquire` takes `machine` in place of `image` to lease a durable machine,
307
+ a real Mac that machine-service exposes, such as `Build-Mac-1`. Every other
308
+ tool works on it as on a VM ([docs/durable-machines.md](docs/durable-machines.md)).
309
+
310
+ - The relay finds the instance that owns the machine as `machctl list` does:
311
+ the loopback instance, then every `machine-service` registration of the
312
+ Consul agent at `CONSUL_HTTP_ADDR` (default `http://127.0.0.1:8500`). A Mac
313
+ without its own Consul agent points `CONSUL_HTTP_ADDR` at one, for example
314
+ through an SSH tunnel.
315
+ - Every call carries the lease's `lease_id`, files go as bytes, and the relay
316
+ stages under the lease's workspace, which machine-service removes at release.
317
+ - Runs take snapshots only while the Mac's cua-driver daemon (`CuaDriver.app`,
318
+ `com.trycua.driver`) holds Screen Recording, read with
319
+ `cua-driver permissions status --json` in the lease. machine-service's own
320
+ permissions are not read, and it needs no Screen Recording grant.
321
+ - A durable machine is on the home network and not isolated from it, a CI job
322
+ may share its desktop, and it has no console.
323
+
305
324
  ## Selected environments
306
325
 
307
326
  Set `VM_ENVIRONMENT_FILE` to a profile, at `schemaVersion` 2 with
@@ -352,7 +371,8 @@ keeps the VM for a retry after space is freed.
352
371
 
353
372
  - `MCP_RELAY_PROJECT`: the project directory (the plugin passes Claude Code's). Evidence lands under `relay-evidence/<task>/` there. Every host file the relay reads, `relay_stage`'s `workspace` and `files[].local` and `relay_script`'s `localPath`, lies in this folder: a relative path resolves against it, an absolute path must already lie in it, and a path through a symlink is refused.
354
373
  - `MCP_RELAY_SESSION`: an explicit session identity. By default each server process takes a fresh random one; a stable identity lets a restarted server reconcile and reattach the guests of the same identity.
355
- - `MCP_RELAY_URL`: the loopback machine-service origin, default `http://localhost:6240`. Non-loopback servers, redirects and physical targets are refused.
374
+ - `MCP_RELAY_URL`: the loopback machine-service origin, default `http://localhost:6240`. Non-loopback servers and redirects are refused; a durable machine's instance on another Mac is reached only when Consul lists it.
375
+ - `CONSUL_HTTP_ADDR`: the Consul agent that lists machine-service instances, for durable machines; default `http://127.0.0.1:8500`.
356
376
  - `MCP_RELAY_GUEST_NETWORK`: the network every guest is acquired on, `nat` (the default) or `internet`. With `internet`, machine-service gives a guest that reaches the internet and reaches neither this host nor any private network; an application that hosts agents sets it. The agent cannot choose it: `relay_acquire` takes no network. Any other value stops the server at startup and refuses every acquisition, and a machine-service that cannot give `internet` refuses the acquisition with its own reason, never falling back to `nat`.
357
377
  - `MCP_RELAY_ON_EXIT`: what the end of a session does to its guests, `pause` (the default: renewal pauses and the VMs are kept for an explicit finish or release) or `release` (every guest is released, then the server exits). An application that owns its tasks' machines, such as The Desk, sets `release`. Any other value stops the server at startup.
358
378
  - `MCP_RELAY_CAPACITY_WAIT`: how many seconds `relay_acquire` waits when the host is at capacity, such as at machine-service's limit of two running macOS VMs, asking again every 15 s; default 1800, and 0 for not at all. Any other value stops the server at startup.
@@ -362,7 +382,7 @@ keeps the VM for a retry after space is freed.
362
382
  - `MCP_RELAY_SHUTDOWN_GRACE_MS`: how long a session end waits for an in-flight operation, and with `MCP_RELAY_ON_EXIT=release` for the guests' releases, before cancelling it; default 120000.
363
383
  - `MCP_RELAY_PYTHON`: the Python 3 used for the registry lock; default `python3` on PATH.
364
384
  - `VM_ENVIRONMENT_FILE`: a selected environment profile; it overrides the URL, state directory and registry above and binds the Tart store.
365
- - Guest files go to `/var/tmp/<UTC-timestamp>-mcp-relay-<task>/`, with the runtime in `receiver.mjs`, support in `support/` and work in `workspace/`.
385
+ - Guest files go to `/var/tmp/<UTC-timestamp>-mcp-relay-<task>/` on a VM and to `<lease workspace>/work/mcp-relay-<task>/` on a durable machine, with the runtime in `receiver.mjs`, support in `support/` and work in `workspace/`.
366
386
 
367
387
  ## Development
368
388
 
@@ -5,8 +5,9 @@ tools: mcp__plugin_mcp-relay_relay__relay_search, mcp__plugin_mcp-relay_relay__r
5
5
  model: sonnet
6
6
  ---
7
7
 
8
- Work in a dedicated fresh VM through the relay's MCP tools. Probe first to
9
- pick the image the task needs. Acquire one
8
+ Work in a dedicated fresh VM, or on a durable machine (a real Mac named with
9
+ `machine`), through the relay's MCP tools. Probe first to pick the image the
10
+ task needs, or use the durable machine the task names. Acquire one
10
11
  guest for each machine the task needs, and declare every output you will bring
11
12
  home as an extraction before any work. relay_acquire answers the guest's name,
12
13
  `guest`; name it in every later call on that guest. Several guests may run at
@@ -954,9 +954,11 @@
954
954
  "node_modules/zod/v4/mini/parse.js": "b87374f4e821d583f699d83e4b74ac59e4a5a782c510959187a0ba209145d76b",
955
955
  "node_modules/zod/v4/mini/schemas.js": "5614339bbec6b9be13ed1809e1215fe44d78e99f5f0eee848c0bb3b25dc1c9b6",
956
956
  "src/archive.ts": "469ca411558db5696c8790d8a7132108d6705d4316c5a31a149f7472ddbef0ec",
957
+ "src/capture-gate.ts": "6757d7329b62e5b093323eddc779ee13722a0da24ab659649a23a2e70c4fbd56",
957
958
  "src/config.ts": "3fbc475596ec0a1b6122ea963bf2769420a8a2a0e62fda55e66018fb3a6d53b3",
958
959
  "src/console.ts": "d8258173a24449c2a394289b14983b9575c5ce753ab267d4e13213f3abfcb72d",
959
960
  "src/core.ts": "dd889fda6af982ab47b40b346e7fbc41a213b6d258d3d5fe56cd8c5373221159",
961
+ "src/discovery.ts": "80db010052e9a37a00c5f5c1bb525fc95d8026c68ef9cd307eab0e4ec1d48920",
960
962
  "src/doctor.ts": "8249e9fa78b679e9ef7fd30f617bf07848961346101d3b64c42f779cfb042671",
961
963
  "src/downloads.ts": "4f37b5bb4fac96f9260a3a87c83bacf715b9add5ae9926d3fe0994000c70a8dd",
962
964
  "src/environment.ts": "5770e966e49d78ae069614078c667f94e70074b150f83111049529ff613aa215",
@@ -964,19 +966,19 @@
964
966
  "src/guest/image-evidence.ts": "9c5daaed5b33b9912021a91fd79a2e6d5be42c75d37761772a3bd2645d20a55e",
965
967
  "src/guest/receiver.ts": "92fc8d3bfe95ed56d43cfe5b46eb196034ade5e4e9f58ed202465531458f697d",
966
968
  "src/image-presentation.ts": "64ca29a3444a04606cb783c81ac2d0f3136f9a9ac730ae9074156f0a63256c76",
967
- "src/images.ts": "734a30ba34cd80ef0b5c3791232f13b170b06d6d74c4b843d39566d2e09136d0",
968
- "src/machine-service.ts": "777fac0552e2aa63910b6e224c787cf0b2696e7652eab0a734c7c772de3eddf3",
969
- "src/manager.ts": "440c06f3cd42b5f8031e0dca43088225175ca64a956c85e88890e39b8b3ea291",
969
+ "src/images.ts": "415bfb37966a60ef3e407236295b9aeeb314f7fb33de55a6ada512cff6661908",
970
+ "src/machine-service.ts": "9bb169564572304488cf7f33db959186ec2a4f9be9685b84b270cf4cd6f3aee9",
971
+ "src/manager.ts": "03d6c94034378f04089d2af9a0a1bdef2cec028a16d5009019c7c397211ab758",
970
972
  "src/owner-lock.ts": "a99cbaba67b4aff0e646dc5d5967db4497ba6dbda83fb1838c55f0bf0f6e0367",
971
973
  "src/package.ts": "a52ed791813922e3ace9144706ddde8313a67d8580a3acd54a0799de3ebe44d2",
972
974
  "src/probe.ts": "40a123f725aad7c22fe63707dd2de99646cb1f307d7d660927e8ca2b973e9ce0",
973
975
  "src/registry.ts": "87478f1ceef0f06df9b28c064a817383ff153bdadd70e6d58b4a7ed464f66146",
974
976
  "src/review-data.ts": "2e873eb23612fd4502d84e65322006345f4e97bb679109b23dc4d26683200c19",
975
- "src/schema.ts": "110d65d59a2ad3bcd3a35de188f68804dcada9c92702630aaf9de029ba77b5a5",
977
+ "src/schema.ts": "7f68a85c9593fc2ad1455efd6e757c43f8ed591293fd820f1a08408db17c1912",
976
978
  "src/search-diagnostics.ts": "cea037618c56f075d51155101ad1cc0314bfa67b174bdb070191e0ea5ea04679",
977
979
  "src/search.ts": "8aaf544fcb27e7e018bd976e1ba7d3c70c047aeda3182b3dce91873a901a245e",
978
980
  "src/server.ts": "bff4c09c29890aa62175ead36d9cfd6f8fa7334d2ee0929b51a0371d38c5df1c",
979
- "src/surface.ts": "f7772fbafa613aaeba05e47d2def4975fb0ce75d1af067bde968f0e95775f81a",
981
+ "src/surface.ts": "25681325cb01dfb04524bca8e0e5f3d4b4795d3db814384c7d1e9a8ec831eb16",
980
982
  "src/transfer.ts": "f27d65c0b42f9933e6a7f950f56111b84c644e8739bab44805aebfb54d77e320",
981
983
  "src/transport.ts": "35df20b321f52c4a371f1e29923e957e7c85d58001e2864f0fd13c2c2838945f",
982
984
  "src/typebox.ts": "7f071fbc67548c7d3701272dabe88a217812e12e41dfad76974ff08169fa1a7e",
package/dist/doctor.mjs CHANGED
@@ -47,6 +47,8 @@ async function command(argv, options = {}) {
47
47
 
48
48
  // src/machine-service.ts
49
49
  import { isIP } from "node:net";
50
+ import { createHash as createHash2 } from "node:crypto";
51
+ import { open, rm } from "node:fs/promises";
50
52
  var MachineServiceError = class extends Error {
51
53
  constructor(message, status, responseBody, options) {
52
54
  super(message, options);
@@ -69,13 +71,14 @@ function capacityRefusal(error) {
69
71
  }
70
72
  if (!body || typeof body !== "object") return false;
71
73
  const { error: reason, outcome } = body;
72
- return typeof reason === "string" && reason.startsWith("macOS VM limit reached") && outcome !== "uncertain";
74
+ return typeof reason === "string" && /^(macOS VM limit reached|durable machine leased|durable machine unavailable)/.test(reason) && outcome !== "uncertain";
73
75
  }
74
76
  var SERVICE_NAME = "machine-service";
75
77
  function expectMachineService(health, origin) {
76
78
  if (health.service === SERVICE_NAME) return;
77
79
  throw new Error(`The service at ${origin} answers as ${JSON.stringify(health.service ?? null)}, not ${SERVICE_NAME}. This relay speaks only machine-service's /machines API: install machine-service, which replaced vm-service.`);
78
80
  }
81
+ var PULL_IDLE_MS = 12e4;
79
82
  var AcquireIndeterminateError = class extends MachineServiceError {
80
83
  constructor(purpose, cause) {
81
84
  super(`Acquisition outcome unknown for purpose '${purpose}'; reconcile GET /machines before retrying or ending the enclosure`, void 0, void 0, { cause });
@@ -91,8 +94,16 @@ function positive(value, label) {
91
94
  function record(value) {
92
95
  return value !== null && typeof value === "object" && !Array.isArray(value);
93
96
  }
97
+ function named(value) {
98
+ const fields = value;
99
+ if (record(value) && fields.kind === "durable" && typeof fields.vm !== "string" && typeof fields.name === "string") fields.vm = fields.name;
100
+ return value;
101
+ }
94
102
  function isLease(value) {
95
103
  if (!record(value)) return false;
104
+ if (named(value).kind === "durable") {
105
+ return ["vm", "purpose", "lease_id", "workspace"].every((k) => typeof value[k] === "string" && value[k] !== "") && value.image === null && value.image_kind === null && value.state === "leased" && ["created_at", "ttl_expires_at"].every((k) => typeof value[k] === "number" && Number.isFinite(value[k]));
106
+ }
96
107
  return ["vm", "purpose", "image"].every((k) => typeof value[k] === "string" && value[k] !== "") && ["macos", "linux"].includes(String(value.image_kind)) && ["pending", "provisioning", "running", "releasing"].includes(String(value.state)) && ["created_at", "ttl_expires_at"].every((k) => typeof value[k] === "number" && Number.isFinite(value[k])) && ["cpu", "memory_mb", "disk_gb", "grace_until"].every((k) => value[k] === null || typeof value[k] === "number") && ["env", "ip"].every((k) => value[k] === null || typeof value[k] === "string") && typeof value.warned === "boolean";
97
108
  }
98
109
  var MachineService = class {
@@ -108,8 +119,8 @@ var MachineService = class {
108
119
  if (options.environment && url.origin !== new URL(options.environment.profile.vmServiceUrl).origin) throw new TypeError("Backend endpoint does not match the selected environment");
109
120
  const host = url.hostname.replace(/^\[|\]$/g, "");
110
121
  const loopback = host === "localhost" || host === "::1" || isIP(host) === 4 && host.startsWith("127.");
111
- if (!loopback || !["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
112
- throw new TypeError("machine-service baseUrl must be a loopback HTTP(S) origin without credentials, path, query or fragment");
122
+ if (!loopback && !options.listed || !["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
123
+ throw new TypeError("machine-service baseUrl must be a loopback HTTP(S) origin, or one Consul lists as machine-service, without credentials, path, query or fragment");
113
124
  }
114
125
  this.baseUrl = url.origin;
115
126
  this.timeoutMs = positive(options.timeoutMs ?? 66e4, "timeoutMs");
@@ -119,8 +130,10 @@ var MachineService = class {
119
130
  health(options = {}) {
120
131
  return this.request("/health", void 0, options);
121
132
  }
122
- list(options = {}) {
123
- return this.request("/machines", void 0, options);
133
+ async list(options = {}) {
134
+ const list = await this.request("/machines", void 0, options);
135
+ if (record(list.machines)) Object.values(list.machines).forEach(named);
136
+ return list;
124
137
  }
125
138
  images(options = {}) {
126
139
  return this.request("/images", void 0, options);
@@ -147,8 +160,8 @@ var MachineService = class {
147
160
  throw new MachineServiceError(`Console API unavailable or request outcome unknown${error instanceof MachineServiceError && error.status ? ` (HTTP ${error.status})` : ""}; resolve before another open`, error instanceof MachineServiceError ? error.status : void 0);
148
161
  }
149
162
  }
150
- get(vm, options = {}) {
151
- return this.request(this.path(vm), void 0, options);
163
+ async get(vm, options = {}) {
164
+ return named(await this.request(this.path(vm), void 0, options));
152
165
  }
153
166
  /**
154
167
  * Cancellation before dispatch prevents allocation. Once dispatched we deliberately
@@ -181,42 +194,118 @@ var MachineService = class {
181
194
  pull(vm, body, options = {}) {
182
195
  return this.request(this.path(vm, "pull"), body, options);
183
196
  }
184
- heartbeat(vm, body = {}, options = {}) {
185
- return this.request(this.path(vm, "heartbeat"), body, options);
197
+ async heartbeat(vm, body = {}, options = {}) {
198
+ return named(await this.request(this.path(vm, "heartbeat"), body, options));
186
199
  }
187
200
  release(vm, body = {}, options = {}) {
188
201
  return this.request(this.path(vm, "release"), body, options);
189
202
  }
203
+ /**
204
+ * Push one file as bytes, `PUT /machines/<name>/files` (FD-4): the instance
205
+ * checks the digest before it writes, so a client on another Mac needs no
206
+ * host path the instance could read (DC-31).
207
+ */
208
+ async pushBytes(vm, body, options = {}) {
209
+ const sha256 = createHash2("sha256").update(body.bytes).digest("hex");
210
+ const response = await this.fetchBounded(this.filesPath(vm, body.remote_path, body.lease_id), { method: "PUT", headers: { "Content-Type": "application/octet-stream", "X-Content-SHA256": sha256 }, body: new Uint8Array(body.bytes.buffer, body.bytes.byteOffset, body.bytes.byteLength) }, options, this.maxResponseBytes);
211
+ const answer = this.json(response.path, response.text);
212
+ if (answer.sha256 !== sha256 || answer.bytes !== body.bytes.length) throw new MachineServiceError(`machine-service ${response.path}: the instance stored ${answer.bytes} bytes with SHA-256 ${answer.sha256}, not what was sent`);
213
+ return answer;
214
+ }
215
+ /**
216
+ * Pull one file as bytes, `GET /machines/<name>/files`, into `to`, which
217
+ * must not exist. The bytes stream to disk as they are hashed, so a file of
218
+ * any size needs no memory of its size, and the pull is abandoned only when
219
+ * no byte arrives for its timeout. The file is removed unless the bytes
220
+ * match the digest the instance states (DC-31).
221
+ */
222
+ async pullBytes(vm, body, options = {}) {
223
+ const hash2 = createHash2("sha256"), file = await open(body.to, "wx", 384);
224
+ let bytes = 0;
225
+ try {
226
+ const response = await this.fetchBounded(this.filesPath(vm, body.remote_path, body.lease_id), { method: "GET" }, { ...options, timeoutMs: options.timeoutMs ?? PULL_IDLE_MS }, Number.MAX_SAFE_INTEGER, { idle: true, sink: async (chunk) => {
227
+ hash2.update(chunk);
228
+ bytes += chunk.byteLength;
229
+ await file.write(chunk);
230
+ } });
231
+ if (response.contentType !== "application/octet-stream") throw new MachineServiceError(`machine-service ${response.path}: expected one file, got ${response.contentType ?? "no content type"}`);
232
+ const digest = hash2.digest("hex");
233
+ if (!response.sha256 || digest !== response.sha256.toLowerCase()) throw new MachineServiceError(`machine-service ${response.path}: the bytes' SHA-256 ${digest} differs from the stated ${response.sha256 ?? "none"}`);
234
+ await file.sync();
235
+ await file.close();
236
+ return { sha256: digest, bytes };
237
+ } catch (error) {
238
+ await file.close().catch(() => {
239
+ });
240
+ await rm(body.to, { force: true });
241
+ throw error;
242
+ }
243
+ }
244
+ filesPath(vm, remote, lease_id) {
245
+ const query = new URLSearchParams({ ...lease_id ? { lease_id } : {}, path: remote });
246
+ return `${this.path(vm, "files")}?${query}`;
247
+ }
190
248
  path(vm, action) {
191
249
  if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(vm)) throw new TypeError("Invalid VM name");
192
250
  return `/machines/${encodeURIComponent(vm)}${action ? `/${action}` : ""}`;
193
251
  }
194
252
  async request(path, body, options) {
253
+ const response = await this.fetchBounded(path, {
254
+ method: body === void 0 ? "GET" : "POST",
255
+ headers: body === void 0 ? {} : { "Content-Type": "application/json" },
256
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
257
+ }, options, this.maxResponseBytes);
258
+ return this.json(path, response.text);
259
+ }
260
+ json(path, text) {
261
+ try {
262
+ return JSON.parse(text);
263
+ } catch (cause) {
264
+ throw new MachineServiceError(`machine-service ${path}: invalid JSON response`, void 0, void 0, { cause });
265
+ }
266
+ }
267
+ /**
268
+ * One request whose answer is read up to `maxBytes`; an error answer is read
269
+ * up to 4 KiB and thrown with its status. With `sink`, a successful answer is
270
+ * handed over chunk by chunk instead of kept; with `idle`, the timeout counts
271
+ * from the last chunk rather than from the start.
272
+ */
273
+ async fetchBounded(path, init, options, maxBytes, stream = {}) {
195
274
  options.signal?.throwIfAborted();
196
275
  const timeoutMs = positive(options.timeoutMs ?? this.timeoutMs, "timeoutMs");
197
276
  const controller = new AbortController();
198
277
  const abort = () => controller.abort(options.signal?.reason);
199
278
  options.signal?.addEventListener("abort", abort, { once: true });
200
- const timer = setTimeout(() => controller.abort(new MachineServiceError(`machine-service ${path} timed out after ${timeoutMs}ms`)), timeoutMs);
279
+ const expire = () => controller.abort(new MachineServiceError(`machine-service ${path} timed out after ${timeoutMs}ms${stream.idle ? " without a byte" : ""}`));
280
+ let timer = setTimeout(expire, timeoutMs);
201
281
  try {
202
282
  const response = await fetch(`${this.baseUrl}${path}`, {
203
- method: body === void 0 ? "GET" : "POST",
204
- headers: { ...body === void 0 ? {} : { "Content-Type": "application/json" }, ...this.environment ? { "X-VM-Environment-Fingerprint": this.environment.identity.fingerprint } : {} },
205
- ...body === void 0 ? {} : { body: JSON.stringify(body) },
283
+ method: init.method,
284
+ headers: { ...init.headers, ...this.environment ? { "X-VM-Environment-Fingerprint": this.environment.identity.fingerprint } : {} },
285
+ ...init.body === void 0 ? {} : { body: init.body },
206
286
  signal: controller.signal,
207
287
  redirect: "error"
208
- // Do not let a loopback service redirect to remote hosts.
288
+ // Do not let a service redirect to another host.
209
289
  });
210
290
  const reader = response.body?.getReader();
211
291
  const chunks = [];
212
292
  let size = 0;
213
- const bound = response.ok ? this.maxResponseBytes : Math.min(4096, this.maxResponseBytes);
293
+ const bound = response.ok ? maxBytes : Math.min(4096, maxBytes);
214
294
  let truncated = false;
215
295
  if (reader) {
216
296
  try {
217
297
  for (; ; ) {
218
298
  const { value, done } = await reader.read();
219
299
  if (done) break;
300
+ if (stream.idle) {
301
+ clearTimeout(timer);
302
+ timer = setTimeout(expire, timeoutMs);
303
+ }
304
+ if (response.ok && stream.sink) {
305
+ size += value.byteLength;
306
+ await stream.sink(value);
307
+ continue;
308
+ }
220
309
  const remaining = bound - size;
221
310
  chunks.push(value.subarray(0, remaining));
222
311
  size += Math.min(value.byteLength, remaining);
@@ -230,18 +319,14 @@ var MachineService = class {
230
319
  reader.releaseLock();
231
320
  }
232
321
  }
233
- const text = Buffer.concat(chunks).toString("utf8");
322
+ const bytes = Buffer.concat(chunks), text = bytes.toString("utf8");
234
323
  if (!response.ok) throw new MachineServiceError(`machine-service ${path}: HTTP ${response.status}: ${text}${truncated ? " [truncated]" : ""}`, response.status, text);
235
324
  if (truncated) throw new MachineServiceError(`machine-service ${path}: response exceeds ${bound} bytes`);
236
- try {
237
- return JSON.parse(text);
238
- } catch (cause) {
239
- throw new MachineServiceError(`machine-service ${path}: invalid JSON response`, void 0, void 0, { cause });
240
- }
325
+ return { path, bytes, text, contentType: response.headers.get("content-type") ?? void 0, sha256: response.headers.get("x-content-sha256") ?? void 0 };
241
326
  } catch (cause) {
242
327
  if (controller.signal.aborted) throw controller.signal.reason;
243
328
  if (cause instanceof MachineServiceError) throw cause;
244
- throw new MachineServiceError(`machine-service ${path}: request failed`, void 0, void 0, { cause });
329
+ throw new MachineServiceError(`machine-service ${path}: request failed${cause instanceof Error ? `: ${cause.message}` : ""}`, void 0, void 0, { cause });
245
330
  } finally {
246
331
  clearTimeout(timer);
247
332
  options.signal?.removeEventListener("abort", abort);
@@ -251,7 +336,7 @@ var MachineService = class {
251
336
 
252
337
  // src/registry.ts
253
338
  import { randomUUID as randomUUID2 } from "node:crypto";
254
- import { link, lstat, mkdir, open, readFile, realpath, rename, unlink } from "node:fs/promises";
339
+ import { link, lstat, mkdir, open as open2, readFile, realpath, rename, unlink } from "node:fs/promises";
255
340
  import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
256
341
  import { homedir as homedir3 } from "node:os";
257
342
 
@@ -261,7 +346,7 @@ import { isAbsolute as isAbsolute2, join as join2, normalize } from "node:path";
261
346
 
262
347
  // src/environment.ts
263
348
  import { accessSync, constants, lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
264
- import { createHash as createHash2 } from "node:crypto";
349
+ import { createHash as createHash3 } from "node:crypto";
265
350
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
266
351
  import { homedir } from "node:os";
267
352
  import { isIP as isIP2 } from "node:net";
@@ -354,7 +439,7 @@ function loadEnvironment(path, env = process.env, home = env.HOME ?? homedir())
354
439
  for (const other of mutable) if (key !== other && overlaps(value, profile[other])) throw new Error("Environment mutable roots must be disjoint");
355
440
  }
356
441
  const ordered = Object.fromEntries(Object.keys(profile).sort().map((k) => [k, profile[k]]));
357
- const fingerprint = createHash2("sha256").update(JSON.stringify(ordered), "utf8").digest("hex");
442
+ const fingerprint = createHash3("sha256").update(JSON.stringify(ordered), "utf8").digest("hex");
358
443
  const identity = Object.freeze({
359
444
  id: profile.id,
360
445
  fingerprint,
@@ -601,7 +686,7 @@ var Registry = class {
601
686
  const updated = transform(original);
602
687
  if (original === updated) return false;
603
688
  temporary = join3(dirname2(target), `.${target.split("/").at(-1)}.${token}.tmp`);
604
- const handle = await open(temporary, "wx", before.mode & 511);
689
+ const handle = await open2(temporary, "wx", before.mode & 511);
605
690
  try {
606
691
  await handle.chmod(before.mode & 511);
607
692
  await handle.writeFile(updated, "utf8");
@@ -617,7 +702,7 @@ var Registry = class {
617
702
  lock.check();
618
703
  await rename(temporary, target);
619
704
  temporary = void 0;
620
- const dir = await open(dirname2(target), "r");
705
+ const dir = await open2(dirname2(target), "r");
621
706
  try {
622
707
  await dir.sync();
623
708
  } finally {
@@ -644,7 +729,7 @@ var Registry = class {
644
729
  if (!errno(error, "ENOENT")) throw error;
645
730
  }
646
731
  const temporary = join3(dirname2(target), `.registry.${randomUUID2()}.tmp`);
647
- const handle = await open(temporary, "wx", 384);
732
+ const handle = await open2(temporary, "wx", 384);
648
733
  try {
649
734
  try {
650
735
  await handle.chmod(384);
@@ -659,7 +744,7 @@ var Registry = class {
659
744
  } catch (error) {
660
745
  if (!errno(error, "EEXIST")) throw error;
661
746
  }
662
- const dir = await open(dirname2(target), "r");
747
+ const dir = await open2(dirname2(target), "r");
663
748
  try {
664
749
  await dir.sync();
665
750
  } finally {
@@ -1,6 +1,6 @@
1
1
  {
2
- "server.mjs": "59774785e2e9d3e930f7e96fa4b93843a557509137338e76ae9c0a5e93228db1",
2
+ "server.mjs": "7de81a14e4248abfef15cffa78109dfd86a5c84bfdd7ccbacbacebab2954fa80",
3
3
  "receiver.mjs": "8b5b6fdd6cb789cdc4060e367a155cb42e7cf34187044c899789bf76b7bb0e14",
4
- "doctor.mjs": "63003135f4ffae0abbf962e46b6ef3840a2f9c83c46aff3b0b294e498a0d7e32",
4
+ "doctor.mjs": "f40afe5454bf4367ed50357c6fc20886eae69cbb391085bb853322ea29ab88ae",
5
5
  "review-data.mjs": "da7b6b35d060e09cfc445df4febda02a1a0c0f23d9b854866aed8d604cbb3993"
6
6
  }