@wezzard/mcp-relay 0.14.2 → 0.16.0
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/.claude-plugin/plugin.json +1 -1
- package/README.md +66 -48
- package/agents/vm-relay-operator.md +7 -7
- package/dist/build-info.json +13 -13
- package/dist/doctor.mjs +43 -35
- package/dist/integrity.json +3 -3
- package/dist/receiver.mjs +31 -33
- package/dist/server.mjs +135 -143
- package/package.json +1 -1
- package/pi-mcp.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -17197,8 +17197,9 @@ import { createHash } from "node:crypto";
|
|
|
17197
17197
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
17198
17198
|
import { homedir } from "node:os";
|
|
17199
17199
|
import { isIP } from "node:net";
|
|
17200
|
-
var paths = ["imageRepository", "tartHome", "serviceStateDir", "imageStateDir", "relayStateDir", "
|
|
17200
|
+
var paths = ["imageRepository", "tartHome", "serviceStateDir", "imageStateDir", "relayStateDir", "machctlPath", "tartPath"];
|
|
17201
17201
|
var mutable = ["tartHome", "serviceStateDir", "imageStateDir", "relayStateDir"];
|
|
17202
|
+
var LEGACY_PROFILE = "Environment profile is from before the machine-service rename, which reads only schemaVersion 2 with machctlPath: a profile at schemaVersion 1 or with vmctlPath is refused. Rename vmctlPath to machctlPath, naming the machctl executable, and set schemaVersion to 2.";
|
|
17202
17203
|
function canonicalPath(value) {
|
|
17203
17204
|
if (typeof value !== "string" || !isAbsolute(value) || !value.trim() || /[\x00-\x1f\x7f\uD800-\uDFFF]/u.test(value)) throw new Error("Environment paths must be absolute and contain no control characters");
|
|
17204
17205
|
let ancestor = resolve(value);
|
|
@@ -17259,19 +17260,20 @@ function loadEnvironment(path, env = process.env, home = env.HOME ?? homedir())
|
|
|
17259
17260
|
} else if (text4[i] === "{" || text4[i] === "[") depth++;
|
|
17260
17261
|
else if (text4[i] === "}" || text4[i] === "]") depth--;
|
|
17261
17262
|
}
|
|
17263
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && (raw.schemaVersion === 1 || Object.hasOwn(raw, "vmctlPath"))) throw new Error(LEGACY_PROFILE);
|
|
17262
17264
|
const fields = ["schemaVersion", "id", "vmServiceUrl", ...paths].sort();
|
|
17263
17265
|
if (!raw || typeof raw !== "object" || Array.isArray(raw) || JSON.stringify(Object.keys(raw).sort()) !== JSON.stringify(fields)) throw new Error("Environment profile has missing or unknown fields");
|
|
17264
17266
|
const p = raw;
|
|
17265
|
-
if (p.schemaVersion !==
|
|
17266
|
-
const profile = { schemaVersion:
|
|
17267
|
+
if (p.schemaVersion !== 2 || typeof p.id !== "string" || !/^[a-z0-9][a-z0-9-]{0,47}$/.test(p.id)) throw new Error("Invalid environment schemaVersion or id");
|
|
17268
|
+
const profile = { schemaVersion: 2, id: p.id, vmServiceUrl: endpoint(p.vmServiceUrl) };
|
|
17267
17269
|
for (const key of paths) profile[key] = canonicalPath(p[key]);
|
|
17268
17270
|
if (!statSync(profile.imageRepository).isDirectory() || !statSync(join(profile.imageRepository, "images")).isDirectory()) throw new Error("Selected imageRepository must contain images/");
|
|
17269
|
-
for (const key of ["
|
|
17271
|
+
for (const key of ["machctlPath", "tartPath"]) {
|
|
17270
17272
|
if (!statSync(profile[key]).isFile()) throw new Error(`${key} must be a regular executable file`);
|
|
17271
17273
|
accessSync(profile[key], constants.X_OK);
|
|
17272
17274
|
}
|
|
17273
17275
|
const state = env.XDG_STATE_HOME ? canonicalPath(env.XDG_STATE_HOME) : join(canonicalPath(home), ".local/state");
|
|
17274
|
-
const names = ["vm-service", "pilot-images", "mcp-relay", "mcp-vm-relay"];
|
|
17276
|
+
const names = ["machine-service", "vm-service", "pilot-images", "mcp-relay", "mcp-vm-relay"];
|
|
17275
17277
|
const defaults = [join(canonicalPath(home), ".tart"), ...names.map((n) => join(state, n)), ...names.map((n) => join(canonicalPath(home), ".local/state", n))].map(canonicalPath);
|
|
17276
17278
|
for (const key of mutable) {
|
|
17277
17279
|
const value = profile[key];
|
|
@@ -17310,13 +17312,13 @@ function environmentVariables(selected) {
|
|
|
17310
17312
|
VM_ENVIRONMENT_FINGERPRINT: selected.identity.fingerprint,
|
|
17311
17313
|
PILOT_REPO: p.imageRepository,
|
|
17312
17314
|
TART_HOME: p.tartHome,
|
|
17313
|
-
|
|
17315
|
+
MACHINE_SERVICE_STATE: p.serviceStateDir,
|
|
17314
17316
|
PILOT_IMAGES_STATE_DIR: p.imageStateDir,
|
|
17315
17317
|
VM_RELAY_STATE_DIR: p.relayStateDir,
|
|
17316
17318
|
VM_RELAY_URL: p.vmServiceUrl,
|
|
17317
|
-
|
|
17318
|
-
|
|
17319
|
-
|
|
17319
|
+
MACHINE_SERVICE_HOST: url.hostname.replace(/^\[|\]$/g, ""),
|
|
17320
|
+
MACHINE_SERVICE_PORT: String(Number(p.vmServiceUrl.match(/:([0-9]+)$/)[1])),
|
|
17321
|
+
MACHCTL: p.machctlPath,
|
|
17320
17322
|
TART: p.tartPath
|
|
17321
17323
|
};
|
|
17322
17324
|
}
|
|
@@ -17572,12 +17574,12 @@ var Session = class {
|
|
|
17572
17574
|
* persisted before transmission; a transport loss leaves the submission
|
|
17573
17575
|
* inspectable as uncertain, never replayed.
|
|
17574
17576
|
*/
|
|
17575
|
-
async exec(
|
|
17577
|
+
async exec(argv, options = {}) {
|
|
17576
17578
|
const executionId = formatId(allocateId("execution"));
|
|
17577
17579
|
const submission = {
|
|
17578
17580
|
executionId,
|
|
17579
17581
|
sessionId: this.sessionId,
|
|
17580
|
-
argv
|
|
17582
|
+
argv,
|
|
17581
17583
|
submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17582
17584
|
state: "pending"
|
|
17583
17585
|
};
|
|
@@ -17587,7 +17589,7 @@ var Session = class {
|
|
|
17587
17589
|
attemptId: "attempt-1",
|
|
17588
17590
|
kind: "exec",
|
|
17589
17591
|
executionId,
|
|
17590
|
-
argv
|
|
17592
|
+
argv,
|
|
17591
17593
|
cwd: options.cwd,
|
|
17592
17594
|
step: options.step,
|
|
17593
17595
|
snapshots: options.snapshots
|
|
@@ -17613,11 +17615,11 @@ var Session = class {
|
|
|
17613
17615
|
const upload = await this.transport.upload(localPath, { remotePath });
|
|
17614
17616
|
const executionId = formatId(allocateId("execution"));
|
|
17615
17617
|
const interpreter = language2 === "python" ? "python3" : language2 === "typescript" ? "tsx" : "node";
|
|
17616
|
-
const
|
|
17618
|
+
const argv = [interpreter, ...options.interpreterArgs ?? [], remotePath];
|
|
17617
17619
|
const submission = {
|
|
17618
17620
|
executionId,
|
|
17619
17621
|
sessionId: this.sessionId,
|
|
17620
|
-
argv
|
|
17622
|
+
argv,
|
|
17621
17623
|
submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17622
17624
|
state: "pending",
|
|
17623
17625
|
script: {
|
|
@@ -17635,7 +17637,7 @@ var Session = class {
|
|
|
17635
17637
|
executionId,
|
|
17636
17638
|
remotePath,
|
|
17637
17639
|
language: language2,
|
|
17638
|
-
argv
|
|
17640
|
+
argv,
|
|
17639
17641
|
cwd: options.cwd,
|
|
17640
17642
|
step: options.step,
|
|
17641
17643
|
snapshots: options.snapshots,
|
|
@@ -17744,14 +17746,14 @@ var Session = class {
|
|
|
17744
17746
|
// node_modules/@wezzard/relay-driver-host-sdk/dist/src/index.js
|
|
17745
17747
|
init_evidence_package();
|
|
17746
17748
|
|
|
17747
|
-
// src/
|
|
17749
|
+
// src/machine-service.ts
|
|
17748
17750
|
import { isIP as isIP2 } from "node:net";
|
|
17749
|
-
var
|
|
17751
|
+
var MachineServiceError = class extends Error {
|
|
17750
17752
|
constructor(message3, status, responseBody, options) {
|
|
17751
17753
|
super(message3, options);
|
|
17752
17754
|
this.status = status;
|
|
17753
17755
|
this.responseBody = responseBody;
|
|
17754
|
-
this.name = "
|
|
17756
|
+
this.name = "MachineServiceError";
|
|
17755
17757
|
}
|
|
17756
17758
|
status;
|
|
17757
17759
|
responseBody;
|
|
@@ -17759,7 +17761,7 @@ var VmServiceError = class extends Error {
|
|
|
17759
17761
|
capacity = false;
|
|
17760
17762
|
};
|
|
17761
17763
|
function capacityRefusal(error2) {
|
|
17762
|
-
if (!(error2 instanceof
|
|
17764
|
+
if (!(error2 instanceof MachineServiceError) || error2.status !== 409 || !error2.responseBody) return false;
|
|
17763
17765
|
let body;
|
|
17764
17766
|
try {
|
|
17765
17767
|
body = JSON.parse(error2.responseBody);
|
|
@@ -17770,9 +17772,14 @@ function capacityRefusal(error2) {
|
|
|
17770
17772
|
const { error: reason2, outcome } = body;
|
|
17771
17773
|
return typeof reason2 === "string" && reason2.startsWith("macOS VM limit reached") && outcome !== "uncertain";
|
|
17772
17774
|
}
|
|
17773
|
-
var
|
|
17775
|
+
var SERVICE_NAME = "machine-service";
|
|
17776
|
+
function expectMachineService(health, origin) {
|
|
17777
|
+
if (health.service === SERVICE_NAME) return;
|
|
17778
|
+
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.`);
|
|
17779
|
+
}
|
|
17780
|
+
var AcquireIndeterminateError = class extends MachineServiceError {
|
|
17774
17781
|
constructor(purpose, cause) {
|
|
17775
|
-
super(`Acquisition outcome unknown for purpose '${purpose}'; reconcile GET /
|
|
17782
|
+
super(`Acquisition outcome unknown for purpose '${purpose}'; reconcile GET /machines before retrying or ending the enclosure`, void 0, void 0, { cause });
|
|
17776
17783
|
this.purpose = purpose;
|
|
17777
17784
|
this.name = "AcquireIndeterminateError";
|
|
17778
17785
|
}
|
|
@@ -17789,7 +17796,7 @@ function isLease(value) {
|
|
|
17789
17796
|
if (!record2(value)) return false;
|
|
17790
17797
|
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";
|
|
17791
17798
|
}
|
|
17792
|
-
var
|
|
17799
|
+
var MachineService = class {
|
|
17793
17800
|
baseUrl;
|
|
17794
17801
|
environment;
|
|
17795
17802
|
timeoutMs;
|
|
@@ -17803,7 +17810,7 @@ var VmService = class {
|
|
|
17803
17810
|
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
17804
17811
|
const loopback = host === "localhost" || host === "::1" || isIP2(host) === 4 && host.startsWith("127.");
|
|
17805
17812
|
if (!loopback || !["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
|
|
17806
|
-
throw new TypeError("
|
|
17813
|
+
throw new TypeError("machine-service baseUrl must be a loopback HTTP(S) origin without credentials, path, query or fragment");
|
|
17807
17814
|
}
|
|
17808
17815
|
this.baseUrl = url.origin;
|
|
17809
17816
|
this.timeoutMs = positive(options.timeoutMs ?? 66e4, "timeoutMs");
|
|
@@ -17814,7 +17821,7 @@ var VmService = class {
|
|
|
17814
17821
|
return this.request("/health", void 0, options);
|
|
17815
17822
|
}
|
|
17816
17823
|
list(options = {}) {
|
|
17817
|
-
return this.request("/
|
|
17824
|
+
return this.request("/machines", void 0, options);
|
|
17818
17825
|
}
|
|
17819
17826
|
images(options = {}) {
|
|
17820
17827
|
return this.request("/images", void 0, options);
|
|
@@ -17838,7 +17845,7 @@ var VmService = class {
|
|
|
17838
17845
|
try {
|
|
17839
17846
|
return await this.request(path, body, options);
|
|
17840
17847
|
} catch (error2) {
|
|
17841
|
-
throw new
|
|
17848
|
+
throw new MachineServiceError(`Console API unavailable or request outcome unknown${error2 instanceof MachineServiceError && error2.status ? ` (HTTP ${error2.status})` : ""}; resolve before another open`, error2 instanceof MachineServiceError ? error2.status : void 0);
|
|
17842
17849
|
}
|
|
17843
17850
|
}
|
|
17844
17851
|
get(vm, options = {}) {
|
|
@@ -17857,12 +17864,12 @@ var VmService = class {
|
|
|
17857
17864
|
const timeoutMs2 = positive(options.timeoutMs ?? this.acquireTimeoutMs, "timeoutMs");
|
|
17858
17865
|
try {
|
|
17859
17866
|
const lease = await this.request("/acquire", body, { timeoutMs: timeoutMs2 });
|
|
17860
|
-
if (!isLease(lease)) throw new
|
|
17867
|
+
if (!isLease(lease)) throw new MachineServiceError("Invalid machine-service acquire response");
|
|
17861
17868
|
return lease;
|
|
17862
17869
|
} catch (error2) {
|
|
17863
|
-
const safeError = body.vnc ? new
|
|
17864
|
-
if (safeError instanceof
|
|
17865
|
-
if (error2 instanceof
|
|
17870
|
+
const safeError = body.vnc ? new MachineServiceError(`VNC acquisition refused or outcome unknown${error2 instanceof MachineServiceError && error2.status ? ` (HTTP ${error2.status})` : ""}; inspect capabilities and reconcile ownership`, error2 instanceof MachineServiceError ? error2.status : void 0) : error2;
|
|
17871
|
+
if (safeError instanceof MachineServiceError) safeError.capacity = capacityRefusal(error2);
|
|
17872
|
+
if (error2 instanceof MachineServiceError && error2.status !== void 0 && error2.status >= 400 && error2.status < 500) throw safeError;
|
|
17866
17873
|
throw new AcquireIndeterminateError(body.purpose, safeError);
|
|
17867
17874
|
}
|
|
17868
17875
|
}
|
|
@@ -17883,7 +17890,7 @@ var VmService = class {
|
|
|
17883
17890
|
}
|
|
17884
17891
|
path(vm, action) {
|
|
17885
17892
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(vm)) throw new TypeError("Invalid VM name");
|
|
17886
|
-
return `/
|
|
17893
|
+
return `/machines/${encodeURIComponent(vm)}${action ? `/${action}` : ""}`;
|
|
17887
17894
|
}
|
|
17888
17895
|
async request(path, body, options) {
|
|
17889
17896
|
options.signal?.throwIfAborted();
|
|
@@ -17891,7 +17898,7 @@ var VmService = class {
|
|
|
17891
17898
|
const controller = new AbortController();
|
|
17892
17899
|
const abort = () => controller.abort(options.signal?.reason);
|
|
17893
17900
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
17894
|
-
const timer = setTimeout(() => controller.abort(new
|
|
17901
|
+
const timer = setTimeout(() => controller.abort(new MachineServiceError(`machine-service ${path} timed out after ${timeoutMs2}ms`)), timeoutMs2);
|
|
17895
17902
|
try {
|
|
17896
17903
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
17897
17904
|
method: body === void 0 ? "GET" : "POST",
|
|
@@ -17925,17 +17932,17 @@ var VmService = class {
|
|
|
17925
17932
|
}
|
|
17926
17933
|
}
|
|
17927
17934
|
const text4 = Buffer.concat(chunks).toString("utf8");
|
|
17928
|
-
if (!response.ok) throw new
|
|
17929
|
-
if (truncated) throw new
|
|
17935
|
+
if (!response.ok) throw new MachineServiceError(`machine-service ${path}: HTTP ${response.status}: ${text4}${truncated ? " [truncated]" : ""}`, response.status, text4);
|
|
17936
|
+
if (truncated) throw new MachineServiceError(`machine-service ${path}: response exceeds ${bound} bytes`);
|
|
17930
17937
|
try {
|
|
17931
17938
|
return JSON.parse(text4);
|
|
17932
17939
|
} catch (cause) {
|
|
17933
|
-
throw new
|
|
17940
|
+
throw new MachineServiceError(`machine-service ${path}: invalid JSON response`, void 0, void 0, { cause });
|
|
17934
17941
|
}
|
|
17935
17942
|
} catch (cause) {
|
|
17936
17943
|
if (controller.signal.aborted) throw controller.signal.reason;
|
|
17937
|
-
if (cause instanceof
|
|
17938
|
-
throw new
|
|
17944
|
+
if (cause instanceof MachineServiceError) throw cause;
|
|
17945
|
+
throw new MachineServiceError(`machine-service ${path}: request failed`, void 0, void 0, { cause });
|
|
17939
17946
|
} finally {
|
|
17940
17947
|
clearTimeout(timer);
|
|
17941
17948
|
options.signal?.removeEventListener("abort", abort);
|
|
@@ -18331,20 +18338,20 @@ async function inventory(root) {
|
|
|
18331
18338
|
await walk(root);
|
|
18332
18339
|
return result2;
|
|
18333
18340
|
}
|
|
18334
|
-
async function command(
|
|
18341
|
+
async function command(argv, options = {}) {
|
|
18335
18342
|
options.signal?.throwIfAborted();
|
|
18336
18343
|
return new Promise((resolve11, reject) => {
|
|
18337
|
-
const child = spawn3(
|
|
18344
|
+
const child = spawn3(argv[0], argv.slice(1), { cwd: options.cwd, env: options.env, stdio: ["ignore", "pipe", "pipe"], signal: options.signal });
|
|
18338
18345
|
let stdout = "", stderr = "", size = 0;
|
|
18339
18346
|
let failure2;
|
|
18340
18347
|
const timer = setTimeout(() => {
|
|
18341
|
-
failure2 = new Error(`Command timed out: ${
|
|
18348
|
+
failure2 = new Error(`Command timed out: ${argv[0]}`);
|
|
18342
18349
|
child.kill("SIGKILL");
|
|
18343
18350
|
}, options.timeoutMs ?? 1e4);
|
|
18344
18351
|
const consume = (channel, chunk) => {
|
|
18345
18352
|
size += chunk.length;
|
|
18346
18353
|
if (size > (options.maxBytes ?? 128 * 1024)) {
|
|
18347
|
-
failure2 = new Error(`Command output exceeded limit: ${
|
|
18354
|
+
failure2 = new Error(`Command output exceeded limit: ${argv[0]}`);
|
|
18348
18355
|
child.kill("SIGKILL");
|
|
18349
18356
|
return;
|
|
18350
18357
|
}
|
|
@@ -18596,8 +18603,8 @@ var Transfer = class {
|
|
|
18596
18603
|
}
|
|
18597
18604
|
}
|
|
18598
18605
|
}
|
|
18599
|
-
async checked(
|
|
18600
|
-
const framed =
|
|
18606
|
+
async checked(argv, timeoutMs2, signal) {
|
|
18607
|
+
const framed = argv[0] === this.node && argv[1] === "-e" ? [argv[0], argv[1], `try { ${argv[2]} } catch(error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode=1; }`, ...argv.slice(3)] : argv;
|
|
18601
18608
|
for (let attempt = 1; ; attempt++) {
|
|
18602
18609
|
const result2 = await (signal ? this.vm.exec(this.name, framed, timeoutMs2, { signal, ...timeoutMs2 ? { timeoutMs: timeoutMs2 } : {} }) : this.vm.exec(this.name, framed, timeoutMs2));
|
|
18603
18610
|
if (result2.code === 0) return result2.stdout;
|
|
@@ -18988,8 +18995,8 @@ var Transfer = class {
|
|
|
18988
18995
|
await assertHostPath(localRoot, local);
|
|
18989
18996
|
const staging = await mkdtemp(join7(local, ".relay-archive-"));
|
|
18990
18997
|
try {
|
|
18991
|
-
const
|
|
18992
|
-
const fact = JSON.parse(await this.checked(
|
|
18998
|
+
const argv = [this.node, "-e", ARCHIVE, remote, approvedRoot, archive, guestRoot, options.present ? "present" : "all", ...chunk.map((file) => file.path)];
|
|
18999
|
+
const fact = JSON.parse(await this.checked(argv, scanTimeoutMs(2 * (bytes ?? 0)), options.signal));
|
|
18993
19000
|
const size = fact?.bytes;
|
|
18994
19001
|
if (fact?.path !== archive || !Number.isSafeInteger(size) || bytes !== void 0 && size !== bytes) throw new Error("Invalid remote archive fact");
|
|
18995
19002
|
const staged = join7(staging, "archive");
|
|
@@ -19125,7 +19132,8 @@ var VmTransport = class {
|
|
|
19125
19132
|
if (!this.because.trim()) throw new Error("Run execution intent is required");
|
|
19126
19133
|
if (!/^[A-Za-z0-9][A-Za-z0-9_.-]{0,159}$/.test(request.executionId)) throw new Error("Invalid execution identity");
|
|
19127
19134
|
this.response = void 0;
|
|
19128
|
-
const
|
|
19135
|
+
const { kind: _kind, argv: _argv, ...framed } = request;
|
|
19136
|
+
const payload = { ...framed, because: this.because, timeoutMs: this.timeoutMs, ...this.diagnostic ? { diagnostic: true } : {}, ...this.capture ? {} : { capture: false } };
|
|
19129
19137
|
const local = join8(this.hostRoot, "requests", `${request.executionId}.json`);
|
|
19130
19138
|
const remote = join8(this.guestRoot, "requests", `${request.executionId}.json`);
|
|
19131
19139
|
await assertHostPath(this.hostRoot, local, true);
|
|
@@ -19421,12 +19429,12 @@ async function analyze(root, options, files) {
|
|
|
19421
19429
|
const actionReceipts = receipts.filter((r) => (r.actionId === id2 || executionId && r.executionId === executionId) && (r.actionId === void 0 || r.actionId === id2) && (r.executionId === void 0 || executionId === void 0 || r.executionId === executionId));
|
|
19422
19430
|
execution2 = reconcileOutcome(execution2, actionReceipts);
|
|
19423
19431
|
const completion = completions.get(id2);
|
|
19424
|
-
const
|
|
19432
|
+
const argv = events.find((e) => e.kind === "execution-start" && executionId && e.executionId === executionId && Array.isArray(e.argv))?.argv;
|
|
19425
19433
|
details.set(stepId2, {
|
|
19426
19434
|
at: source.writtenAt ?? before?.capturedAt,
|
|
19427
19435
|
beforeAt: before?.capturedAt,
|
|
19428
19436
|
afterAt: after?.capturedAt,
|
|
19429
|
-
...
|
|
19437
|
+
...argv?.every((w) => typeof w === "string") ? { argv } : {},
|
|
19430
19438
|
output: commandOutput(actionReceipts.find((r) => commandOutput(r)) ?? completion?.toolOutcome?.value)
|
|
19431
19439
|
});
|
|
19432
19440
|
const originalObserved = refusal?.diagnostic ?? completion?.diagnostic ?? (completion?.toolOutcome ? JSON.stringify(completion.toolOutcome) : void 0);
|
|
@@ -19609,13 +19617,13 @@ async function verifyDeliveredPackage(rootDir) {
|
|
|
19609
19617
|
|
|
19610
19618
|
// src/probe.ts
|
|
19611
19619
|
async function probeLocal(run = command, platform = process.platform) {
|
|
19612
|
-
async function observe(
|
|
19620
|
+
async function observe(argv, parse7) {
|
|
19613
19621
|
try {
|
|
19614
|
-
const result2 = await run(
|
|
19622
|
+
const result2 = await run(argv);
|
|
19615
19623
|
if (result2.code) throw new Error(result2.stderr || `exit ${result2.code}`);
|
|
19616
|
-
return { value: parse7(result2.stdout), source:
|
|
19624
|
+
return { value: parse7(result2.stdout), source: argv.join(" ") };
|
|
19617
19625
|
} catch (error2) {
|
|
19618
|
-
return { value: null, source:
|
|
19626
|
+
return { value: null, source: argv.join(" "), diagnostic: String(error2) };
|
|
19619
19627
|
}
|
|
19620
19628
|
}
|
|
19621
19629
|
const permissions = await observe(["cua-driver", "permissions", "status", "--json"], JSON.parse);
|
|
@@ -28000,7 +28008,7 @@ async function prepareImage(bytes, mimeType) {
|
|
|
28000
28008
|
// src/guest/image-evidence.ts
|
|
28001
28009
|
var safeId = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,159}$/.test(value);
|
|
28002
28010
|
function afterRequested(request) {
|
|
28003
|
-
return
|
|
28011
|
+
return request?.diagnostic !== true && request?.capture !== false && !["first", "member"].includes(request?.snapshots?.group?.phase ?? "");
|
|
28004
28012
|
}
|
|
28005
28013
|
function validateImageEvidence(value, request, authoritativeSnapshots) {
|
|
28006
28014
|
const fail2 = () => {
|
|
@@ -28736,6 +28744,7 @@ async function refreshEvidenceState(incoming, destination, archiveRoot, options
|
|
|
28736
28744
|
}
|
|
28737
28745
|
|
|
28738
28746
|
// src/manager.ts
|
|
28747
|
+
var SCRIPT_EXTENSIONS = { shell: "sh", javascript: "js", typescript: "ts", python: "py" };
|
|
28739
28748
|
var RENEWAL_WINDOW_MS = 15 * 6e4;
|
|
28740
28749
|
var MIN_RENEWAL_MS = 0.1 * 36e5;
|
|
28741
28750
|
var DEFAULT_AFTER_INTERVAL_MS = 500;
|
|
@@ -28754,7 +28763,7 @@ async function settleEach(work) {
|
|
|
28754
28763
|
const failed = (await Promise.allSettled(work)).find((result2) => result2.status === "rejected");
|
|
28755
28764
|
if (failed) throw failed.reason;
|
|
28756
28765
|
}
|
|
28757
|
-
var instructions = "This server offers
|
|
28766
|
+
var instructions = "This server offers fourteen tools for guests, VMs that run the work you choose to run there: relay_search, relay_probe, relay_acquisition_capabilities, relay_acquire, relay_stage, the run tool relay_script, relay_image, relay_extract, relay_finish, relay_release, relay_console_resolve, relay_console_open, relay_console_cancel and relay_status. relay_script runs a shell, JavaScript, TypeScript or Python script, given inline or as a project file; a command is a shell script, and the script drives whatever the image lists, such as cua-driver, Playwright or Chrome DevTools, through their own libraries or command lines. Staging needs only Node.js in the guest, and a run takes before and after snapshots only when the image lists capture software (cua-driver). Evidence is automatic, and a run's after-image is returned as pending and downloaded in the background, so call relay_image with the imageId when you need to see it. Acquire one guest for each machine your work needs; several guests may run at once, up to the session's limit that relay_status reports. relay_acquire answers each guest's name, `guest`, and every call that acts on a guest names it with `guest`. Calls on different guests run at the same time; calls on one guest keep their order. Work each guest in order: relay_probe, then relay_acquire, then relay_stage, then relay_script, then relay_image or relay_extract as needed, then relay_finish or relay_release; finishing or releasing one guest leaves the others running. Always call relay_finish or relay_release explicitly for every guest before you return an answer; ending the session never finishes a guest: it pauses lease renewal and keeps the VMs or, where the relay is set up to, releases them, and the backend's own expiry is the last-resort safeguard. A refused, uncertain or nonzero operation keeps the VM so you can diagnose and submit a corrected operation; never replay input whose effect is uncertain. A tool result, an attached image or a verified evidence package, is evidence for a human reviewer, never the review itself. The relay never targets a physical or local display and offers no video or spawn API. Every tool's text result is capped at 50 KiB / 2000 lines; a larger result is retained whole in a local file the result names.";
|
|
28758
28767
|
var NO_OWNED_LEASE = "This session owns no lease: it holds no guest, so nothing was released. Each server process has its own session identity (a new random one unless MCP_RELAY_SESSION sets it); a lease acquired under another identity is not visible here. Restart the server with that MCP_RELAY_SESSION to reconcile and release it, or let the backend TTL expire it.";
|
|
28759
28768
|
var RelayManager = class {
|
|
28760
28769
|
constructor(options) {
|
|
@@ -28768,12 +28777,12 @@ var RelayManager = class {
|
|
|
28768
28777
|
this.capacityWaitMs = options.capacityWaitMs ?? capacityWait() * 1e3;
|
|
28769
28778
|
this.capacityRetryMs = options.capacityRetryMs ?? CAPACITY_RETRY_MS;
|
|
28770
28779
|
if (!Number.isFinite(this.capacityWaitMs) || this.capacityWaitMs < 0 || !Number.isFinite(this.capacityRetryMs) || this.capacityRetryMs <= 0) throw new Error("capacityWaitMs must be nonnegative and capacityRetryMs positive");
|
|
28771
|
-
this.vm = options.vm ?? new
|
|
28780
|
+
this.vm = options.vm ?? new MachineService({ baseUrl: this.environment?.profile.vmServiceUrl ?? process.env.MCP_RELAY_URL, environment: this.environment });
|
|
28772
28781
|
this.registry = options.registry ?? new Registry(this.environment ? { managedRoot: this.environment.profile.relayStateDir } : {});
|
|
28773
28782
|
this.root = join13(this.environment?.profile.relayStateDir ?? options.stateRoot ?? relayStateRoot(), hash(options.sessionId).slice(0, 32));
|
|
28774
28783
|
this.channel = {
|
|
28775
|
-
exec: async (name,
|
|
28776
|
-
const result2 = await this.vm.exec(name, { argv
|
|
28784
|
+
exec: async (name, argv, timeoutMs2 = 18e4, options2) => {
|
|
28785
|
+
const result2 = await this.vm.exec(name, { argv, timeout: Math.ceil(timeoutMs2 / 1e3) }, { timeoutMs: options2?.timeoutMs ?? timeoutMs2 + 3e4, signal: options2?.signal });
|
|
28777
28786
|
return { stdout: result2.output, stderr: result2.output, code: result2.rc };
|
|
28778
28787
|
},
|
|
28779
28788
|
push: (name, local_path, remote_path) => this.vm.push(name, { local_path, remote_path }),
|
|
@@ -28938,7 +28947,8 @@ var RelayManager = class {
|
|
|
28938
28947
|
if (!this.environment) return;
|
|
28939
28948
|
if (new URL(this.vm.baseUrl).origin !== new URL(this.environment.profile.vmServiceUrl).origin) throw new Error("Injected backend endpoint does not match selected environment");
|
|
28940
28949
|
const health = await this.vm.health({ timeoutMs: 5e3 });
|
|
28941
|
-
|
|
28950
|
+
expectMachineService(health, this.vm.baseUrl);
|
|
28951
|
+
if (!health.ok || !matchesEnvironment(health.environment, this.environment)) throw new Error("machine-service environment identity mismatch; no lease operation was performed");
|
|
28942
28952
|
}
|
|
28943
28953
|
async unlock() {
|
|
28944
28954
|
if (this.ownerLock) {
|
|
@@ -28997,7 +29007,7 @@ var RelayManager = class {
|
|
|
28997
29007
|
async readAcquisitionCapabilities(signal) {
|
|
28998
29008
|
signal?.throwIfAborted();
|
|
28999
29009
|
await this.assertBackend();
|
|
29000
|
-
if (!this.vm.acquisitionCapabilities) throw new Error("Backend lacks acquisition-capabilities; upgrade
|
|
29010
|
+
if (!this.vm.acquisitionCapabilities) throw new Error("Backend lacks acquisition-capabilities; upgrade machine-service for VNC");
|
|
29001
29011
|
return acquisitionCapabilities(await this.vm.acquisitionCapabilities({ signal, timeoutMs: 1e4 }));
|
|
29002
29012
|
}
|
|
29003
29013
|
acquisitionCapabilities(signal) {
|
|
@@ -29296,7 +29306,7 @@ var Guest = class {
|
|
|
29296
29306
|
await this.m.assertBackend();
|
|
29297
29307
|
e.backend ??= this.m.binding();
|
|
29298
29308
|
if (!e.lease) {
|
|
29299
|
-
const matches = Object.values((await this.m.vm.list({ timeoutMs: 1e4 })).
|
|
29309
|
+
const matches = Object.values((await this.m.vm.list({ timeoutMs: 1e4 })).machines).filter((v) => v.purpose === e.purpose);
|
|
29300
29310
|
if (matches.length !== 1) throw new Error(`Cannot reconcile acquisition for ${e.purpose}; ownership retained, never automatically reacquire`);
|
|
29301
29311
|
e.lease = matches[0];
|
|
29302
29312
|
e.acquisitionInFlight = false;
|
|
@@ -29319,7 +29329,7 @@ var Guest = class {
|
|
|
29319
29329
|
await this.save();
|
|
29320
29330
|
} catch (error2) {
|
|
29321
29331
|
e.guestState = "unknown";
|
|
29322
|
-
if (error2 instanceof
|
|
29332
|
+
if (error2 instanceof MachineServiceError && error2.status === 404 && await this.destroyed(e.lease.vm)) {
|
|
29323
29333
|
await this.m.registry.remove(e.row);
|
|
29324
29334
|
await jsonFile(`${e.hostRoot}.lifecycle.json`, { purpose: e.purpose, vm: e.lease.vm, released: true, reason: "backend lease absent and destruction verified", finishedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
29325
29335
|
this.enclosure = void 0;
|
|
@@ -29347,10 +29357,10 @@ var Guest = class {
|
|
|
29347
29357
|
async probe() {
|
|
29348
29358
|
const e = this.current();
|
|
29349
29359
|
const checks = [];
|
|
29350
|
-
for (const [name, language2,
|
|
29360
|
+
for (const [name, language2, argv] of [["node", "javascript", [e.node ?? "node", "--version"]], ["tsx", "typescript", ["tsx", "--version"]], ["python3", "python", ["python3", "--version"]], ["sh", "shell", ["/bin/sh", "-c", "exit 0"]]]) {
|
|
29351
29361
|
const required2 = name === "node";
|
|
29352
29362
|
try {
|
|
29353
|
-
const r = await this.m.channel.exec(e.lease.vm, [...
|
|
29363
|
+
const r = await this.m.channel.exec(e.lease.vm, [...argv], 1e4);
|
|
29354
29364
|
checks.push({ name, language: language2, required: required2, ...r, ready: r.code === 0 });
|
|
29355
29365
|
} catch (error2) {
|
|
29356
29366
|
checks.push({ name, language: language2, required: required2, ready: false, diagnostic: String(error2) });
|
|
@@ -29368,7 +29378,7 @@ var Guest = class {
|
|
|
29368
29378
|
software = { image: e.image, diagnostic: `The image catalog could not be read: ${message(error2)}` };
|
|
29369
29379
|
}
|
|
29370
29380
|
const snapshots2 = e.capture === void 0 && !e.staged ? { taken: null, reason: "Decided at relay_stage: runs take snapshots only when the image lists capture software (cua-driver)." } : this.snapshotFacts(e);
|
|
29371
|
-
const facts = { scope: "guest", guest: this.name, observedAt: (/* @__PURE__ */ new Date()).toISOString(), owned: this.status(), checks, software, snapshots: snapshots2, note: "A ready runtime means its --version exited 0. Listed software is what the catalog says the image holds; it never proves that a program runs, that a browser renders on the display or that capture works.", captureVerified: false, browserVerified: false };
|
|
29381
|
+
const facts = { scope: "guest", guest: this.name, observedAt: (/* @__PURE__ */ new Date()).toISOString(), owned: this.status(), checks, software, snapshots: snapshots2, note: "A ready runtime means its --version, or for /bin/sh `exit 0`, exited 0. Listed software is what the catalog says the image holds; it never proves that a program runs, that a browser renders on the display or that capture works.", captureVerified: false, browserVerified: false };
|
|
29372
29382
|
await this.log("guest-readiness", void 0, facts);
|
|
29373
29383
|
return facts;
|
|
29374
29384
|
}
|
|
@@ -29383,7 +29393,7 @@ var Guest = class {
|
|
|
29383
29393
|
}
|
|
29384
29394
|
async resolveConsole(signal) {
|
|
29385
29395
|
const e = await this.consoleOwner(signal);
|
|
29386
|
-
if (!this.m.vm.consoleResolve) throw new Error("Backend lacks console API; upgrade
|
|
29396
|
+
if (!this.m.vm.consoleResolve) throw new Error("Backend lacks console API; upgrade machine-service");
|
|
29387
29397
|
let observation;
|
|
29388
29398
|
try {
|
|
29389
29399
|
observation = consoleStatus(await this.m.vm.consoleResolve(e.lease.vm, { lease_id: e.lease.lease_id }, { signal, timeoutMs: 1e4 }));
|
|
@@ -29410,7 +29420,7 @@ var Guest = class {
|
|
|
29410
29420
|
if (!e.lease.console?.console_id) throw new Error("This lease has no acquired console; automatic VNC retrofit is forbidden");
|
|
29411
29421
|
if (resolved.console_id !== input.console_id) throw new Error("Console instance identity mismatch");
|
|
29412
29422
|
const method = operation === "open" ? this.m.vm.consoleOpen : this.m.vm.consoleCancel;
|
|
29413
|
-
if (!method) throw new Error("Backend lacks console API; upgrade
|
|
29423
|
+
if (!method) throw new Error("Backend lacks console API; upgrade machine-service");
|
|
29414
29424
|
if (operation === "open") {
|
|
29415
29425
|
if (resolved.viewer_location !== "service-host") throw new Error("Only a viewer on the declared service host is supported; no remote-client viewer fallback");
|
|
29416
29426
|
if (e.lease.state !== "running" || !Number.isFinite(e.lease.ttl_expires_at) || e.lease.ttl_expires_at <= Date.now() / 1e3) throw new Error("Console lease is not running or has expired");
|
|
@@ -29458,8 +29468,8 @@ var Guest = class {
|
|
|
29458
29468
|
}
|
|
29459
29469
|
/**
|
|
29460
29470
|
* The acquisition, in this guest's own order. Its ownership intent is
|
|
29461
|
-
* persisted and registered before
|
|
29462
|
-
* that, or
|
|
29471
|
+
* persisted and registered before machine-service is asked. A refusal before
|
|
29472
|
+
* that, or machine-service's own refusal, leaves the session without the guest;
|
|
29463
29473
|
* any other failure keeps the guest's record for reconciliation.
|
|
29464
29474
|
*/
|
|
29465
29475
|
async acquire(input, network, signal) {
|
|
@@ -29482,7 +29492,7 @@ var Guest = class {
|
|
|
29482
29492
|
const stamp = startedAt.slice(0, 19).replace(/[T:]/g, "-") + "-Z";
|
|
29483
29493
|
const project = this.m.options.project, environment = this.m.environment;
|
|
29484
29494
|
const hostRoot = join13(this.m.options.outputRoot ?? resolve9(project, "relay-evidence"), purpose);
|
|
29485
|
-
const row = { machine: environment ? `${environment.profile.vmServiceUrl} (${environment.profile.id}; ${purpose})` : `127.0.0.1 (
|
|
29495
|
+
const row = { machine: environment ? `${environment.profile.vmServiceUrl} (${environment.profile.id}; ${purpose})` : `127.0.0.1 (machine-service ${purpose})`, os: input.image, taskName: purpose, agent: `mcp-relay ${this.m.options.sessionId}`, project: resolve9(project), startDate: stamp };
|
|
29486
29496
|
const e = this.enclosure = { backend: this.m.binding(), purpose, task: input.task, image: input.image, project, startedAt, guestRoot: `/var/tmp/${stamp}-mcp-relay-${purpose}`, hostRoot, ttlHours, extractions: input.extractions, fullWorkspace: input.fullWorkspace ?? false, row, staged: false };
|
|
29487
29497
|
let refused = false;
|
|
29488
29498
|
try {
|
|
@@ -29512,11 +29522,11 @@ var Guest = class {
|
|
|
29512
29522
|
break;
|
|
29513
29523
|
} catch (error2) {
|
|
29514
29524
|
if (signal?.aborted && error2 === signal.reason) e.acquisitionInFlight = false;
|
|
29515
|
-
else if (error2 instanceof
|
|
29525
|
+
else if (error2 instanceof MachineServiceError && error2.status !== void 0 && error2.status >= 400 && error2.status < 500) {
|
|
29516
29526
|
e.acquisitionInFlight = false;
|
|
29517
29527
|
refused = true;
|
|
29518
29528
|
}
|
|
29519
|
-
if (!refused || !(error2 instanceof
|
|
29529
|
+
if (!refused || !(error2 instanceof MachineServiceError && error2.capacity) || this.m.capacityWaitMs <= 0) throw error2;
|
|
29520
29530
|
firstRefusal ??= asked;
|
|
29521
29531
|
await this.waitForCapacity(e, error2, firstRefusal, signal);
|
|
29522
29532
|
refused = false;
|
|
@@ -29550,7 +29560,7 @@ Guest ${this.name} keeps this acquisition's ownership record: name it to reconci
|
|
|
29550
29560
|
/**
|
|
29551
29561
|
* The host is at capacity: wait one retry interval, or what is left of
|
|
29552
29562
|
* MCP_RELAY_CAPACITY_WAIT, before the acquisition is asked again. Refuses
|
|
29553
|
-
* with
|
|
29563
|
+
* with machine-service's reason and the time waited once the wait has run out,
|
|
29554
29564
|
* or when the call is cancelled or the session ends (DC-22).
|
|
29555
29565
|
*/
|
|
29556
29566
|
async waitForCapacity(e, refusal, since, signal) {
|
|
@@ -29576,16 +29586,16 @@ Guest ${this.name} keeps this acquisition's ownership record: name it to reconci
|
|
|
29576
29586
|
if (stop.aborted) throw new Error(`${signal?.aborted ? String(signal.reason) : "The relay session ended"} while the acquisition waited ${seconds(Date.now() - since)} s for capacity (${refusal.message}), so nothing was acquired`, { cause: refusal });
|
|
29577
29587
|
}
|
|
29578
29588
|
/**
|
|
29579
|
-
* A refused acquisition acquired nothing: once
|
|
29589
|
+
* A refused acquisition acquired nothing: once machine-service lists no VM for
|
|
29580
29590
|
* its purpose, its registry row goes and the guest leaves the session.
|
|
29581
29591
|
* False when that cannot be established, so the record stays.
|
|
29582
29592
|
*/
|
|
29583
29593
|
async withdraw(error2) {
|
|
29584
29594
|
const e = this.enclosure;
|
|
29585
29595
|
try {
|
|
29586
|
-
if (Object.values((await this.m.vm.list({ timeoutMs: 1e4 })).
|
|
29596
|
+
if (Object.values((await this.m.vm.list({ timeoutMs: 1e4 })).machines).some((lease) => lease.purpose === e.purpose)) return false;
|
|
29587
29597
|
await this.m.registry.remove(e.row);
|
|
29588
|
-
await jsonFile(`${e.hostRoot}.lifecycle.json`, { purpose: e.purpose, released: false, acquired: false, reason: "
|
|
29598
|
+
await jsonFile(`${e.hostRoot}.lifecycle.json`, { purpose: e.purpose, released: false, acquired: false, reason: "machine-service refused the acquisition", error: String(error2), finishedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
29589
29599
|
this.enclosure = void 0;
|
|
29590
29600
|
await this.save();
|
|
29591
29601
|
await this.m.forget(this);
|
|
@@ -29683,7 +29693,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29683
29693
|
const e = this.current();
|
|
29684
29694
|
if (e.delivered) throw new Error("Evidence already sealed; release this VM explicitly");
|
|
29685
29695
|
if (input.resetRecording || e.pendingReset) await this.resetRecording();
|
|
29686
|
-
if (e.staged && (input.workspace || input.files?.length)) throw new Error("Runtime already staged; use
|
|
29696
|
+
if (e.staged && (input.workspace || input.files?.length)) throw new Error("Runtime already staged; use a shell relay_script with diagnostic: true for repairs, or stage with only corrected executable paths");
|
|
29687
29697
|
const project = resolve9(this.m.options.project);
|
|
29688
29698
|
const files = [];
|
|
29689
29699
|
for (const file of input.files ?? []) files.push({ local: await this.m.projectPath(file.local, "files[].local"), path: file.path });
|
|
@@ -29720,7 +29730,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29720
29730
|
this.transport = new VmTransport(transfer, e.guestRoot, join13(e.hostRoot, "host"), e.cuaDriver);
|
|
29721
29731
|
this.transport.capture = e.capture !== false;
|
|
29722
29732
|
relay.useTransport(() => this.transport);
|
|
29723
|
-
this.session = await relay.start({ taskId: e.purpose, target: `
|
|
29733
|
+
this.session = await relay.start({ taskId: e.purpose, target: `machine-service:${e.lease.vm}` });
|
|
29724
29734
|
e.sessionId = this.session.sessionId;
|
|
29725
29735
|
e.staged = true;
|
|
29726
29736
|
await this.save();
|
|
@@ -29762,7 +29772,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29762
29772
|
} catch (error2) {
|
|
29763
29773
|
if (signal?.aborted) throw error2;
|
|
29764
29774
|
const waited = Date.now() - since;
|
|
29765
|
-
if (waited + retryMs > waitMs) throw new Error(`relay_stage waited ${Math.round(waited / 1e3)} s for ${e.image}'s cua-driver to take a screenshot, which each run's before and after snapshots need, and it never did: ${message(error2)}. Diagnose or start it with
|
|
29775
|
+
if (waited + retryMs > waitMs) throw new Error(`relay_stage waited ${Math.round(waited / 1e3)} s for ${e.image}'s cua-driver to take a screenshot, which each run's before and after snapshots need, and it never did: ${message(error2)}. Diagnose or start it with a shell relay_script and diagnostic: true, such as \`${cuaDriver} serve\` on Linux, then call relay_stage again.`, { cause: error2 });
|
|
29766
29776
|
await new Promise((done) => {
|
|
29767
29777
|
const timer = setTimeout(done, retryMs);
|
|
29768
29778
|
signal?.addEventListener("abort", () => {
|
|
@@ -29782,11 +29792,11 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29782
29792
|
const e = this.current();
|
|
29783
29793
|
const timeoutMs2 = input.timeoutMs ?? 12e4;
|
|
29784
29794
|
if (!Number.isSafeInteger(timeoutMs2) || timeoutMs2 < 1 || timeoutMs2 > 36e5) throw new Error("timeoutMs must be an integer from 1 to 3600000");
|
|
29785
|
-
if (input.diagnostic && input.
|
|
29795
|
+
if (input.diagnostic && input.language !== "shell") throw new Error("Only a shell script may be diagnostic, because a diagnostic run goes through machine-service without the receiver");
|
|
29786
29796
|
if (e.delivered) throw new Error("Evidence already sealed; release this VM explicitly");
|
|
29787
29797
|
if (input.diagnostic) return this.diagnostic(input, timeoutMs2, signal);
|
|
29788
|
-
if (e.pendingReset) throw new Error("Recording reset is pending; retry stage to reconcile it, or use
|
|
29789
|
-
if (!e.staged || !this.session || !this.transport) throw new Error("Use relay_stage before a run, or
|
|
29798
|
+
if (e.pendingReset) throw new Error("Recording reset is pending; retry stage to reconcile it, or use a shell relay_script with diagnostic: true");
|
|
29799
|
+
if (!e.staged || !this.session || !this.transport) throw new Error("Use relay_stage before a run, or a shell relay_script with diagnostic: true for setup diagnosis and repair");
|
|
29790
29800
|
const record3 = this.derive(e, input);
|
|
29791
29801
|
await this.save();
|
|
29792
29802
|
this.transport.because = record3.because;
|
|
@@ -29795,20 +29805,14 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29795
29805
|
this.transport.signal = signal;
|
|
29796
29806
|
const options = { step: record3.step, snapshots: record3.snapshots, cwd: join13(e.guestRoot, "workspace") };
|
|
29797
29807
|
let result2;
|
|
29798
|
-
if (input.
|
|
29799
|
-
if (
|
|
29800
|
-
result2 = await this.session.
|
|
29801
|
-
} else
|
|
29802
|
-
if (!input.
|
|
29803
|
-
|
|
29804
|
-
|
|
29805
|
-
|
|
29806
|
-
} else {
|
|
29807
|
-
if (!input.localPath || input.code !== void 0) throw new Error("relay_script with inline: false takes the script file as localPath, and no code");
|
|
29808
|
-
const local = await this.m.projectPath(input.localPath, "localPath");
|
|
29809
|
-
result2 = await this.session.runScript(local, join13(e.guestRoot, "scripts", `${randomUUID6()}.${input.language === "python" ? "py" : input.language === "typescript" ? "ts" : "js"}`), input.language, options);
|
|
29810
|
-
}
|
|
29811
|
-
} else throw new Error("Unknown operation kind");
|
|
29808
|
+
if (input.inline) {
|
|
29809
|
+
if (typeof input.code !== "string" || input.localPath !== void 0) throw new Error("relay_script with inline: true takes the script as code, and no localPath");
|
|
29810
|
+
result2 = await this.session.runCode(input.code, input.language, options);
|
|
29811
|
+
} else {
|
|
29812
|
+
if (!input.localPath || input.code !== void 0) throw new Error("relay_script with inline: false takes the script file as localPath, and no code");
|
|
29813
|
+
const local = await this.m.projectPath(input.localPath, "localPath");
|
|
29814
|
+
result2 = await this.session.runScript(local, join13(e.guestRoot, "scripts", `${randomUUID6()}.${SCRIPT_EXTENSIONS[input.language]}`), input.language, options);
|
|
29815
|
+
}
|
|
29812
29816
|
const outcome = result2.outcome;
|
|
29813
29817
|
if (outcome.kind !== "completed" || outcome.exitStatus.code !== 0 || outcome.exitStatus.signal) {
|
|
29814
29818
|
await this.log("execution-failed", record3.because, result2);
|
|
@@ -29823,19 +29827,20 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29823
29827
|
}
|
|
29824
29828
|
/**
|
|
29825
29829
|
* The step record for a run, from the call itself: a title such as
|
|
29826
|
-
* `
|
|
29830
|
+
* `shell ls -al`, `code (python)` or `script check.py`, an expected result, an input mode, a default
|
|
29827
29831
|
* after-snapshot wait and a reason. Anything the caller gave overrides it.
|
|
29828
29832
|
*/
|
|
29829
29833
|
derive(e, input) {
|
|
29830
29834
|
const seq = e.runSeq = (e.runSeq ?? 0) + 1;
|
|
29831
29835
|
const stepId2 = (prefix) => `${prefix.replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 100) || "run"}-${seq}`;
|
|
29832
|
-
const
|
|
29836
|
+
const firstLine = input.code?.split("\n").find((line) => line.trim())?.trim();
|
|
29837
|
+
const title = input.step?.title ?? (input.inline ? input.language === "shell" && firstLine ? `shell ${firstLine}` : `code (${input.language})` : `script ${input.localPath?.split("/").at(-1) ?? ""}`).slice(0, 500);
|
|
29833
29838
|
const snapshots2 = { ...input.snapshots ?? {} };
|
|
29834
29839
|
const group = snapshots2.group;
|
|
29835
29840
|
if (!group ? snapshots2.afterIntervalMs === void 0 : group.phase === "last" && group.afterIntervalMs === void 0 && snapshots2.afterIntervalMs === void 0) Object.assign(snapshots2, { afterIntervalMs: DEFAULT_AFTER_INTERVAL_MS });
|
|
29836
29841
|
return {
|
|
29837
29842
|
because: input.because ?? `Relay ${title} (no reason given)`.slice(0, 4e3),
|
|
29838
|
-
step: { id: input.step?.id ?? stepId2(input.
|
|
29843
|
+
step: { id: input.step?.id ?? stepId2(input.inline ? "code" : "script"), title: title || "script", expected: input.step?.expected ?? "Exits with status 0", inputMode: input.step?.inputMode ?? "ordinary" },
|
|
29839
29844
|
snapshots: snapshots2
|
|
29840
29845
|
};
|
|
29841
29846
|
}
|
|
@@ -29862,7 +29867,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
29862
29867
|
const lease = await this.m.vm.get(e.lease.vm, options);
|
|
29863
29868
|
if (lease.purpose !== e.purpose) throw Object.assign(new Error("Lease ownership identity changed."), { code: "unauthorized-reference" });
|
|
29864
29869
|
} catch (error2) {
|
|
29865
|
-
if (error2 instanceof
|
|
29870
|
+
if (error2 instanceof MachineServiceError && error2.status === 404) throw Object.assign(new Error("Saved image guest is no longer available."), { code: "stale-reference" });
|
|
29866
29871
|
throw error2;
|
|
29867
29872
|
}
|
|
29868
29873
|
}
|
|
@@ -30163,15 +30168,17 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
30163
30168
|
}
|
|
30164
30169
|
async diagnostic(input, timeoutMs2, signal) {
|
|
30165
30170
|
const e = this.current();
|
|
30166
|
-
if (
|
|
30171
|
+
if (input.language !== "shell" || input.snapshots?.group) throw new Error("A diagnostic run is a shell script and cannot join a snapshot group");
|
|
30172
|
+
const script = input.inline ? input.code : await readFile9(await this.m.projectPath(input.localPath ?? "", "localPath"), "utf8");
|
|
30173
|
+
if (typeof script !== "string") throw new Error("relay_script with inline: true takes the script as code, and no localPath");
|
|
30167
30174
|
const executionId = `diagnostic-${randomUUID6()}`;
|
|
30168
30175
|
const { guest: _guest, ...requested } = input;
|
|
30169
|
-
const
|
|
30176
|
+
const argv = e.staged ? ["/bin/sh", "-c", 'cd "$1" || exit; shift; exec "$@"', "relay-diagnostic", join13(e.guestRoot, "workspace"), "/bin/sh", "-c", script] : ["/bin/sh", "-c", script];
|
|
30177
|
+
const request = { executionId, at: (/* @__PURE__ */ new Date()).toISOString(), evidenceMode: "diagnostic", timeoutMs: timeoutMs2, ...requested, argv };
|
|
30170
30178
|
await jsonFile(join13(e.hostRoot, "host", "diagnostics", `${executionId}.request.json`), request);
|
|
30171
30179
|
let result2;
|
|
30172
30180
|
try {
|
|
30173
|
-
const
|
|
30174
|
-
const r = await this.m.channel.exec(e.lease.vm, argv2, timeoutMs2, { signal });
|
|
30181
|
+
const r = await this.m.channel.exec(e.lease.vm, argv, timeoutMs2, { signal });
|
|
30175
30182
|
result2 = { executionId, outcome: { kind: "completed", exitStatus: { code: r.code, signal: null } }, output: r.stdout, outputStreams: "stdout and stderr combined" };
|
|
30176
30183
|
} catch (error2) {
|
|
30177
30184
|
result2 = { executionId, outcome: { kind: "uncertain", diagnostic: String(error2) }, output: "", outputStreams: "stdout and stderr combined" };
|
|
@@ -30248,7 +30255,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
30248
30255
|
if (!e.released) {
|
|
30249
30256
|
if (!e.lease) {
|
|
30250
30257
|
const list = await this.m.vm.list({ timeoutMs: 1e4 });
|
|
30251
|
-
const matches = Object.values(list.
|
|
30258
|
+
const matches = Object.values(list.machines).filter((lease) => lease.purpose === e.purpose);
|
|
30252
30259
|
if (matches.length > 1) throw new Error("Ambiguous acquisition; refusing to remove ownership record");
|
|
30253
30260
|
if (!matches.length && e.acquisitionInFlight) throw new Error(`Acquire outcome still indeterminate for ${e.purpose}; ownership record retained at ${this.dir}. Reconcile before retrying; never blindly acquire again.`);
|
|
30254
30261
|
e.lease = matches[0];
|
|
@@ -30260,7 +30267,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
30260
30267
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
30261
30268
|
try {
|
|
30262
30269
|
const response = await this.m.vm.release(e.lease.vm, { reason: reason2 }, { timeoutMs: timeoutMs2 });
|
|
30263
|
-
if (!response.released) throw new Error("
|
|
30270
|
+
if (!response.released) throw new Error("machine-service did not confirm destruction");
|
|
30264
30271
|
released = true;
|
|
30265
30272
|
break;
|
|
30266
30273
|
} catch (error2) {
|
|
@@ -30269,7 +30276,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
30269
30276
|
try {
|
|
30270
30277
|
await this.m.vm.get(e.lease.vm, { timeoutMs: 5e3 });
|
|
30271
30278
|
} catch (getError) {
|
|
30272
|
-
if (getError instanceof
|
|
30279
|
+
if (getError instanceof MachineServiceError && getError.status === 404) {
|
|
30273
30280
|
released = true;
|
|
30274
30281
|
break;
|
|
30275
30282
|
}
|
|
@@ -30278,7 +30285,7 @@ VM state: ${JSON.stringify(this.status())}`, { cause: error2 });
|
|
|
30278
30285
|
}
|
|
30279
30286
|
}
|
|
30280
30287
|
if (!released) throw new Error("Lease release unconfirmed");
|
|
30281
|
-
if (!await this.destroyed(e.lease.vm)) throw new Error(`
|
|
30288
|
+
if (!await this.destroyed(e.lease.vm)) throw new Error(`machine-service relinquished ${e.lease.vm}, but Tart still lists it. Destruction is unverified; ownership retained. See docs/verification.md dependency limitation.`);
|
|
30282
30289
|
}
|
|
30283
30290
|
e.released = true;
|
|
30284
30291
|
await this.save().catch(() => {
|
|
@@ -30355,8 +30362,7 @@ var imageTarget = typebox_exports.Union([
|
|
|
30355
30362
|
typebox_exports.Object({ source: typebox_exports.Literal("application"), name: typebox_exports.String({ minLength: 1, maxLength: 101 }), path: typebox_exports.Optional(typebox_exports.String({ minLength: 1, maxLength: 4096 })) }, closed2),
|
|
30356
30363
|
typebox_exports.Object({ source: typebox_exports.Literal("reference"), imageId: typebox_exports.String({ pattern: "^image-[a-f0-9]{64}$" }) }, closed2)
|
|
30357
30364
|
]);
|
|
30358
|
-
var
|
|
30359
|
-
var language = StringEnum(["javascript", "typescript", "python"]);
|
|
30365
|
+
var language = StringEnum(["shell", "javascript", "typescript", "python"]);
|
|
30360
30366
|
var timeoutMs = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 36e5, description: "Execution timeout in milliseconds, default 120000, maximum 3600000. Independent of snapshot delay and lease TTL." }));
|
|
30361
30367
|
var runBase = { action: typebox_exports.Literal("run"), guest, reason: optionalReason, step: typebox_exports.Optional(step), snapshots: typebox_exports.Optional(snapshots), timeoutMs };
|
|
30362
30368
|
var relayContract = typebox_exports.Union([
|
|
@@ -30385,15 +30391,14 @@ var relayContract = typebox_exports.Union([
|
|
|
30385
30391
|
nodePath: typebox_exports.Optional(typebox_exports.String({ description: "Guest Node executable, default node; use image nvm path if needed." })),
|
|
30386
30392
|
cuaDriver: typebox_exports.Optional(typebox_exports.String({ description: "Guest CUA executable; OS default when omitted." }))
|
|
30387
30393
|
}, closed2),
|
|
30388
|
-
|
|
30389
|
-
// One branch for relay_script: `inline` selects which of `code` and `localPath` the call gives, checked in validateRelayInput.
|
|
30394
|
+
// The one run branch, relay_script (DC-26): `inline` selects which of `code` and `localPath` the call gives, and `diagnostic` needs `shell`, both checked in validateRelayInput.
|
|
30390
30395
|
typebox_exports.Object({
|
|
30391
30396
|
...runBase,
|
|
30392
|
-
kind: typebox_exports.Literal("script"),
|
|
30393
30397
|
language,
|
|
30394
30398
|
inline: typebox_exports.Boolean({ description: "true: the script is `code`, given inline. false: the script is the host file `localPath`. Give exactly the one that inline names." }),
|
|
30395
30399
|
code: typebox_exports.Optional(typebox_exports.String({ maxLength: 1048576, description: "With inline: true, the script itself, up to 1 MiB." })),
|
|
30396
|
-
localPath: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "With inline: false, a host script file in the project folder: relative to it, or absolute inside it; no symlinks." }))
|
|
30400
|
+
localPath: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "With inline: false, a host script file in the project folder: relative to it, or absolute inside it; no symlinks." })),
|
|
30401
|
+
diagnostic: typebox_exports.Optional(typebox_exports.Boolean({ description: "Shell scripts only: explicit diagnosis or repair without screenshot evidence, including before staging. The script and its outcome remain recorded. Never claim visual verification." }))
|
|
30397
30402
|
}, closed2),
|
|
30398
30403
|
typebox_exports.Object({ action: typebox_exports.Literal("image"), guest, target: imageTarget }, closed2),
|
|
30399
30404
|
typebox_exports.Object({ action: typebox_exports.Literal("extract"), guest, names: typebox_exports.Array(typebox_exports.String()) }, closed2),
|
|
@@ -30411,28 +30416,25 @@ for (const branch of relayContract.anyOf) {
|
|
|
30411
30416
|
var parameterObject = typebox_exports.Object({
|
|
30412
30417
|
action: StringEnum(["search", "probe", "acquire", "stage", "run", "image", "extract", "finish", "release", "acquisition-capabilities", "console-resolve", "console-open", "console-cancel"]),
|
|
30413
30418
|
...projected
|
|
30414
|
-
}, { ...closed2, anyOf: relayContract.anyOf, description: "Select exactly one action. Each closed branch defines allowed fields. Run
|
|
30419
|
+
}, { ...closed2, anyOf: relayContract.anyOf, description: "Select exactly one action. Each closed branch defines allowed fields. Run takes a script; console-open requires reason, expected and userRequested=true. No default action." });
|
|
30415
30420
|
var relayParameters = typebox_exports.Unsafe(parameterObject);
|
|
30416
|
-
function branchFor(action
|
|
30417
|
-
const found = relayContract.anyOf.find((branch) =>
|
|
30418
|
-
|
|
30419
|
-
if (properties.action.const !== action) return false;
|
|
30420
|
-
return kind === void 0 ? properties.kind === void 0 : properties.kind?.const === kind;
|
|
30421
|
-
});
|
|
30422
|
-
if (!found) throw new Error(`No contract branch for action ${action}${kind ? ` kind ${kind}` : ""}`);
|
|
30421
|
+
function branchFor(action) {
|
|
30422
|
+
const found = relayContract.anyOf.find((branch) => branch.properties.action.const === action);
|
|
30423
|
+
if (!found) throw new Error(`No contract branch for action ${action}`);
|
|
30423
30424
|
return found;
|
|
30424
30425
|
}
|
|
30425
|
-
function toolInputSchema(action
|
|
30426
|
-
const raw = JSON.parse(JSON.stringify(branchFor(action
|
|
30427
|
-
const { action: _action,
|
|
30428
|
-
const required2 = (raw.required ?? []).filter((key) => key !== "action"
|
|
30426
|
+
function toolInputSchema(action) {
|
|
30427
|
+
const raw = JSON.parse(JSON.stringify(branchFor(action)));
|
|
30428
|
+
const { action: _action, ...properties } = raw.properties;
|
|
30429
|
+
const required2 = (raw.required ?? []).filter((key) => key !== "action");
|
|
30429
30430
|
return { type: raw.type, properties, ...required2.length ? { required: required2 } : {}, additionalProperties: raw.additionalProperties ?? false };
|
|
30430
30431
|
}
|
|
30431
30432
|
function validateRelayInput(value) {
|
|
30432
|
-
if (!Check2(relayContract, value)) throw new Error("Invalid relay input: action is required; a call that acts on a guest names it with guest, the name relay_acquire answered; console-open requires nonblank reason. Supply only the fields for the selected action
|
|
30433
|
+
if (!Check2(relayContract, value)) throw new Error("Invalid relay input: action is required; a call that acts on a guest names it with guest, the name relay_acquire answered; console-open requires nonblank reason. Supply only the fields for the selected action.");
|
|
30433
30434
|
if (value.action === "probe" && value.scope === "guest" && value.guest === void 0) throw new Error('Invalid relay input: relay_probe with scope "guest" names the guest to probe with guest, the name relay_acquire answered.');
|
|
30434
|
-
if (value.action === "run"
|
|
30435
|
-
|
|
30435
|
+
if (value.action === "run") {
|
|
30436
|
+
if (value.diagnostic && value.language !== "shell") throw new Error("Invalid relay input: only a shell script may be diagnostic, because a diagnostic run goes through machine-service without the receiver.");
|
|
30437
|
+
if (value.diagnostic && value.snapshots?.group) throw new Error("Diagnostic scripts cannot join snapshot groups.");
|
|
30436
30438
|
const given = value.inline ? value.code : value.localPath, other = value.inline ? value.localPath : value.code;
|
|
30437
30439
|
if (given === void 0 || other !== void 0) throw new Error(value.inline ? "Invalid relay input: relay_script with inline: true takes the script as code, and no localPath." : "Invalid relay input: relay_script with inline: false takes the script file as localPath, and no code.");
|
|
30438
30440
|
}
|
|
@@ -30445,7 +30447,6 @@ import { tmpdir as tmpdir2 } from "node:os";
|
|
|
30445
30447
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
30446
30448
|
var readOnly = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
30447
30449
|
var acts = (openWorld, destructive = false) => ({ readOnlyHint: false, destructiveHint: destructive, idempotentHint: false, openWorldHint: openWorld });
|
|
30448
|
-
var runShared = "Evidence is automatic, as for relay_command, whose optional `reason`, `step`, `snapshots` and `timeoutMs` it shares.";
|
|
30449
30450
|
var relayTools = [
|
|
30450
30451
|
{
|
|
30451
30452
|
name: "relay_search",
|
|
@@ -30459,7 +30460,7 @@ var relayTools = [
|
|
|
30459
30460
|
action: "probe",
|
|
30460
30461
|
title: "Probe host and guest readiness",
|
|
30461
30462
|
annotations: readOnly,
|
|
30462
|
-
description: 'Read-only host and service facts, used to pick an image; it reports current owned state on its own, so call it again after context compaction rather than trusting earlier messages. Default `scope: "host"` reports host permissions and activity, VM service availability, and every guest this session holds with its state, not guest readiness. `scope: "guest"` with `guest` (an already-acquired guest) reports whether Node.js, which staging requires, is available, and, as facts, whether each relay_script language\'s runtime runs (`node`, `tsx`, `python3`), the software the image lists in the catalog, and whether this lease\'s runs take snapshots, without installing or starting anything, and never claims capture readiness. Acquire one guest for each machine the work needs; several may run at once. Continue each guest in order: relay_acquire, relay_stage,
|
|
30463
|
+
description: 'Read-only host and service facts, used to pick an image; it reports current owned state on its own, so call it again after context compaction rather than trusting earlier messages. Default `scope: "host"` reports host permissions and activity, VM service availability, and every guest this session holds with its state, not guest readiness. `scope: "guest"` with `guest` (an already-acquired guest) reports whether Node.js, which staging requires, is available, and, as facts, whether each relay_script language\'s runtime runs (`/bin/sh`, `node`, `tsx`, `python3`), the software the image lists in the catalog, and whether this lease\'s runs take snapshots, without installing or starting anything, and never claims capture readiness. Acquire one guest for each machine the work needs; several may run at once. Continue each guest in order: relay_acquire, relay_stage, relay_script, relay_image/relay_extract, then relay_finish or relay_release, called explicitly for every guest before you return.'
|
|
30463
30464
|
},
|
|
30464
30465
|
{
|
|
30465
30466
|
name: "relay_acquisition_capabilities",
|
|
@@ -30473,7 +30474,7 @@ var relayTools = [
|
|
|
30473
30474
|
action: "acquire",
|
|
30474
30475
|
title: "Acquire a VM",
|
|
30475
30476
|
annotations: acts(false),
|
|
30476
|
-
description: "Acquire one fresh VM, a guest, and start its ownership heartbeat. The result's `guest` is the guest's name in this session, such as `login-test-1`; every later call on this guest names it with `guest`. Requires `task` (a short slug), `image` (a key from relay_probe or relay_search) and `extractions`: every output you intend to bring home, declared before any work (`[]` is allowed; nothing is extracted automatically). Optional `ttlHours` (default 4), `env` (a credential pack, never baked into images), `fullWorkspace` (opt in to deliver the whole workspace) and `vnc` (default false; only prepares console-sharing capacity, never opens a viewer). Acquire one guest for each machine the work needs: several guests may run at once, each with its own lease, evidence and finish, up to the session's limit (relay_status reports `maxGuests`, MCP_RELAY_MAX_GUESTS, default 4); an acquisition beyond it is refused with the names of the guests held. When the host is at capacity, such as at its limit on running macOS VMs, the acquisition waits for it, asking again every 15 s for up to MCP_RELAY_CAPACITY_WAIT (30 minutes by default), and the result's `waitedForCapacityMs` says how long it waited; once the wait runs out it is refused with the backend's reason and the time waited. The backend's other refusals pass through at once. Continue with relay_stage,
|
|
30477
|
+
description: "Acquire one fresh VM, a guest, and start its ownership heartbeat. The result's `guest` is the guest's name in this session, such as `login-test-1`; every later call on this guest names it with `guest`. Requires `task` (a short slug), `image` (a key from relay_probe or relay_search) and `extractions`: every output you intend to bring home, declared before any work (`[]` is allowed; nothing is extracted automatically). Optional `ttlHours` (default 4), `env` (a credential pack, never baked into images), `fullWorkspace` (opt in to deliver the whole workspace) and `vnc` (default false; only prepares console-sharing capacity, never opens a viewer). Acquire one guest for each machine the work needs: several guests may run at once, each with its own lease, evidence and finish, up to the session's limit (relay_status reports `maxGuests`, MCP_RELAY_MAX_GUESTS, default 4); an acquisition beyond it is refused with the names of the guests held. When the host is at capacity, such as at its limit on running macOS VMs, the acquisition waits for it, asking again every 15 s for up to MCP_RELAY_CAPACITY_WAIT (30 minutes by default), and the result's `waitedForCapacityMs` says how long it waited; once the wait runs out it is refused with the backend's reason and the time waited. The backend's other refusals pass through at once. Continue with relay_stage, relay_script, relay_image/relay_extract, then relay_finish or relay_release explicitly before you return; a failed step keeps the VM for repair rather than replaying uncertain input."
|
|
30477
30478
|
},
|
|
30478
30479
|
{
|
|
30479
30480
|
name: "relay_stage",
|
|
@@ -30482,21 +30483,12 @@ var relayTools = [
|
|
|
30482
30483
|
annotations: acts(false),
|
|
30483
30484
|
description: "Push and hash-check the guest runtime, plus an optional workspace and support files (`files`, landing under `support/`), onto the acquired guest that `guest` names. `workspace` and each `files[].local` lie in the project folder, relative to it or absolute inside it, with no symlinks. Staging needs only Node.js in the guest (`nodePath`, default `node`); an image without it is refused, because the relay pushes no runtime. Runs take before and after snapshots only when the image lists capture software (cua-driver); otherwise their records have none, and the result's `snapshots` says which. When the image lists cua-driver, staging waits up to 120 s for it to take a screenshot, since the image starts its daemon at login, and refuses if it never does. `cuaDriver` names the guest cua-driver the snapshots use. A failed stage can be retried; once staged, only corrected executable paths may be resubmitted, and staging does not prove capture readiness. `resetRecording: true` archives the current recording's evidence and starts a fresh recording on the same VM; it refuses while a receiver lock is held."
|
|
30484
30485
|
},
|
|
30485
|
-
{
|
|
30486
|
-
name: "relay_command",
|
|
30487
|
-
action: "run",
|
|
30488
|
-
kind: "exec",
|
|
30489
|
-
title: "Run a guest command",
|
|
30490
|
-
annotations: acts(true),
|
|
30491
|
-
description: "Run one guest command (`argv`) as one recorded operation; never hide several interactions in one call. Evidence is automatic: the relay records a step derived from the command and, when the image lists cua-driver, snapshots the display before and after. Optional `reason` (intent, never authorization), `step` (`id`, `title`, `expected`, `inputMode`) and `snapshots.afterIntervalMs` (default 500 ms) enrich or tune the record; consecutive keystrokes may form an explicit text group with `snapshots.group` (`first`/`member`/`last`). `timeoutMs` bounds execution (default 120000, up to 3600000). The result carries the outcome and bounded stdout/stderr; it names the after-snapshot as `pending` with its `imageId` while the image downloads in the background, so call relay_image with that `imageId` to see it. A refused, uncertain or nonzero result keeps the VM; never replay input whose effect is uncertain. `diagnostic: true` records a diagnosis or repair without snapshots, even before relay_stage; it is never visual verification, and its result has one `output` field with stdout and stderr combined."
|
|
30492
|
-
},
|
|
30493
30486
|
{
|
|
30494
30487
|
name: "relay_script",
|
|
30495
30488
|
action: "run",
|
|
30496
|
-
kind: "script",
|
|
30497
30489
|
title: "Run a guest script",
|
|
30498
30490
|
annotations: acts(true),
|
|
30499
|
-
description:
|
|
30491
|
+
description: "Run one guest script as one recorded operation; never hide several interactions in one call. A command is a shell script. The script drives whatever the image lists, such as cua-driver, Playwright or Chrome DevTools, through their own libraries or command lines, and its exit status says whether it succeeded, so a script that calls cua-driver checks the driver's answer itself. Requires `language` (`shell`, `javascript`, `typescript` or `python`) and `inline`: with `inline: true` give the script itself as `code` (up to 1 MiB); with `inline: false` give `localPath`, a host file in the project folder (relative to it or absolute inside it, with no symlinks). Give exactly the one `inline` names; any other call is refused. It runs in the staged workspace: shell with `/bin/sh`, JavaScript with the guest's Node.js, TypeScript with `tsx` from the guest's PATH or else the guest Node.js's own type stripping (22.6 or later), and Python with `python3` from the guest's PATH (relay_probe scope=guest reports which run); a missing runtime refuses the run before it starts. Evidence is automatic: the relay records a step derived from the call and, when the image lists cua-driver, snapshots the display before and after. Optional `reason` (intent, never authorization), `step` (`id`, `title`, `expected`, `inputMode`) and `snapshots.afterIntervalMs` (default 500 ms) enrich or tune the record; consecutive keystrokes may form an explicit text group with `snapshots.group` (`first`/`member`/`last`). `timeoutMs` bounds execution (default 120000, up to 3600000). The result carries the outcome and bounded stdout/stderr; it names the after-snapshot as `pending` with its `imageId` while the image downloads in the background, so call relay_image with that `imageId` to see it. A refused, uncertain or nonzero result keeps the VM; never replay input whose effect is uncertain. `diagnostic: true`, for shell scripts only, records a diagnosis or repair without snapshots, even before relay_stage, running the script as `/bin/sh -c`; it is never visual verification, and its result has one `output` field with stdout and stderr combined."
|
|
30500
30492
|
},
|
|
30501
30493
|
{
|
|
30502
30494
|
name: "relay_image",
|
|
@@ -30549,12 +30541,12 @@ var relayTools = [
|
|
|
30549
30541
|
}
|
|
30550
30542
|
];
|
|
30551
30543
|
function relayToolInputSchema(tool) {
|
|
30552
|
-
return toolInputSchema(tool.action
|
|
30544
|
+
return toolInputSchema(tool.action);
|
|
30553
30545
|
}
|
|
30554
30546
|
function relayToolInput(name, args) {
|
|
30555
30547
|
const tool = relayTools.find((candidate) => candidate.name === name);
|
|
30556
30548
|
if (!tool) throw new Error(`Unknown relay tool: ${name}`);
|
|
30557
|
-
return { action: tool.action, ...
|
|
30549
|
+
return { action: tool.action, ...args };
|
|
30558
30550
|
}
|
|
30559
30551
|
var relayResultKind = "relay-image-result-v1";
|
|
30560
30552
|
async function renderRelayResult(value, resultRoot = join14(tmpdir2(), "mcp-relay-results"), indent = 2) {
|
|
@@ -30644,7 +30636,7 @@ async function relayCall(host, raw, options = {}) {
|
|
|
30644
30636
|
|
|
30645
30637
|
// src/server.ts
|
|
30646
30638
|
var SERVER_NAME = "relay";
|
|
30647
|
-
var SERVER_VERSION = true ? "0.
|
|
30639
|
+
var SERVER_VERSION = true ? "0.16.0" : JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8")).version;
|
|
30648
30640
|
var STATUS_TOOL = "relay_status";
|
|
30649
30641
|
var PLUGIN_TOOL_PREFIX = "mcp__plugin_mcp-relay_relay__";
|
|
30650
30642
|
var message2 = (error2) => error2 instanceof Error ? error2.message : String(error2);
|