@rivet-dev/agentos-runtime-core 0.0.0-codex-actor-plugin-contract-coverage.115ca8a → 0.0.0-fix-main-wasm-ownership.150c49a

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 (238) hide show
  1. package/commands/[ +0 -0
  2. package/commands/_stubs +0 -0
  3. package/commands/acl_tools +0 -0
  4. package/commands/arch +0 -0
  5. package/commands/attr +0 -0
  6. package/commands/awk +0 -0
  7. package/commands/b2sum +0 -0
  8. package/commands/base32 +0 -0
  9. package/commands/base64 +0 -0
  10. package/commands/basename +0 -0
  11. package/commands/basenc +0 -0
  12. package/commands/bash +0 -0
  13. package/commands/bc +0 -0
  14. package/commands/cat +0 -0
  15. package/commands/chacl +0 -0
  16. package/commands/chcon +0 -0
  17. package/commands/chgrp +0 -0
  18. package/commands/chmod +0 -0
  19. package/commands/chown +0 -0
  20. package/commands/chroot +0 -0
  21. package/commands/cksum +0 -0
  22. package/commands/cmp +0 -0
  23. package/commands/column +0 -0
  24. package/commands/comm +0 -0
  25. package/commands/cp +0 -0
  26. package/commands/curl +0 -0
  27. package/commands/cut +0 -0
  28. package/commands/date +0 -0
  29. package/commands/dd +0 -0
  30. package/commands/df +0 -0
  31. package/commands/diff +0 -0
  32. package/commands/dir +0 -0
  33. package/commands/dircolors +0 -0
  34. package/commands/dirname +0 -0
  35. package/commands/du +0 -0
  36. package/commands/echo +0 -0
  37. package/commands/egrep +0 -0
  38. package/commands/env +0 -0
  39. package/commands/envsubst +0 -0
  40. package/commands/expand +0 -0
  41. package/commands/expr +0 -0
  42. package/commands/factor +0 -0
  43. package/commands/false +0 -0
  44. package/commands/fd +0 -0
  45. package/commands/fgrep +0 -0
  46. package/commands/file +0 -0
  47. package/commands/find +0 -0
  48. package/commands/findmnt +0 -0
  49. package/commands/fmt +0 -0
  50. package/commands/fold +0 -0
  51. package/commands/getent +0 -0
  52. package/commands/getfacl +0 -0
  53. package/commands/getfattr +0 -0
  54. package/commands/git +0 -0
  55. package/commands/git-receive-pack +0 -0
  56. package/commands/git-remote-http +0 -0
  57. package/commands/git-remote-https +0 -0
  58. package/commands/git-upload-archive +0 -0
  59. package/commands/git-upload-pack +0 -0
  60. package/commands/grep +0 -0
  61. package/commands/groups +0 -0
  62. package/commands/gunzip +0 -0
  63. package/commands/gzip +0 -0
  64. package/commands/head +0 -0
  65. package/commands/hostid +0 -0
  66. package/commands/hostname +0 -0
  67. package/commands/http-test +0 -0
  68. package/commands/id +0 -0
  69. package/commands/install +0 -0
  70. package/commands/join +0 -0
  71. package/commands/jq +0 -0
  72. package/commands/kill +0 -0
  73. package/commands/link +0 -0
  74. package/commands/ln +0 -0
  75. package/commands/logname +0 -0
  76. package/commands/ls +0 -0
  77. package/commands/md5sum +0 -0
  78. package/commands/mkdir +0 -0
  79. package/commands/mkfifo +0 -0
  80. package/commands/mknod +0 -0
  81. package/commands/mktemp +0 -0
  82. package/commands/more +0 -0
  83. package/commands/mount +0 -0
  84. package/commands/mv +0 -0
  85. package/commands/nice +0 -0
  86. package/commands/nl +0 -0
  87. package/commands/nohup +0 -0
  88. package/commands/nproc +0 -0
  89. package/commands/numfmt +0 -0
  90. package/commands/od +0 -0
  91. package/commands/paste +0 -0
  92. package/commands/pathchk +0 -0
  93. package/commands/pinky +0 -0
  94. package/commands/printenv +0 -0
  95. package/commands/printf +0 -0
  96. package/commands/ptx +0 -0
  97. package/commands/pwd +0 -0
  98. package/commands/readlink +0 -0
  99. package/commands/realpath +0 -0
  100. package/commands/rev +0 -0
  101. package/commands/rg +0 -0
  102. package/commands/rm +0 -0
  103. package/commands/rmdir +0 -0
  104. package/commands/runas +0 -0
  105. package/commands/runcon +0 -0
  106. package/commands/sed +0 -0
  107. package/commands/seq +0 -0
  108. package/commands/setfacl +0 -0
  109. package/commands/setfattr +0 -0
  110. package/commands/sh +0 -0
  111. package/commands/sha1sum +0 -0
  112. package/commands/sha224sum +0 -0
  113. package/commands/sha256sum +0 -0
  114. package/commands/sha384sum +0 -0
  115. package/commands/sha512sum +0 -0
  116. package/commands/shred +0 -0
  117. package/commands/shuf +0 -0
  118. package/commands/sleep +0 -0
  119. package/commands/sort +0 -0
  120. package/commands/spawn-test-host +0 -0
  121. package/commands/split +0 -0
  122. package/commands/sqlite3 +0 -0
  123. package/commands/ssh +0 -0
  124. package/commands/ssh-keysign +0 -0
  125. package/commands/ssh-sk-helper +0 -0
  126. package/commands/stat +0 -0
  127. package/commands/stdbuf +0 -0
  128. package/commands/strings +0 -0
  129. package/commands/stty +0 -0
  130. package/commands/su +0 -0
  131. package/commands/sum +0 -0
  132. package/commands/sync +0 -0
  133. package/commands/tac +0 -0
  134. package/commands/tail +0 -0
  135. package/commands/tar +0 -0
  136. package/commands/tee +0 -0
  137. package/commands/test +0 -0
  138. package/commands/timeout +0 -0
  139. package/commands/touch +0 -0
  140. package/commands/tr +0 -0
  141. package/commands/tree +0 -0
  142. package/commands/true +0 -0
  143. package/commands/truncate +0 -0
  144. package/commands/tsort +0 -0
  145. package/commands/tty +0 -0
  146. package/commands/uname +0 -0
  147. package/commands/unexpand +0 -0
  148. package/commands/uniq +0 -0
  149. package/commands/unlink +0 -0
  150. package/commands/unzip +0 -0
  151. package/commands/uptime +0 -0
  152. package/commands/users +0 -0
  153. package/commands/vdir +0 -0
  154. package/commands/wc +0 -0
  155. package/commands/wget +0 -0
  156. package/commands/which +0 -0
  157. package/commands/who +0 -0
  158. package/commands/whoami +0 -0
  159. package/commands/xargs +0 -0
  160. package/commands/xattr_tools +0 -0
  161. package/commands/xfs_io +0 -0
  162. package/commands/xu +0 -0
  163. package/commands/yes +0 -0
  164. package/commands/yq +0 -0
  165. package/commands/zcat +0 -0
  166. package/commands/zip +0 -0
  167. package/dist/correlation.d.ts +1 -4
  168. package/dist/correlation.js +7 -10
  169. package/dist/descriptors.d.ts +2 -12
  170. package/dist/descriptors.js +10 -6
  171. package/dist/frame-rpc.d.ts +9 -4
  172. package/dist/frame-rpc.js +19 -2
  173. package/dist/frame-stream.d.ts +33 -0
  174. package/dist/frame-stream.js +113 -0
  175. package/dist/generated/AcpLimitsConfig.d.ts +16 -0
  176. package/dist/generated/BindingLimitsConfig.d.ts +10 -0
  177. package/dist/generated/CreateVmConfig.d.ts +4 -0
  178. package/dist/generated/Http2LimitsConfig.d.ts +12 -0
  179. package/dist/generated/Http2LimitsConfig.js +2 -0
  180. package/dist/generated/JsRuntimeLimitsConfig.d.ts +1 -0
  181. package/dist/generated/MountPluginDescriptor.d.ts +1 -1
  182. package/dist/generated/ProcessLimitsConfig.d.ts +7 -0
  183. package/dist/generated/ProcessLimitsConfig.js +2 -0
  184. package/dist/generated/ReactorLimitsConfig.d.ts +23 -0
  185. package/dist/generated/ReactorLimitsConfig.js +2 -0
  186. package/dist/generated/SqliteLimitsConfig.d.ts +3 -0
  187. package/dist/generated/SqliteLimitsConfig.js +2 -0
  188. package/dist/generated/TlsLimitsConfig.d.ts +3 -0
  189. package/dist/generated/TlsLimitsConfig.js +2 -0
  190. package/dist/generated/UdpLimitsConfig.d.ts +4 -0
  191. package/dist/generated/UdpLimitsConfig.js +2 -0
  192. package/dist/generated/VmGroupConfig.d.ts +5 -0
  193. package/dist/generated/VmGroupConfig.js +2 -0
  194. package/dist/generated/VmLimitsConfig.d.ts +14 -2
  195. package/dist/generated/VmSqliteDescriptor.d.ts +11 -0
  196. package/dist/generated/VmSqliteDescriptor.js +2 -0
  197. package/dist/generated/VmUserAccountConfig.d.ts +9 -0
  198. package/dist/generated/VmUserAccountConfig.js +2 -0
  199. package/dist/generated/VmUserConfig.d.ts +19 -0
  200. package/dist/generated/VmUserConfig.js +1 -0
  201. package/dist/generated/WasmLimitsConfig.d.ts +1 -0
  202. package/dist/generated-protocol.d.ts +60 -2
  203. package/dist/generated-protocol.js +166 -31
  204. package/dist/kernel-proxy.d.ts +5 -1
  205. package/dist/kernel-proxy.js +77 -39
  206. package/dist/native-client.d.ts +9 -5
  207. package/dist/native-client.js +41 -9
  208. package/dist/node-runtime-options-schema.d.ts +1 -1
  209. package/dist/node-runtime-options-schema.js +43 -1
  210. package/dist/node-runtime.d.ts +12 -3
  211. package/dist/node-runtime.js +8 -7
  212. package/dist/process.d.ts +3 -1
  213. package/dist/process.js +27 -8
  214. package/dist/protocol-client.d.ts +26 -4
  215. package/dist/protocol-client.js +164 -12
  216. package/dist/protocol-frames.d.ts +14 -3
  217. package/dist/protocol-frames.js +26 -1
  218. package/dist/protocol-schema.d.ts +1 -1
  219. package/dist/protocol-schema.js +1 -1
  220. package/dist/request-payloads.d.ts +4 -1
  221. package/dist/request-payloads.js +7 -2
  222. package/dist/response-payloads.d.ts +23 -2
  223. package/dist/response-payloads.js +34 -2
  224. package/dist/sidecar-errors.d.ts +37 -0
  225. package/dist/sidecar-errors.js +27 -0
  226. package/dist/sidecar-process.d.ts +20 -6
  227. package/dist/sidecar-process.js +79 -15
  228. package/dist/state.d.ts +6 -6
  229. package/dist/state.js +10 -11
  230. package/dist/test-runtime.d.ts +21 -6
  231. package/dist/test-runtime.js +129 -65
  232. package/dist/vm-config.d.ts +5 -1
  233. package/package.json +5 -3
  234. package/commands/codex +0 -0
  235. package/commands/codex-exec +0 -0
  236. package/commands/http_get +0 -0
  237. package/dist/generated/ToolLimitsConfig.d.ts +0 -10
  238. /package/dist/generated/{ToolLimitsConfig.js → BindingLimitsConfig.js} +0 -0
@@ -5,7 +5,7 @@ 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 { NATIVE_SIDECAR_FRAME_TIMEOUT_MS, NativeSidecarKernelProxy, SidecarProcess, serializeMountConfigForSidecar, } from "./kernel-proxy.js";
8
+ import { NativeSidecarKernelProxy, SidecarProcess, serializeMountConfigForSidecar, } from "./kernel-proxy.js";
9
9
  import { resolvePublishedSidecarBinary } from "./binary.js";
10
10
  import { findCargoBinary, resolveCargoBinary } from "./cargo.js";
11
11
  export const AF_INET = 2;
@@ -33,6 +33,8 @@ const KERNEL_POSIX_BOOTSTRAP_DIRS = [
33
33
  "/srv",
34
34
  "/sys",
35
35
  "/opt",
36
+ "/opt/agentos",
37
+ "/opt/agentos/bin",
36
38
  "/mnt",
37
39
  "/media",
38
40
  "/home",
@@ -66,9 +68,21 @@ const SIDECAR_BUILD_INPUTS = [
66
68
  path.join(REPO_ROOT, "Cargo.toml"),
67
69
  path.join(REPO_ROOT, "Cargo.lock"),
68
70
  path.join(REPO_ROOT, "crates/bridge"),
71
+ path.join(REPO_ROOT, "crates/build-support"),
69
72
  path.join(REPO_ROOT, "crates/execution"),
70
73
  path.join(REPO_ROOT, "crates/kernel"),
71
- path.join(REPO_ROOT, "crates/sidecar"),
74
+ path.join(REPO_ROOT, "crates/native-sidecar"),
75
+ path.join(REPO_ROOT, "crates/native-sidecar-core"),
76
+ path.join(REPO_ROOT, "crates/sidecar-protocol"),
77
+ path.join(REPO_ROOT, "crates/v8-runtime"),
78
+ path.join(REPO_ROOT, "crates/vfs"),
79
+ path.join(REPO_ROOT, "crates/vm-config"),
80
+ path.join(REPO_ROOT, "packages/build-tools/bridge-src"),
81
+ path.join(REPO_ROOT, "packages/build-tools/package.json"),
82
+ path.join(REPO_ROOT, "packages/build-tools/scripts/build-v8-bridge.mjs"),
83
+ path.join(REPO_ROOT, "packages/core/fixtures/base-filesystem.json"),
84
+ path.join(REPO_ROOT, "packages/runtime-core/fixtures/base-filesystem.json"),
85
+ path.join(REPO_ROOT, "pnpm-lock.yaml"),
72
86
  ];
73
87
  let ensuredSidecarBinary = null;
74
88
  export class KernelError extends Error {
@@ -325,8 +339,10 @@ export class InMemoryFileSystem {
325
339
  typeBits === 0 ? (entry.mode & 0o170000) | (mode & 0o7777) : mode;
326
340
  entry.ctimeMs = Date.now();
327
341
  }
328
- async chown(targetPath, uid, gid) {
329
- const entry = this.resolveEntry(targetPath);
342
+ async chown(targetPath, uid, gid, options) {
343
+ const entry = options?.followSymlinks === false
344
+ ? this.entries.get(normalizePath(targetPath))
345
+ : this.resolveEntry(targetPath);
330
346
  if (!entry)
331
347
  throw errnoError("ENOENT", `chown '${targetPath}'`);
332
348
  entry.uid = uid;
@@ -548,8 +564,14 @@ export class NodeFileSystem {
548
564
  async chmod(targetPath, mode) {
549
565
  await fs.chmod(this.normalizeTarget(targetPath), mode);
550
566
  }
551
- async chown(targetPath, uid, gid) {
552
- await fs.chown(this.normalizeTarget(targetPath), uid, gid);
567
+ async chown(targetPath, uid, gid, options) {
568
+ const normalized = this.normalizeTarget(targetPath);
569
+ if (options?.followSymlinks === false) {
570
+ await fs.lchown(normalized, uid, gid);
571
+ }
572
+ else {
573
+ await fs.chown(normalized, uid, gid);
574
+ }
553
575
  }
554
576
  async utimes(targetPath, atime, mtime) {
555
577
  await fs.utimes(this.normalizeTarget(targetPath), atime / 1000, mtime / 1000);
@@ -569,7 +591,7 @@ export class NodeFileSystem {
569
591
  }
570
592
  }
571
593
  async pwrite(targetPath, offset, data) {
572
- const handle = await fs.open(this.normalizeTarget(targetPath), "r+");
594
+ const handle = await fs.open(this.normalizeTarget(targetPath), fsSync.constants.O_WRONLY);
573
595
  try {
574
596
  await handle.write(data, 0, data.length, offset);
575
597
  }
@@ -857,7 +879,6 @@ export const WASMVM_COMMANDS = Object.freeze([
857
879
  "unzip",
858
880
  "sqlite3",
859
881
  "curl",
860
- "wget",
861
882
  "git",
862
883
  "git-remote-http",
863
884
  "git-remote-https",
@@ -1021,7 +1042,6 @@ export const DEFAULT_FIRST_PARTY_TIERS = Object.freeze({
1021
1042
  tac: "read-only",
1022
1043
  tsort: "read-only",
1023
1044
  curl: "full",
1024
- wget: "full",
1025
1045
  sqlite3: "read-write",
1026
1046
  });
1027
1047
  class NativeRuntimeDescriptor {
@@ -1148,8 +1168,8 @@ class WasmVmRuntimeDescriptor {
1148
1168
  recordModuleExecution(command) {
1149
1169
  const normalized = normalizeCommandLookup(command);
1150
1170
  if (this._commandPaths.has(normalized) ||
1151
- (!this.commandDirs || this.commandDirs.length === 0) &&
1152
- this.commands.includes(normalized)) {
1171
+ ((!this.commandDirs || this.commandDirs.length === 0) &&
1172
+ this.commands.includes(normalized))) {
1153
1173
  this._moduleCache.set(normalized, true);
1154
1174
  }
1155
1175
  }
@@ -1201,7 +1221,6 @@ function ensureNativeSidecarBinary() {
1201
1221
  // A published install has no in-repo Cargo workspace to build from: resolve
1202
1222
  // the prebuilt platform binary (or an explicit sidecar override).
1203
1223
  if (process.env.AGENTOS_SIDECAR_BIN ||
1204
- process.env.AGENTOS_SIDECAR_BIN ||
1205
1224
  !fsSync.existsSync(path.join(REPO_ROOT, "Cargo.toml"))) {
1206
1225
  return resolvePublishedSidecarBinary();
1207
1226
  }
@@ -1243,7 +1262,7 @@ function createBootstrapEntries(commandNames) {
1243
1262
  ...KERNEL_POSIX_BOOTSTRAP_DIRS.map((entryPath) => ({
1244
1263
  path: entryPath,
1245
1264
  kind: "directory",
1246
- mode: 0o755,
1265
+ mode: entryPath === "/tmp" || entryPath === "/var/tmp" ? 0o1777 : 0o755,
1247
1266
  uid: 0,
1248
1267
  gid: 0,
1249
1268
  })),
@@ -1412,9 +1431,16 @@ function collectGuestCommandPaths(commandDirs, startIndex = 0) {
1412
1431
  async function ensureCommandStubs(proxy, commands) {
1413
1432
  const rootView = proxy.createRootView();
1414
1433
  for (const command of commands) {
1415
- const stubPath = `/bin/${command}`;
1416
- await rootView.writeFile(stubPath, KERNEL_COMMAND_STUB);
1417
- await rootView.chmod(stubPath, 0o755);
1434
+ // `/bin` supports PATH-based test commands. `/opt/agentos/bin` mirrors
1435
+ // the package projection used by production VMs and is required by
1436
+ // 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
+ ]) {
1441
+ await rootView.writeFile(stubPath, KERNEL_COMMAND_STUB);
1442
+ await rootView.chmod(stubPath, 0o755);
1443
+ }
1418
1444
  }
1419
1445
  }
1420
1446
  class DeferredFileSystem {
@@ -1483,8 +1509,8 @@ class DeferredFileSystem {
1483
1509
  chmod(path, mode) {
1484
1510
  return this.filesystem().chmod(path, mode);
1485
1511
  }
1486
- chown(path, uid, gid) {
1487
- return this.filesystem().chown(path, uid, gid);
1512
+ chown(path, uid, gid, options) {
1513
+ return this.filesystem().chown(path, uid, gid, options);
1488
1514
  }
1489
1515
  utimes(path, atime, mtime) {
1490
1516
  return this.filesystem().utimes(path, atime, mtime);
@@ -1524,7 +1550,10 @@ const VIRTUAL_FILESYSTEM_METHOD_NAMES = [
1524
1550
  "pread",
1525
1551
  "pwrite",
1526
1552
  ];
1527
- const LIVE_FILESYSTEM_SYNC_CHUNK_SIZE = 512 * 1024;
1553
+ const DEFAULT_LIVE_FILESYSTEM_SYNC_MAX_BYTES = 64 * 1024 * 1024;
1554
+ class LiveFilesystemSyncLimitError extends Error {
1555
+ code = "ERR_AGENTOS_LIVE_FILESYSTEM_SYNC_LIMIT";
1556
+ }
1528
1557
  function topLevelSyncRoot(targetPath) {
1529
1558
  const normalized = normalizePath(targetPath);
1530
1559
  const [first] = normalized.split("/").filter(Boolean);
@@ -1552,48 +1581,75 @@ async function ensureBoundParentDirectory(methods, targetPath) {
1552
1581
  if (parent === targetPath) {
1553
1582
  return;
1554
1583
  }
1555
- await callBoundFilesystemMethod(methods, "mkdir", parent, { recursive: true });
1584
+ await callBoundFilesystemMethod(methods, "mkdir", parent, {
1585
+ recursive: true,
1586
+ });
1556
1587
  }
1557
- async function syncLiveFilesystemToBoundMethods(live, methods, paths) {
1588
+ async function syncLiveFilesystemToBoundMethods(live, methods, paths, maxBytes) {
1589
+ const snapshot = [];
1590
+ const usage = { bytes: 0 };
1558
1591
  for (const targetPath of [...new Set(paths.map(normalizePath))].sort((left, right) => left.localeCompare(right))) {
1559
1592
  if (!(await live.exists(targetPath).catch(() => false))) {
1560
1593
  continue;
1561
1594
  }
1562
- await syncLiveFilesystemPathToBoundMethods(live, methods, targetPath);
1595
+ await snapshotLiveFilesystemPath(live, targetPath, snapshot, usage, maxBytes);
1596
+ }
1597
+ if (usage.bytes >= maxBytes * 0.8) {
1598
+ process.emitWarning(`live filesystem sync retained ${usage.bytes} of ${maxBytes} bytes; ` +
1599
+ "raise createKernel({ maxFilesystemBytes }) before increasing VM filesystem limits", { code: "AGENTOS_LIVE_FILESYSTEM_SYNC_NEAR_LIMIT" });
1600
+ }
1601
+ for (const entry of snapshot) {
1602
+ await applyLiveFilesystemSnapshotEntry(methods, entry);
1563
1603
  }
1564
1604
  }
1565
- async function syncLiveFilesystemPathToBoundMethods(live, methods, targetPath) {
1566
- const stat = targetPath === "/" ? await live.stat(targetPath) : await live.lstat(targetPath);
1605
+ async function snapshotLiveFilesystemPath(live, targetPath, snapshot, usage, maxBytes, knownEntry) {
1606
+ const stat = knownEntry ??
1607
+ (targetPath === "/" ? await live.stat(targetPath) : await live.lstat(targetPath));
1567
1608
  if (stat.isSymbolicLink) {
1568
- await ensureBoundParentDirectory(methods, targetPath);
1569
- await callBoundFilesystemMethod(methods, "removeFile", targetPath).catch(() => { });
1570
- await callBoundFilesystemMethod(methods, "symlink", await live.readlink(targetPath), targetPath);
1609
+ snapshot.push({ kind: "symlink", path: targetPath, target: await live.readlink(targetPath) });
1571
1610
  return;
1572
1611
  }
1573
1612
  if (stat.isDirectory) {
1574
- await callBoundFilesystemMethod(methods, "mkdir", targetPath, {
1575
- recursive: true,
1576
- });
1613
+ snapshot.push({ kind: "directory", path: targetPath });
1577
1614
  const children = (await live.readDirWithTypes(targetPath))
1578
- .map((entry) => entry.name)
1579
- .filter((name) => name !== "." && name !== "..")
1580
- .sort((left, right) => left.localeCompare(right));
1615
+ .filter((entry) => entry.name !== "." && entry.name !== "..")
1616
+ .sort((left, right) => left.name.localeCompare(right.name));
1581
1617
  for (const child of children) {
1582
- await syncLiveFilesystemPathToBoundMethods(live, methods, targetPath === "/" ? posixPath.join("/", child) : posixPath.join(targetPath, child));
1618
+ await snapshotLiveFilesystemPath(live, targetPath === "/"
1619
+ ? posixPath.join("/", child.name)
1620
+ : posixPath.join(targetPath, child.name), snapshot, usage, maxBytes, child);
1583
1621
  }
1584
1622
  return;
1585
1623
  }
1586
- await ensureBoundParentDirectory(methods, targetPath);
1587
- await callBoundFilesystemMethod(methods, "writeFile", targetPath, new Uint8Array(0));
1588
- for (let offset = 0; offset < stat.size; offset += LIVE_FILESYSTEM_SYNC_CHUNK_SIZE) {
1589
- const chunk = await live.pread(targetPath, offset, Math.min(LIVE_FILESYSTEM_SYNC_CHUNK_SIZE, stat.size - offset));
1590
- if (chunk.length === 0) {
1591
- break;
1592
- }
1593
- await callBoundFilesystemMethod(methods, "pwrite", targetPath, offset, chunk);
1624
+ const fileSize = "size" in stat && typeof stat.size === "number"
1625
+ ? stat.size
1626
+ : (await live.lstat(targetPath)).size;
1627
+ if (fileSize > maxBytes - usage.bytes) {
1628
+ throw new LiveFilesystemSyncLimitError(`live filesystem sync for ${targetPath} exceeds ${maxBytes} bytes ` +
1629
+ "(createKernel maxFilesystemBytes); raise createKernel({ maxFilesystemBytes })");
1630
+ }
1631
+ const content = await live.readFile(targetPath);
1632
+ if (content.byteLength > maxBytes - usage.bytes) {
1633
+ throw new LiveFilesystemSyncLimitError(`live filesystem sync for ${targetPath} exceeds ${maxBytes} bytes ` +
1634
+ "(createKernel maxFilesystemBytes); raise createKernel({ maxFilesystemBytes })");
1635
+ }
1636
+ usage.bytes += content.byteLength;
1637
+ snapshot.push({ kind: "file", path: targetPath, content });
1638
+ }
1639
+ async function applyLiveFilesystemSnapshotEntry(methods, entry) {
1640
+ if (entry.kind === "directory") {
1641
+ await callBoundFilesystemMethod(methods, "mkdir", entry.path, { recursive: true });
1642
+ return;
1594
1643
  }
1644
+ await ensureBoundParentDirectory(methods, entry.path);
1645
+ if (entry.kind === "symlink") {
1646
+ await callBoundFilesystemMethod(methods, "removeFile", entry.path).catch(() => { });
1647
+ await callBoundFilesystemMethod(methods, "symlink", entry.target, entry.path);
1648
+ return;
1649
+ }
1650
+ await callBoundFilesystemMethod(methods, "writeFile", entry.path, entry.content);
1595
1651
  }
1596
- function bindLiveFilesystem(target, getFilesystem) {
1652
+ function bindLiveFilesystem(target, getFilesystem, maxBytes) {
1597
1653
  const fallback = {};
1598
1654
  for (const method of VIRTUAL_FILESYSTEM_METHOD_NAMES) {
1599
1655
  const candidate = target[method];
@@ -1619,7 +1675,7 @@ function bindLiveFilesystem(target, getFilesystem) {
1619
1675
  if (!filesystem) {
1620
1676
  return;
1621
1677
  }
1622
- await syncLiveFilesystemToBoundMethods(filesystem, fallback, paths);
1678
+ await syncLiveFilesystemToBoundMethods(filesystem, fallback, paths, maxBytes);
1623
1679
  },
1624
1680
  restore() {
1625
1681
  for (const [method, delegate] of Object.entries(fallback)) {
@@ -1653,9 +1709,9 @@ class NativeKernel {
1653
1709
  loopbackExemptPorts;
1654
1710
  // Bindings registered with the VM, keyed by the callback key the sidecar
1655
1711
  // sends back on a host_callback request (the binding name). Installed lazily
1656
- // on the first registerHostTools call.
1657
- hostToolHandlers = new Map();
1658
- hostToolRequestHandlerInstalled = false;
1712
+ // on the first registerBindings call.
1713
+ bindingHandlers = new Map();
1714
+ bindingRequestHandlerInstalled = false;
1659
1715
  constructor(options) {
1660
1716
  this.options = options;
1661
1717
  this.env = { ...(options.env ?? {}) };
@@ -1685,7 +1741,7 @@ class NativeKernel {
1685
1741
  });
1686
1742
  }
1687
1743
  this.vfs = new DeferredFileSystem(() => this.rootFilesystem);
1688
- this.liveFilesystemBinding = bindLiveFilesystem(this.options.filesystem, () => this.rootFilesystem);
1744
+ this.liveFilesystemBinding = bindLiveFilesystem(this.options.filesystem, () => this.rootFilesystem, options.maxFilesystemBytes ?? DEFAULT_LIVE_FILESYSTEM_SYNC_MAX_BYTES);
1689
1745
  }
1690
1746
  get zombieTimerCount() {
1691
1747
  return this.proxy?.zombieTimerCount ?? 0;
@@ -1880,7 +1936,7 @@ class NativeKernel {
1880
1936
  await this.ensureReady();
1881
1937
  return this.proxy.vmFetch(request);
1882
1938
  }
1883
- async registerHostTools(tools) {
1939
+ async registerBindings(bindings) {
1884
1940
  await this.ensureReady();
1885
1941
  if (!this.client || !this.session || !this.vm) {
1886
1942
  throw new Error("kernel is not ready");
@@ -1888,12 +1944,12 @@ class NativeKernel {
1888
1944
  // Install the dispatcher once. It routes every host_callback request the
1889
1945
  // sidecar emits to the matching registered handler and replies with a
1890
1946
  // host_callback_result frame.
1891
- if (!this.hostToolRequestHandlerInstalled) {
1892
- this.client.setSidecarRequestHandler((request) => this.dispatchHostToolRequest(request));
1893
- this.hostToolRequestHandlerInstalled = true;
1947
+ if (!this.bindingRequestHandlerInstalled) {
1948
+ this.client.setSidecarRequestHandler((request) => this.dispatchBindingRequest(request));
1949
+ this.bindingRequestHandlerInstalled = true;
1894
1950
  }
1895
- for (const [name, binding] of Object.entries(tools)) {
1896
- this.hostToolHandlers.set(name, binding.handler);
1951
+ for (const [name, binding] of Object.entries(bindings)) {
1952
+ this.bindingHandlers.set(name, binding.handler);
1897
1953
  const definition = {
1898
1954
  description: binding.description,
1899
1955
  inputSchema: binding.inputSchema,
@@ -1909,9 +1965,9 @@ class NativeKernel {
1909
1965
  }
1910
1966
  : {}),
1911
1967
  };
1912
- // Register each binding as its own single-callback toolkit so the guest
1968
+ // Register each binding as its own single-callback binding collection so the guest
1913
1969
  // can invoke it directly by name (or by any caller-provided alias). The
1914
- // sidecar exposes the toolkit name as a guest command; the single
1970
+ // sidecar exposes the binding collection name as a guest command; the single
1915
1971
  // callback carries the binding's schema and gates the `binding`
1916
1972
  // permission.
1917
1973
  await this.client.registerHostCallbacks(this.session, this.vm, {
@@ -1926,21 +1982,21 @@ class NativeKernel {
1926
1982
  }
1927
1983
  }
1928
1984
  }
1929
- async dispatchHostToolRequest(request) {
1985
+ async dispatchBindingRequest(request) {
1930
1986
  const { payload } = request;
1931
1987
  if (payload.type !== "host_callback") {
1932
1988
  throw new Error(`unsupported sidecar request for bindings: ${payload.type}`);
1933
1989
  }
1934
- // Callback keys arrive as `${toolkit}:${tool}` for toolkit invocations and
1935
- // as the bare command name otherwise. The toolkit name and tool name are
1936
- // the same here, so the registered tool name is the segment after the last
1990
+ // Callback keys arrive as `${collection}:${binding}` for collection invocations
1991
+ // and as the bare command name otherwise. The collection and binding name are
1992
+ // the same here, so the registered binding name is the segment after the last
1937
1993
  // colon (or the whole key when no colon is present).
1938
1994
  const callbackKey = payload.callback_key;
1939
- const toolName = callbackKey.includes(":")
1995
+ const bindingName = callbackKey.includes(":")
1940
1996
  ? callbackKey.slice(callbackKey.lastIndexOf(":") + 1)
1941
1997
  : callbackKey;
1942
- const handler = this.hostToolHandlers.get(toolName) ??
1943
- this.hostToolHandlers.get(callbackKey);
1998
+ const handler = this.bindingHandlers.get(bindingName) ??
1999
+ this.bindingHandlers.get(callbackKey);
1944
2000
  if (!handler) {
1945
2001
  return {
1946
2002
  type: "host_callback_result",
@@ -1996,6 +2052,10 @@ class NativeKernel {
1996
2052
  await this.ensureReady();
1997
2053
  return this.proxy.rename(oldPath, newPath);
1998
2054
  }
2055
+ async pwrite(targetPath, offset, data) {
2056
+ await this.ensureReady();
2057
+ return this.proxy.vfs.pwrite(targetPath, offset, data);
2058
+ }
1999
2059
  tryResolveMountedCommand(command) {
2000
2060
  const normalized = normalizeCommandLookup(command);
2001
2061
  for (const driver of this.mountedRuntimeDrivers) {
@@ -2062,15 +2122,19 @@ class NativeKernel {
2062
2122
  cwd: REPO_ROOT,
2063
2123
  command: ensureNativeSidecarBinary(),
2064
2124
  args: [],
2065
- frameTimeoutMs: NATIVE_SIDECAR_FRAME_TIMEOUT_MS,
2125
+ gracefulExitMs: 100,
2126
+ forceExitMs: 100,
2066
2127
  }));
2067
2128
  const session = await this.measureBoot("session_open", () => client.authenticateAndOpenSession());
2068
2129
  const vm = await this.measureBoot("vm_create", () => client.createVm(session, {
2069
2130
  runtime: "java_script",
2070
2131
  config: {
2071
2132
  env: createVmEnv,
2133
+ ...(this.options.user ? { user: this.options.user } : {}),
2072
2134
  rootFilesystem,
2073
- ...(bootstrapPermissions ? { permissions: bootstrapPermissions } : {}),
2135
+ ...(bootstrapPermissions
2136
+ ? { permissions: bootstrapPermissions }
2137
+ : {}),
2074
2138
  loopbackExemptPorts: this.loopbackExemptPorts,
2075
2139
  ...(this.options.jsRuntime
2076
2140
  ? { jsRuntime: this.options.jsRuntime }
@@ -1,5 +1,8 @@
1
1
  export type { AcpLimitsConfig } from "./generated/AcpLimitsConfig.js";
2
2
  export type { CreateVmConfig } from "./generated/CreateVmConfig.js";
3
+ export type { VmUserConfig } from "./generated/VmUserConfig.js";
4
+ export type { VmUserAccountConfig } from "./generated/VmUserAccountConfig.js";
5
+ export type { VmGroupConfig } from "./generated/VmGroupConfig.js";
3
6
  export type { FsPermissionRule } from "./generated/FsPermissionRule.js";
4
7
  export type { FsPermissionRuleSet } from "./generated/FsPermissionRuleSet.js";
5
8
  export type { FsPermissionScope } from "./generated/FsPermissionScope.js";
@@ -16,6 +19,7 @@ export type { PatternPermissionScope } from "./generated/PatternPermissionScope.
16
19
  export type { PermissionMode } from "./generated/PermissionMode.js";
17
20
  export type { PermissionsPolicy } from "./generated/PermissionsPolicy.js";
18
21
  export type { PluginLimitsConfig } from "./generated/PluginLimitsConfig.js";
22
+ export type { ProcessLimitsConfig } from "./generated/ProcessLimitsConfig.js";
19
23
  export type { PythonLimitsConfig } from "./generated/PythonLimitsConfig.js";
20
24
  export type { ResourceLimitsConfig } from "./generated/ResourceLimitsConfig.js";
21
25
  export type { RootFilesystemConfig } from "./generated/RootFilesystemConfig.js";
@@ -24,7 +28,7 @@ export type { RootFilesystemEntryEncoding } from "./generated/RootFilesystemEntr
24
28
  export type { RootFilesystemEntryKind } from "./generated/RootFilesystemEntryKind.js";
25
29
  export type { RootFilesystemLowerDescriptor } from "./generated/RootFilesystemLowerDescriptor.js";
26
30
  export type { RootFilesystemMode } from "./generated/RootFilesystemMode.js";
27
- export type { ToolLimitsConfig } from "./generated/ToolLimitsConfig.js";
31
+ export type { BindingLimitsConfig } from "./generated/BindingLimitsConfig.js";
28
32
  export type { VmDnsConfig } from "./generated/VmDnsConfig.js";
29
33
  export type { VmLimitsConfig } from "./generated/VmLimitsConfig.js";
30
34
  export type { VmListenPolicyConfig } from "./generated/VmListenPolicyConfig.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivet-dev/agentos-runtime-core",
3
- "version": "0.0.0-codex-actor-plugin-contract-coverage.115ca8a",
3
+ "version": "0.0.0-fix-main-wasm-ownership.150c49a",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -189,10 +189,12 @@
189
189
  "check-types": "pnpm run build:protocol && pnpm run build:vm-config && tsc --noEmit",
190
190
  "build": "pnpm run build:protocol && pnpm run build:vm-config && tsc && pnpm run copy-commands",
191
191
  "prepack": "node scripts/copy-wasm-commands.mjs --require",
192
- "test": "vitest run"
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"
193
195
  },
194
196
  "dependencies": {
195
- "@rivet-dev/agentos-runtime-sidecar": "0.0.0-codex-actor-plugin-contract-coverage.115ca8a",
197
+ "@rivet-dev/agentos-runtime-sidecar": "0.0.0-fix-main-wasm-ownership.150c49a",
196
198
  "@rivetkit/bare-ts": "^0.6.2",
197
199
  "zod": "^4.1.11"
198
200
  },
package/commands/codex DELETED
Binary file
Binary file
package/commands/http_get DELETED
Binary file
@@ -1,10 +0,0 @@
1
- export type ToolLimitsConfig = {
2
- defaultToolTimeoutMs?: number;
3
- maxToolTimeoutMs?: number;
4
- maxRegisteredToolkits?: number;
5
- maxRegisteredToolsPerVm?: number;
6
- maxToolsPerToolkit?: number;
7
- maxToolSchemaBytes?: number;
8
- maxToolExamplesPerTool?: number;
9
- maxToolExampleInputBytes?: number;
10
- };