@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.
@@ -1,6 +1,6 @@
1
1
  {
2
- "server.mjs": "ffb1d595668b5a6d135088ccde3c2e67a48043c4ee1fdf49e4c0bf9d55687cb8",
3
- "receiver.mjs": "2c98de7231780391c6f958c054409d80318230bb009e529a4fc68ed34e34f09e",
4
- "doctor.mjs": "32bcfbcf318ab72f81be6fa1d2106b7556e7978ed61bf0da0c79bc9f5da360d2",
2
+ "server.mjs": "59774785e2e9d3e930f7e96fa4b93843a557509137338e76ae9c0a5e93228db1",
3
+ "receiver.mjs": "8b5b6fdd6cb789cdc4060e367a155cb42e7cf34187044c899789bf76b7bb0e14",
4
+ "doctor.mjs": "63003135f4ffae0abbf962e46b6ef3840a2f9c83c46aff3b0b294e498a0d7e32",
5
5
  "review-data.mjs": "da7b6b35d060e09cfc445df4febda02a1a0c0f23d9b854866aed8d604cbb3993"
6
6
  }
package/dist/receiver.mjs CHANGED
@@ -830,7 +830,7 @@ function describe(value) {
830
830
  // src/guest/image-evidence.ts
831
831
  var safeId = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,159}$/.test(value);
832
832
  function afterRequested(request) {
833
- return !(request?.kind === "exec" && request.diagnostic === true) && request?.capture !== false && !["first", "member"].includes(request?.snapshots?.group?.phase ?? "");
833
+ return request?.diagnostic !== true && request?.capture !== false && !["first", "member"].includes(request?.snapshots?.group?.phase ?? "");
834
834
  }
835
835
  function validateImageEvidence(value, request, authoritativeSnapshots) {
836
836
  const fail = () => {
@@ -901,10 +901,9 @@ async function optionalJson(path) {
901
901
  function validate(request) {
902
902
  if (!safeId(request.executionId) || !safeId(request.sessionId) || !safeId(request.attemptId)) throw new Error("safe executionId, sessionId and attemptId are required");
903
903
  if (typeof request.because !== "string" || !request.because.trim() || request.because.length > 16384) throw new Error("nonblank because is required (maximum 16384 characters)");
904
- if (!["exec", "script", "code"].includes(request.kind)) throw new Error("kind must be exec, script or code");
905
904
  if (request.cwd !== void 0 && (!text(request.cwd) || !isAbsolute(request.cwd))) throw new Error("cwd must be an absolute path");
906
905
  if (request.timeoutMs !== void 0 && (!Number.isInteger(request.timeoutMs) || request.timeoutMs < 1 || request.timeoutMs > MAX_TIMEOUT_MS)) throw new Error("timeoutMs must be an integer from 1 to 3600000");
907
- if (request.diagnostic !== void 0 && (typeof request.diagnostic !== "boolean" || request.kind !== "exec")) throw new Error("diagnostic is allowed only for exec and must be boolean");
906
+ if (request.diagnostic !== void 0 && (typeof request.diagnostic !== "boolean" || request.language !== "shell")) throw new Error("diagnostic is allowed only for a shell script and must be boolean");
908
907
  if (request.step !== void 0 && (!request.step || !safeId(request.step.id) || !text(request.step.title) || request.step.expected !== void 0 && typeof request.step.expected !== "string" || request.step.inputMode !== void 0 && !["ordinary", "accessibility"].includes(request.step.inputMode))) throw new Error("invalid step metadata");
909
908
  const snapshots = request.snapshots;
910
909
  if (!snapshots || typeof snapshots !== "object" || Array.isArray(snapshots)) throw new Error("snapshots are required; no implicit interval");
@@ -916,11 +915,12 @@ function validate(request) {
916
915
  if (group.afterIntervalMs !== void 0 && !interval(group.afterIntervalMs)) throw new Error("invalid group afterIntervalMs");
917
916
  if (group.phase === "last" && !interval(group.afterIntervalMs ?? snapshots.afterIntervalMs)) throw new Error("last group member requires afterIntervalMs");
918
917
  } else if (!interval(snapshots.afterIntervalMs)) throw new Error("afterIntervalMs is required; no default");
919
- if (request.kind !== "code" && (!Array.isArray(request.argv) || request.argv.length === 0 || request.argv.length > 256 || !request.argv.every((arg, index) => typeof arg === "string" && !arg.includes("\0") && (index > 0 || arg.length > 0)))) throw new Error("argv must be a nonempty string vector without NULs (maximum 256 entries)");
920
- if (request.kind !== "exec" && !["javascript", "typescript", "python"].includes(request.language ?? "")) throw new Error("script/code language is required");
921
- if (request.kind === "code" && (typeof request.code !== "string" || !/^[a-f0-9]{64}$/.test(request.codeSha256 ?? ""))) throw new Error("code and its SHA-256 are required");
918
+ if (!["shell", "javascript", "typescript", "python"].includes(request.language ?? "")) throw new Error("language must be shell, javascript, typescript or python");
919
+ const inline = request.code !== void 0, file = request.remotePath !== void 0;
920
+ if (inline === file) throw new Error("a request holds either the script's code or its uploaded remotePath");
921
+ if (inline && (typeof request.code !== "string" || !/^[a-f0-9]{64}$/.test(request.codeSha256 ?? ""))) throw new Error("code and its SHA-256 are required");
922
922
  if (request.capture !== void 0 && typeof request.capture !== "boolean") throw new Error("capture must be boolean");
923
- if (request.kind === "script" && (!text(request.remotePath) || !isAbsolute(request.remotePath) || !/^[a-f0-9]{64}$/.test(request.scriptSha256 ?? ""))) throw new Error("absolute remotePath and script SHA-256 are required");
923
+ if (file && (!text(request.remotePath) || !isAbsolute(request.remotePath) || !/^[a-f0-9]{64}$/.test(request.scriptSha256 ?? ""))) throw new Error("absolute remotePath and script SHA-256 are required");
924
924
  }
925
925
  function groupAbsentFromProcessTable(group, table) {
926
926
  const lines = table.split("\n").map((line) => line.trim()).filter(Boolean);
@@ -1025,6 +1025,14 @@ async function runArgv(argv, options, onSpawn) {
1025
1025
  });
1026
1026
  });
1027
1027
  }
1028
+ async function executable(path) {
1029
+ try {
1030
+ await access(path, constants.X_OK);
1031
+ return true;
1032
+ } catch {
1033
+ return false;
1034
+ }
1035
+ }
1028
1036
  async function onPath(name) {
1029
1037
  for (const dir of (process.env.PATH ?? "").split(":")) {
1030
1038
  if (!dir) continue;
@@ -1036,7 +1044,11 @@ async function onPath(name) {
1036
1044
  }
1037
1045
  return false;
1038
1046
  }
1039
- async function interpreterArgv(language, path, find = onPath, node = { execPath: process.execPath, version: process.versions.node, strips: Boolean(process.features.typescript) }) {
1047
+ async function interpreterArgv(language, path, find = onPath, node = { execPath: process.execPath, version: process.versions.node, strips: Boolean(process.features.typescript) }, shell = executable) {
1048
+ if (language === "shell") {
1049
+ if (!await shell("/bin/sh")) throw new Error("the guest has no /bin/sh, so a shell script cannot run");
1050
+ return ["/bin/sh", path];
1051
+ }
1040
1052
  if (language === "python") {
1041
1053
  if (!await find("python3")) throw new Error("python3 is not on the guest's PATH, so a Python script cannot run; relay_probe scope=guest reports which runtimes the guest has");
1042
1054
  return ["python3", path];
@@ -1057,7 +1069,7 @@ async function captureWithDriver(outFile, driver, dispatch = runArgv) {
1057
1069
  async function receive(input, options = {}) {
1058
1070
  const request = input;
1059
1071
  const executionId = request && safeId(request.executionId) ? request.executionId : "unknown";
1060
- const evidenceMode = request?.kind === "exec" && request.diagnostic === true ? "diagnostic" : void 0;
1072
+ const evidenceMode = request?.diagnostic === true ? "diagnostic" : void 0;
1061
1073
  const uncaptured = request?.capture === false;
1062
1074
  const timeoutMs = request?.timeoutMs ?? 12e4;
1063
1075
  let imageEvidence = { status: afterRequested(request) ? "capture-unknown" : "not-requested", snapshots: [] };
@@ -1081,10 +1093,10 @@ async function receive(input, options = {}) {
1081
1093
  const operationPids = [];
1082
1094
  let pendingSpawn = false;
1083
1095
  const markLock = (active, settled = false) => durableJson(ownerPath, { pid: process.pid, executionId, active, operationPids, pendingSpawn, settled });
1084
- const runOwned = async (argv, dispatchOptions) => {
1096
+ const runOwned = async (argv2, dispatchOptions) => {
1085
1097
  pendingSpawn = true;
1086
1098
  await markLock(true);
1087
- const result = await runArgv(argv, dispatchOptions, async (pid) => {
1099
+ const result = await runArgv(argv2, dispatchOptions, async (pid) => {
1088
1100
  operationPids.push(pid);
1089
1101
  pendingSpawn = false;
1090
1102
  await markLock(true);
@@ -1096,6 +1108,7 @@ async function receive(input, options = {}) {
1096
1108
  };
1097
1109
  let reconcileGroup;
1098
1110
  let dispatchResult;
1111
+ let argv;
1099
1112
  const output = () => dispatchResult ? { stdout: bounded(dispatchResult.stdout), stderr: bounded(dispatchResult.stderr), timedOut: !!dispatchResult.timedOut, outputTruncated: !!dispatchResult.outputTruncated, terminationConfirmed: dispatchResult.terminationConfirmed } : {};
1100
1113
  try {
1101
1114
  await mkdir3(root, { recursive: true });
@@ -1186,7 +1199,7 @@ async function receive(input, options = {}) {
1186
1199
  imageEvidence = candidate;
1187
1200
  result = JSON.parse(JSON.stringify({ ...result, imageEvidence, evidenceMode, timeoutMs, ...output() }));
1188
1201
  if (result.outcome.kind !== "completed" || result.outcome.exitStatus.code !== 0) await reconcileGroup?.("operation failed or incomplete");
1189
- await store.putExecution({ executionId, ...ids, state: result.outcome.kind === "completed" ? "recorded" : result.outcome.kind, argv: request.argv, scriptId: request.scriptId, exitStatus: result.outcome.kind === "completed" ? result.outcome.exitStatus : void 0 });
1202
+ await store.putExecution({ executionId, ...ids, state: result.outcome.kind === "completed" ? "recorded" : result.outcome.kind, argv, scriptId: request.scriptId, exitStatus: result.outcome.kind === "completed" ? result.outcome.exitStatus : void 0 });
1190
1203
  await store.appendJournal({ kind: "execution-completion", ...ids, executionId, state: result.outcome.kind === "completed" ? "recorded" : result.outcome.kind, response: result }, { durable: true });
1191
1204
  await durableJson(receiptPath, result);
1192
1205
  return result;
@@ -1219,19 +1232,15 @@ async function receive(input, options = {}) {
1219
1232
  if (groups.active && (!group || group.groupId !== groups.active.groupId || request.sessionId !== groups.active.sessionId || request.attemptId !== groups.active.attemptId || group.phase === "first")) return await refuse("coalescing group is open; unrelated input is forbidden until its last member");
1220
1233
  if (!groups.active && group && (group.phase !== "first" || groups.used.includes(group.groupId))) return await refuse("coalescing group must begin with a fresh first member; group IDs cannot be reused");
1221
1234
  reconcileGroup = abandonGroup;
1222
- let argv = request.argv ?? [];
1223
1235
  try {
1224
- if (request.kind === "script") {
1236
+ if (request.remotePath !== void 0) {
1225
1237
  const info = await stat2(request.remotePath);
1226
1238
  if (!info.isFile() || info.size > MAX_SCRIPT_BYTES) throw new Error("script missing or exceeds size bound");
1227
1239
  if (hash(await readFile2(request.remotePath)) !== request.scriptSha256) throw new Error("script hash mismatch");
1228
- const expected = request.language === "python" ? "python3" : request.language === "typescript" ? "tsx" : "node";
1229
- if (argv.length !== 2 || argv[0].split("/").at(-1) !== expected || argv[1] !== request.remotePath) throw new Error("script argv must be [interpreter, verified remotePath]");
1230
1240
  argv = await interpreterArgv(request.language, request.remotePath);
1231
- } else if (request.kind === "code") {
1241
+ } else {
1232
1242
  if (hash(request.code) !== request.codeSha256) throw new Error("streamed code hash mismatch");
1233
- const extension = request.language === "python" ? "py" : request.language === "typescript" ? "ts" : "js";
1234
- const path = join3(root, "streamed", `${executionId}.${extension}`);
1243
+ const path = join3(root, "streamed", `${executionId}.${{ shell: "sh", python: "py", typescript: "ts", javascript: "js" }[request.language]}`);
1235
1244
  await mkdir3(dirname2(path), { recursive: true });
1236
1245
  const file = await open(path, "wx", 384);
1237
1246
  try {
@@ -1246,7 +1255,8 @@ async function receive(input, options = {}) {
1246
1255
  } catch (error) {
1247
1256
  return await refuse(message(error));
1248
1257
  }
1249
- await store.appendJournal({ kind: "execution-start", ...ids, executionId, state: "admitted", argv, cwd: request.cwd, step: request.step, evidenceMode, timeoutMs, ...uncaptured ? { capture: false } : {}, scriptIdentity: request.kind === "exec" ? void 0 : { sha256: request.kind === "code" ? request.codeSha256 : request.scriptSha256, language: request.language, remotePath: argv.at(-1) } }, { durable: true });
1258
+ const command = argv;
1259
+ await store.appendJournal({ kind: "execution-start", ...ids, executionId, state: "admitted", argv, cwd: request.cwd, step: request.step, evidenceMode, timeoutMs, ...uncaptured ? { capture: false } : {}, scriptIdentity: { sha256: request.remotePath === void 0 ? request.codeSha256 : request.scriptSha256, language: request.language, remotePath: argv.at(-1) } }, { durable: true });
1250
1260
  if (group?.phase === "first") {
1251
1261
  groups.active = { groupId: group.groupId, ...ids };
1252
1262
  groups.used.push(group.groupId);
@@ -1271,7 +1281,7 @@ async function receive(input, options = {}) {
1271
1281
  await markLock(true);
1272
1282
  try {
1273
1283
  const dispatchOptions = { cwd: request.cwd, env: process.env, timeoutMs };
1274
- dispatchResult = options.dispatch ? await options.dispatch(argv, dispatchOptions) : await runOwned(argv, dispatchOptions);
1284
+ dispatchResult = options.dispatch ? await options.dispatch(command, dispatchOptions) : await runOwned(command, dispatchOptions);
1275
1285
  return dispatchResult;
1276
1286
  } finally {
1277
1287
  if (dispatchResult && dispatchResult.terminationConfirmed !== false && !keepLock) {
@@ -1285,18 +1295,6 @@ async function receive(input, options = {}) {
1285
1295
  const diagnostic = captureFailure ?? engine.evidenceFailure ?? "missing required snapshot evidence";
1286
1296
  return await retain(response("uncertain", diagnostic));
1287
1297
  }
1288
- const driver = options.cuaDriver ?? process.env.RELAY_CUA_DRIVER;
1289
- if (request.kind === "exec" && driver && argv[0] === driver && argv[1] === "call" && outcome.exitStatus.code === 0) {
1290
- let value;
1291
- try {
1292
- value = JSON.parse(outcome.stdout ?? "");
1293
- } catch {
1294
- }
1295
- if (value && typeof value === "object" && (value.isError === true || value.error || typeof value.code === "string" && value.code.length > 0)) {
1296
- const diagnostic = `CUA structured failure: ${JSON.stringify(value)}`;
1297
- return await retain({ ...response(value.code === "desktop_escalation_required" ? "refused" : "uncertain", diagnostic), stdout: bounded(outcome.stdout), stderr: bounded(outcome.stderr) });
1298
- }
1299
- }
1300
1298
  const result = outcome.spawnError || outcome.timedOut || outcome.outputTruncated ? response("uncertain", outcome.spawnError ?? (outcome.timedOut ? "execution timed out" : "execution exceeded output bound")) : { executionId, outcome: { kind: "completed", exitStatus: outcome.exitStatus } };
1301
1299
  if (group?.phase === "last" && result.outcome.kind === "completed" && result.outcome.exitStatus.code === 0) {
1302
1300
  delete groups.active;