@rivet-dev/agentos-runtime-core 0.0.0-fix-main-wasm-ownership.8ca391b → 0.0.0-fix-core-spawn-keep-stdin-open.242e11c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +2 -2
  2. package/commands/[ +0 -0
  3. package/commands/_stubs +0 -0
  4. package/commands/awk +0 -0
  5. package/commands/bash +0 -0
  6. package/commands/chcon +0 -0
  7. package/commands/chroot +0 -0
  8. package/commands/column +0 -0
  9. package/commands/diff +0 -0
  10. package/commands/du +0 -0
  11. package/commands/egrep +0 -0
  12. package/commands/env +0 -0
  13. package/commands/expr +0 -0
  14. package/commands/fgrep +0 -0
  15. package/commands/file +0 -0
  16. package/commands/groups +0 -0
  17. package/commands/gunzip +0 -0
  18. package/commands/gzip +0 -0
  19. package/commands/hostid +0 -0
  20. package/commands/http-test +0 -0
  21. package/commands/install +0 -0
  22. package/commands/jq +0 -0
  23. package/commands/nice +0 -0
  24. package/commands/nohup +0 -0
  25. package/commands/pinky +0 -0
  26. package/commands/rev +0 -0
  27. package/commands/rg +0 -0
  28. package/commands/runcon +0 -0
  29. package/commands/sh +0 -0
  30. package/commands/sleep +0 -0
  31. package/commands/spawn-test-host +0 -0
  32. package/commands/sqlite3 +0 -0
  33. package/commands/ssh +0 -0
  34. package/commands/stdbuf +0 -0
  35. package/commands/strings +0 -0
  36. package/commands/stty +0 -0
  37. package/commands/sync +0 -0
  38. package/commands/tar +0 -0
  39. package/commands/test +0 -0
  40. package/commands/timeout +0 -0
  41. package/commands/tree +0 -0
  42. package/commands/tty +0 -0
  43. package/commands/unzip +0 -0
  44. package/commands/uptime +0 -0
  45. package/commands/users +0 -0
  46. package/commands/wget +0 -0
  47. package/commands/which +0 -0
  48. package/commands/who +0 -0
  49. package/commands/whoami +0 -0
  50. package/commands/yq +0 -0
  51. package/commands/zcat +0 -0
  52. package/commands/zip +0 -0
  53. package/dist/binary.js +4 -3
  54. package/dist/event-buffer.d.ts +14 -0
  55. package/dist/event-buffer.js +30 -1
  56. package/dist/frame-stream.d.ts +1 -0
  57. package/dist/frame-stream.js +8 -0
  58. package/dist/generated/ExecutionLimitsConfig.d.ts +5 -0
  59. package/dist/generated/ExecutionLimitsConfig.js +2 -0
  60. package/dist/generated/VmLimitsConfig.d.ts +2 -0
  61. package/dist/generated/VmSqliteDescriptor.d.ts +0 -1
  62. package/dist/generated-protocol.d.ts +550 -0
  63. package/dist/generated-protocol.js +1446 -122
  64. package/dist/kernel-proxy.js +1 -1
  65. package/dist/native-client.js +22 -9
  66. package/dist/node-runtime.js +5 -5
  67. package/dist/process.d.ts +4 -2
  68. package/dist/process.js +11 -3
  69. package/dist/protocol-client.d.ts +2 -0
  70. package/dist/protocol-client.js +29 -0
  71. package/dist/request-payloads.d.ts +96 -0
  72. package/dist/request-payloads.js +66 -0
  73. package/dist/response-payloads.d.ts +27 -0
  74. package/dist/response-payloads.js +18 -0
  75. package/dist/sidecar-process.d.ts +8 -1
  76. package/dist/sidecar-process.js +27 -2
  77. package/dist/test-runtime.d.ts +7 -1
  78. package/dist/test-runtime.js +97 -15
  79. package/package.json +11 -8
@@ -5,9 +5,9 @@ import * as path from "node:path";
5
5
  import * as posixPath from "node:path/posix";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import "./native-client.js";
8
- import { NativeSidecarKernelProxy, SidecarProcess, serializeMountConfigForSidecar, } from "./kernel-proxy.js";
9
8
  import { resolvePublishedSidecarBinary } from "./binary.js";
10
9
  import { findCargoBinary, resolveCargoBinary } from "./cargo.js";
10
+ import { NativeSidecarKernelProxy, SidecarProcess, serializeMountConfigForSidecar, } from "./kernel-proxy.js";
11
11
  export const AF_INET = 2;
12
12
  export const AF_UNIX = 1;
13
13
  export const SOCK_STREAM = 1;
@@ -1161,7 +1161,7 @@ class WasmVmRuntimeDescriptor {
1161
1161
  if (dirOffset === undefined) {
1162
1162
  continue;
1163
1163
  }
1164
- guestPaths.set(name, `/__secure_exec/commands/${startIndex + dirOffset}/${name}`);
1164
+ guestPaths.set(name, `/__agentos/commands/${startIndex + dirOffset}/${name}`);
1165
1165
  }
1166
1166
  return guestPaths;
1167
1167
  }
@@ -1220,7 +1220,8 @@ function sidecarBinaryNeedsBuild() {
1220
1220
  function ensureNativeSidecarBinary() {
1221
1221
  // A published install has no in-repo Cargo workspace to build from: resolve
1222
1222
  // the prebuilt platform binary (or an explicit sidecar override).
1223
- if (process.env.AGENTOS_SIDECAR_BIN ||
1223
+ if (process.env.AGENTOS_NATIVE_SIDECAR_BIN ||
1224
+ process.env.AGENTOS_SIDECAR_BIN ||
1224
1225
  !fsSync.existsSync(path.join(REPO_ROOT, "Cargo.toml"))) {
1225
1226
  return resolvePublishedSidecarBinary();
1226
1227
  }
@@ -1262,9 +1263,13 @@ function createBootstrapEntries(commandNames) {
1262
1263
  ...KERNEL_POSIX_BOOTSTRAP_DIRS.map((entryPath) => ({
1263
1264
  path: entryPath,
1264
1265
  kind: "directory",
1265
- mode: entryPath === "/tmp" || entryPath === "/var/tmp" ? 0o1777 : 0o755,
1266
- uid: 0,
1267
- gid: 0,
1266
+ mode: entryPath === "/tmp" || entryPath === "/var/tmp"
1267
+ ? 0o1777
1268
+ : entryPath === "/home/agentos"
1269
+ ? 0o2755
1270
+ : 0o755,
1271
+ uid: entryPath === "/home/agentos" || entryPath === "/workspace" ? 1000 : 0,
1272
+ gid: entryPath === "/home/agentos" || entryPath === "/workspace" ? 1000 : 0,
1268
1273
  })),
1269
1274
  {
1270
1275
  path: "/usr/bin/env",
@@ -1413,17 +1418,88 @@ function planNodeFilesystemPassthroughMounts(filesystem, existingMounts) {
1413
1418
  fs: new NodeFileSystem({ root: hostPath }),
1414
1419
  readOnly: true,
1415
1420
  });
1421
+ if (directoryName === "node_modules") {
1422
+ appendNodeModulesSymlinkTargetMounts(mounts, existingGuestPaths, guestPath, hostPath);
1423
+ }
1416
1424
  }
1417
1425
  return {
1418
1426
  mounts,
1419
1427
  passthroughDirectories,
1420
1428
  };
1421
1429
  }
1430
+ function appendNodeModulesSymlinkTargetMounts(mounts, existingGuestPaths, guestRoot, hostRoot) {
1431
+ let canonicalHostRoot;
1432
+ try {
1433
+ canonicalHostRoot = fsSync.realpathSync(hostRoot);
1434
+ }
1435
+ catch {
1436
+ return;
1437
+ }
1438
+ const appendTarget = (guestPath, symlinkPath) => {
1439
+ if (existingGuestPaths.has(guestPath))
1440
+ return;
1441
+ try {
1442
+ const target = fsSync.realpathSync(symlinkPath);
1443
+ if (!fsSync.statSync(target).isDirectory())
1444
+ return;
1445
+ const relativeTarget = path.relative(canonicalHostRoot, target);
1446
+ if (relativeTarget === "" ||
1447
+ (!relativeTarget.startsWith(`..${path.sep}`) &&
1448
+ relativeTarget !== ".." &&
1449
+ !path.isAbsolute(relativeTarget))) {
1450
+ // pnpm and similar stores deliberately use links that remain inside
1451
+ // node_modules. Keeping those on the root mount preserves the realpath
1452
+ // ancestry needed to resolve their nested dependency links.
1453
+ return;
1454
+ }
1455
+ mounts.push({
1456
+ path: guestPath,
1457
+ fs: new NodeFileSystem({ root: target }),
1458
+ readOnly: true,
1459
+ });
1460
+ existingGuestPaths.add(guestPath);
1461
+ }
1462
+ catch {
1463
+ // Broken or concurrently-removed links remain unavailable, matching Node.
1464
+ }
1465
+ };
1466
+ let entries;
1467
+ try {
1468
+ entries = fsSync.readdirSync(hostRoot, { withFileTypes: true });
1469
+ }
1470
+ catch {
1471
+ return;
1472
+ }
1473
+ for (const entry of entries) {
1474
+ if (entry.name.startsWith("."))
1475
+ continue;
1476
+ const entryPath = path.join(hostRoot, entry.name);
1477
+ if (entry.isSymbolicLink()) {
1478
+ appendTarget(`${guestRoot}/${entry.name}`, entryPath);
1479
+ continue;
1480
+ }
1481
+ if (!entry.isDirectory() || !entry.name.startsWith("@"))
1482
+ continue;
1483
+ let scopedEntries;
1484
+ try {
1485
+ scopedEntries = fsSync.readdirSync(entryPath, { withFileTypes: true });
1486
+ }
1487
+ catch {
1488
+ continue;
1489
+ }
1490
+ for (const scopedEntry of scopedEntries) {
1491
+ if (scopedEntry.name.startsWith(".") || !scopedEntry.isSymbolicLink()) {
1492
+ continue;
1493
+ }
1494
+ appendTarget(`${guestRoot}/${entry.name}/${scopedEntry.name}`, path.join(entryPath, scopedEntry.name));
1495
+ }
1496
+ }
1497
+ }
1422
1498
  function collectGuestCommandPaths(commandDirs, startIndex = 0) {
1423
1499
  const guestPaths = new Map();
1424
1500
  for (const entry of discoverWasmCommandEntries(commandDirs)) {
1425
1501
  if (!guestPaths.has(entry.name)) {
1426
- guestPaths.set(entry.name, `/__secure_exec/commands/${startIndex + entry.dirOffset}/${entry.name}`);
1502
+ guestPaths.set(entry.name, `/__agentos/commands/${startIndex + entry.dirOffset}/${entry.name}`);
1427
1503
  }
1428
1504
  }
1429
1505
  return guestPaths;
@@ -1434,10 +1510,7 @@ async function ensureCommandStubs(proxy, commands) {
1434
1510
  // `/bin` supports PATH-based test commands. `/opt/agentos/bin` mirrors
1435
1511
  // the package projection used by production VMs and is required by
1436
1512
  // upstream tools that exec private helpers via an absolute libexec path.
1437
- for (const stubPath of [
1438
- `/bin/${command}`,
1439
- `/opt/agentos/bin/${command}`,
1440
- ]) {
1513
+ for (const stubPath of [`/bin/${command}`, `/opt/agentos/bin/${command}`]) {
1441
1514
  await rootView.writeFile(stubPath, KERNEL_COMMAND_STUB);
1442
1515
  await rootView.chmod(stubPath, 0o755);
1443
1516
  }
@@ -1604,9 +1677,15 @@ async function syncLiveFilesystemToBoundMethods(live, methods, paths, maxBytes)
1604
1677
  }
1605
1678
  async function snapshotLiveFilesystemPath(live, targetPath, snapshot, usage, maxBytes, knownEntry) {
1606
1679
  const stat = knownEntry ??
1607
- (targetPath === "/" ? await live.stat(targetPath) : await live.lstat(targetPath));
1680
+ (targetPath === "/"
1681
+ ? await live.stat(targetPath)
1682
+ : await live.lstat(targetPath));
1608
1683
  if (stat.isSymbolicLink) {
1609
- snapshot.push({ kind: "symlink", path: targetPath, target: await live.readlink(targetPath) });
1684
+ snapshot.push({
1685
+ kind: "symlink",
1686
+ path: targetPath,
1687
+ target: await live.readlink(targetPath),
1688
+ });
1610
1689
  return;
1611
1690
  }
1612
1691
  if (stat.isDirectory) {
@@ -1638,7 +1717,9 @@ async function snapshotLiveFilesystemPath(live, targetPath, snapshot, usage, max
1638
1717
  }
1639
1718
  async function applyLiveFilesystemSnapshotEntry(methods, entry) {
1640
1719
  if (entry.kind === "directory") {
1641
- await callBoundFilesystemMethod(methods, "mkdir", entry.path, { recursive: true });
1720
+ await callBoundFilesystemMethod(methods, "mkdir", entry.path, {
1721
+ recursive: true,
1722
+ });
1642
1723
  return;
1643
1724
  }
1644
1725
  await ensureBoundParentDirectory(methods, entry.path);
@@ -1783,7 +1864,7 @@ class NativeKernel {
1783
1864
  collectGuestCommandPaths(commandDirs, startIndex);
1784
1865
  const allCommandDirs = [...this.mountedCommandDirs, ...commandDirs];
1785
1866
  const sidecarMounts = allCommandDirs.map((commandDir, index) => serializeMountConfigForSidecar({
1786
- path: `/__secure_exec/commands/${index}`,
1867
+ path: `/__agentos/commands/${index}`,
1787
1868
  readOnly: true,
1788
1869
  plugin: {
1789
1870
  id: "host_dir",
@@ -2136,6 +2217,7 @@ class NativeKernel {
2136
2217
  ? { permissions: bootstrapPermissions }
2137
2218
  : {}),
2138
2219
  loopbackExemptPorts: this.loopbackExemptPorts,
2220
+ ...(this.options.limits ? { limits: this.options.limits } : {}),
2139
2221
  ...(this.options.jsRuntime
2140
2222
  ? { jsRuntime: this.options.jsRuntime }
2141
2223
  : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivet-dev/agentos-runtime-core",
3
- "version": "0.0.0-fix-main-wasm-ownership.8ca391b",
3
+ "version": "0.0.0-fix-core-spawn-keep-stdin-open.242e11c",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -184,17 +184,20 @@
184
184
  },
185
185
  "scripts": {
186
186
  "build:protocol": "pnpm --dir ../build-tools build:protocol",
187
- "build:vm-config": "cargo test -p agentos-vm-config --quiet",
187
+ "generate:vm-config": "cargo test -p agentos-vm-config --quiet",
188
188
  "copy-commands": "node scripts/copy-wasm-commands.mjs",
189
- "check-types": "pnpm run build:protocol && pnpm run build:vm-config && tsc --noEmit",
190
- "build": "pnpm run build:protocol && pnpm run build:vm-config && tsc && pnpm run copy-commands",
189
+ "check-types": "pnpm run build:protocol && tsc --noEmit",
190
+ "build": "pnpm run build:protocol && tsc && pnpm run copy-commands",
191
191
  "prepack": "node scripts/copy-wasm-commands.mjs --require",
192
- "pretest": "cargo build -q -p agentos-native-sidecar",
193
- "test": "vitest run",
194
- "test:ecosystem": "AGENTOS_ECOSYSTEM_E2E=1 vitest run tests/integration/e2e-project-matrix.test.ts -t 'required Node ecosystem reactor matrix' --reporter=verbose"
192
+ "test": "vitest run --exclude '**/*.nightly.test.ts'",
193
+ "test:pr": "vitest run --exclude '**/*.nightly.test.ts' --fileParallelism=false",
194
+ "test:nightly": "vitest run tests/integration/*.nightly.test.ts --passWithNoTests",
195
+ "test:ecosystem": "AGENTOS_ECOSYSTEM_E2E=1 vitest run tests/integration/e2e-project-matrix.nightly.test.ts -t 'required Node ecosystem reactor matrix' --reporter=verbose",
196
+ "test:ecosystem:full": "AGENTOS_ECOSYSTEM_FULL_E2E=1 vitest run tests/integration/e2e-project-matrix.nightly.test.ts -t 'full Node ecosystem matrix through kernel' --reporter=verbose",
197
+ "test:npm-workflows": "AGENTOS_NPM_WORKFLOWS_E2E=1 vitest run tests/integration/e2e-npm-*.nightly.test.ts tests/integration/e2e-npx-and-pipes.nightly.test.ts tests/integration/e2e-concurrently.nightly.test.ts tests/integration/e2e-nextjs-build.nightly.test.ts --reporter=verbose"
195
198
  },
196
199
  "dependencies": {
197
- "@rivet-dev/agentos-runtime-sidecar": "0.0.0-fix-main-wasm-ownership.8ca391b",
200
+ "@rivet-dev/agentos-runtime-sidecar": "0.0.0-fix-core-spawn-keep-stdin-open.242e11c",
198
201
  "@rivetkit/bare-ts": "^0.6.2",
199
202
  "zod": "^4.1.11"
200
203
  },