@rivet-dev/agentos-core 0.0.0-abc-fixes-1.d8c4d95 → 0.0.0-agent-acp-codex-session-benchmark.62b1f46

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 (128) hide show
  1. package/README.md +48 -48
  2. package/dist/agent-os.d.ts +215 -161
  3. package/dist/agent-os.js +1300 -2576
  4. package/dist/agentos-package.d.ts +27 -0
  5. package/dist/agentos-package.js +21 -0
  6. package/dist/base-filesystem.d.ts +1 -16
  7. package/dist/base-filesystem.js +1 -173
  8. package/dist/cron/cron-manager.d.ts +39 -14
  9. package/dist/cron/cron-manager.js +289 -128
  10. package/dist/cron/errors.d.ts +8 -0
  11. package/dist/cron/errors.js +16 -0
  12. package/dist/cron/index.d.ts +1 -3
  13. package/dist/cron/index.js +1 -2
  14. package/dist/cron/types.d.ts +2 -2
  15. package/dist/default-software.d.ts +8 -0
  16. package/dist/default-software.js +10 -0
  17. package/dist/filesystem-snapshot.d.ts +1 -1
  18. package/dist/filesystem-snapshot.js +1 -1
  19. package/dist/generated/AcpLimitsConfig.d.ts +4 -0
  20. package/dist/generated/AcpLimitsConfig.js +2 -0
  21. package/dist/generated/CreateVmConfig.d.ts +29 -0
  22. package/dist/generated/FsPermissionRule.d.ts +6 -0
  23. package/dist/generated/FsPermissionRule.js +1 -0
  24. package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
  25. package/dist/generated/FsPermissionRuleSet.js +1 -0
  26. package/dist/generated/FsPermissionScope.d.ts +3 -0
  27. package/dist/generated/FsPermissionScope.js +1 -0
  28. package/dist/generated/HttpLimitsConfig.d.ts +3 -0
  29. package/dist/generated/HttpLimitsConfig.js +2 -0
  30. package/dist/generated/JsModuleResolution.d.ts +1 -0
  31. package/dist/generated/JsModuleResolution.js +2 -0
  32. package/dist/generated/JsRuntimeConfig.d.ts +31 -0
  33. package/dist/generated/JsRuntimeConfig.js +1 -0
  34. package/dist/generated/JsRuntimeLimitsConfig.d.ts +8 -0
  35. package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
  36. package/dist/generated/JsRuntimePlatform.d.ts +1 -0
  37. package/dist/generated/JsRuntimePlatform.js +2 -0
  38. package/dist/generated/MountPluginDescriptor.d.ts +4 -0
  39. package/dist/generated/MountPluginDescriptor.js +2 -0
  40. package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
  41. package/dist/generated/NativeRootFilesystemConfig.js +1 -0
  42. package/dist/generated/PatternPermissionRule.d.ts +6 -0
  43. package/dist/generated/PatternPermissionRule.js +1 -0
  44. package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
  45. package/dist/generated/PatternPermissionRuleSet.js +1 -0
  46. package/dist/generated/PatternPermissionScope.d.ts +3 -0
  47. package/dist/generated/PatternPermissionScope.js +1 -0
  48. package/dist/generated/PermissionMode.d.ts +1 -0
  49. package/dist/generated/PermissionMode.js +2 -0
  50. package/dist/generated/PermissionsPolicy.d.ts +10 -0
  51. package/dist/generated/PermissionsPolicy.js +1 -0
  52. package/dist/generated/PluginLimitsConfig.d.ts +4 -0
  53. package/dist/generated/PluginLimitsConfig.js +2 -0
  54. package/dist/generated/PythonLimitsConfig.d.ts +6 -0
  55. package/dist/generated/PythonLimitsConfig.js +2 -0
  56. package/dist/generated/ResourceLimitsConfig.d.ts +25 -0
  57. package/dist/generated/ResourceLimitsConfig.js +2 -0
  58. package/dist/generated/RootFilesystemConfig.d.ts +9 -0
  59. package/dist/generated/RootFilesystemConfig.js +1 -0
  60. package/dist/generated/RootFilesystemEntry.d.ts +13 -0
  61. package/dist/generated/RootFilesystemEntry.js +1 -0
  62. package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
  63. package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
  64. package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
  65. package/dist/generated/RootFilesystemEntryKind.js +2 -0
  66. package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
  67. package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
  68. package/dist/generated/RootFilesystemMode.d.ts +1 -0
  69. package/dist/generated/RootFilesystemMode.js +2 -0
  70. package/dist/generated/ToolLimitsConfig.d.ts +10 -0
  71. package/dist/generated/ToolLimitsConfig.js +2 -0
  72. package/dist/generated/VmDnsConfig.d.ts +6 -0
  73. package/dist/generated/VmDnsConfig.js +2 -0
  74. package/dist/generated/VmLimitsConfig.d.ts +18 -0
  75. package/dist/generated/VmLimitsConfig.js +1 -0
  76. package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
  77. package/dist/generated/VmListenPolicyConfig.js +2 -0
  78. package/dist/generated/WasmLimitsConfig.d.ts +7 -0
  79. package/dist/generated/WasmLimitsConfig.js +2 -0
  80. package/dist/host-dir-mount.d.ts +5 -5
  81. package/dist/host-dir-mount.js +4 -4
  82. package/dist/host-tools-zod.js +27 -7
  83. package/dist/host-tools.d.ts +2 -9
  84. package/dist/host-tools.js +0 -18
  85. package/dist/index.d.ts +7 -4
  86. package/dist/index.js +6 -4
  87. package/dist/layers.d.ts +3 -3
  88. package/dist/layers.js +19 -10
  89. package/dist/memory-filesystem.d.ts +39 -0
  90. package/dist/memory-filesystem.js +375 -0
  91. package/dist/options-schema.d.ts +452 -0
  92. package/dist/options-schema.js +269 -0
  93. package/dist/overlay-filesystem.d.ts +1 -1
  94. package/dist/overlay-filesystem.js +3 -3
  95. package/dist/packages.d.ts +10 -123
  96. package/dist/packages.js +3 -329
  97. package/dist/runtime.d.ts +41 -184
  98. package/dist/sidecar/agentos-protocol.d.ts +232 -29
  99. package/dist/sidecar/agentos-protocol.js +456 -120
  100. package/dist/sidecar/binary.d.ts +2 -2
  101. package/dist/sidecar/binary.js +2 -2
  102. package/dist/sidecar/native-process-client.d.ts +5 -3
  103. package/dist/sidecar/native-process-client.js +5 -3
  104. package/dist/sidecar/permissions.d.ts +4 -3
  105. package/dist/sidecar/permissions.js +6 -23
  106. package/dist/sidecar/rpc-client.d.ts +74 -86
  107. package/dist/sidecar/rpc-client.js +422 -1418
  108. package/dist/test/file-system.d.ts +1 -1
  109. package/dist/test/file-system.js +3 -1
  110. package/dist/test/runtime.d.ts +2 -3
  111. package/dist/test/runtime.js +1 -1
  112. package/dist/test/terminal-harness.d.ts +5 -4
  113. package/dist/test/terminal-harness.js +12 -7
  114. package/dist/types.d.ts +12 -5
  115. package/package.json +37 -41
  116. package/dist/agents.d.ts +0 -63
  117. package/dist/agents.js +0 -42
  118. package/dist/cron/parse-schedule.d.ts +0 -25
  119. package/dist/cron/parse-schedule.js +0 -66
  120. package/dist/cron/schedule-driver.d.ts +0 -19
  121. package/dist/cron/timer-driver.d.ts +0 -17
  122. package/dist/cron/timer-driver.js +0 -61
  123. package/dist/runtime-compat.d.ts +0 -475
  124. package/dist/runtime-compat.js +0 -2010
  125. package/dist/sidecar/cargo.d.ts +0 -2
  126. package/dist/sidecar/cargo.js +0 -142
  127. package/fixtures/AGENTOS_SYSTEM_PROMPT.md +0 -21
  128. /package/dist/{cron/schedule-driver.js → generated/CreateVmConfig.js} +0 -0
package/dist/packages.js CHANGED
@@ -1,335 +1,9 @@
1
- import { existsSync, readFileSync, realpathSync } from "node:fs";
2
- import { dirname, join, resolve, sep } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- /**
5
- * Resolve a package directory by walking up the directory tree.
6
- * Supports both nested (pnpm) and flat (npm) node_modules layouts.
7
- */
8
- export function resolvePackageDir(startDir, packageName) {
9
- const localPkgJson = join(startDir, "package.json");
10
- if (existsSync(localPkgJson)) {
11
- try {
12
- const localPkg = JSON.parse(readFileSync(localPkgJson, "utf-8"));
13
- if (localPkg.name === packageName) {
14
- return realpathSync(startDir);
15
- }
16
- }
17
- catch {
18
- // Ignore malformed local package metadata and continue walking.
19
- }
20
- }
21
- let searchDir = startDir;
22
- while (true) {
23
- const candidate = join(searchDir, "node_modules", packageName);
24
- if (existsSync(join(candidate, "package.json"))) {
25
- return realpathSync(candidate);
26
- }
27
- const parent = dirname(searchDir);
28
- if (parent === searchDir)
29
- break;
30
- searchDir = parent;
31
- }
32
- throw new Error(`Package "${packageName}" not found starting from ${startDir}. ` +
33
- `Ensure it is installed.`);
34
- }
35
- const LOCAL_REGISTRY_COMMAND_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "../../..", "registry/native/target/wasm32-wasip1/release/commands");
36
- function readPackageName(packageDir) {
37
- const pkg = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8"));
38
- if (typeof pkg.name !== "string" || pkg.name.length === 0) {
39
- throw new Error(`Package at ${packageDir} is missing a valid name`);
40
- }
41
- return pkg.name;
42
- }
43
- function pushSoftwareRoot(softwareRoots, seenVmPaths, hostPath, vmPath) {
44
- if (seenVmPaths.has(vmPath)) {
45
- return;
46
- }
47
- seenVmPaths.add(vmPath);
48
- softwareRoots.push({ hostPath, vmPath });
49
- }
50
- function findPnpmStoreRoot(hostPath) {
51
- const marker = `${sep}node_modules${sep}.pnpm${sep}`;
52
- const markerIndex = hostPath.indexOf(marker);
53
- if (markerIndex === -1) {
54
- return null;
55
- }
56
- const nodeModulesRoot = `${hostPath.slice(0, markerIndex)}${sep}node_modules`;
57
- const pnpmStoreRoot = join(nodeModulesRoot, ".pnpm");
58
- return existsSync(pnpmStoreRoot) ? pnpmStoreRoot : null;
59
- }
60
- function pushPackageSoftwareRoot(softwareRoots, seenVmPaths, hostPath, vmPath) {
61
- pushSoftwareRoot(softwareRoots, seenVmPaths, hostPath, vmPath);
62
- const pnpmStoreRoot = findPnpmStoreRoot(hostPath);
63
- if (!pnpmStoreRoot) {
64
- return;
65
- }
66
- pushSoftwareRoot(softwareRoots, seenVmPaths, pnpmStoreRoot, "/root/node_modules/.pnpm");
67
- }
68
- /**
69
- * Create a SoftwareContext for a software descriptor.
70
- * Resolves npm package paths relative to the descriptor's packageDir.
71
- */
72
- function createSoftwareContext(packageDir, requires) {
73
- // Pre-resolve all required packages to host paths
74
- const resolvedPackages = new Map();
75
- for (const reqPkg of requires) {
76
- const hostDir = resolvePackageDir(packageDir, reqPkg);
77
- const pkg = JSON.parse(readFileSync(join(hostDir, "package.json"), "utf-8"));
78
- const vmDir = `/root/node_modules/${reqPkg}`;
79
- resolvedPackages.set(reqPkg, { hostDir, vmDir, pkg });
80
- }
81
- return {
82
- resolveBin(packageName, binName) {
83
- const resolved = resolvedPackages.get(packageName);
84
- if (!resolved) {
85
- throw new Error(`Package "${packageName}" is not in the requires list. ` +
86
- `Available: ${[...resolvedPackages.keys()].join(", ")}`);
87
- }
88
- const { pkg, vmDir } = resolved;
89
- let binEntry;
90
- const effectiveBinName = binName ?? packageName;
91
- if (typeof pkg.bin === "string") {
92
- binEntry = pkg.bin;
93
- }
94
- else if (typeof pkg.bin === "object" && pkg.bin !== null) {
95
- const binMap = pkg.bin;
96
- binEntry = binMap[effectiveBinName] ?? Object.values(binMap)[0];
97
- }
98
- if (!binEntry) {
99
- throw new Error(`No bin entry "${effectiveBinName}" found in ${packageName}/package.json`);
100
- }
101
- return `${vmDir}/${binEntry}`;
102
- },
103
- resolvePackage(packageName) {
104
- const resolved = resolvedPackages.get(packageName);
105
- if (!resolved) {
106
- throw new Error(`Package "${packageName}" is not in the requires list. ` +
107
- `Available: ${[...resolvedPackages.keys()].join(", ")}`);
108
- }
109
- return resolved.vmDir;
110
- },
111
- };
112
- }
113
1
  // ── defineSoftware ───────────────────────────────────────────────────
114
2
  /**
115
- * Define a software descriptor. This is a type-safe identity function that
116
- * validates the descriptor shape at compile time.
3
+ * Define a software descriptor. A type-safe identity function that validates the
4
+ * package-dir reference at compile time. The sidecar materializes the package into
5
+ * the `/opt/agentos` projection.
117
6
  */
118
7
  export function defineSoftware(desc) {
119
8
  return desc;
120
9
  }
121
- /** Check if a descriptor is a typed software descriptor (has a `type` field). */
122
- function isTypedDescriptor(desc) {
123
- return ("type" in desc && typeof desc.type === "string");
124
- }
125
- const VALID_PERMISSION_TIERS = new Set([
126
- "full",
127
- "read-write",
128
- "read-only",
129
- "isolated",
130
- ]);
131
- function isPermissionTier(value) {
132
- return (typeof value === "string" &&
133
- VALID_PERMISSION_TIERS.has(value));
134
- }
135
- function registerPermission(commandPermissions, commandName, tier) {
136
- if (commandName in commandPermissions)
137
- return;
138
- commandPermissions[commandName] = tier;
139
- }
140
- function appendDeclaredCommand(declaredCommands, seen, commandName) {
141
- if (typeof commandName !== "string" || seen.has(commandName)) {
142
- return;
143
- }
144
- seen.add(commandName);
145
- declaredCommands.push(commandName);
146
- }
147
- function collectCommandMetadata(pkg) {
148
- const declaredCommands = [];
149
- const seen = new Set();
150
- const aliases = {};
151
- if ("aliases" in pkg && pkg.aliases) {
152
- for (const [aliasName, targetName] of Object.entries(pkg.aliases)) {
153
- if (typeof targetName !== "string") {
154
- continue;
155
- }
156
- aliases[aliasName] = targetName;
157
- appendDeclaredCommand(declaredCommands, seen, aliasName);
158
- appendDeclaredCommand(declaredCommands, seen, targetName);
159
- }
160
- }
161
- const rawCommands = pkg.commands;
162
- if (Array.isArray(rawCommands)) {
163
- for (const rawCommand of rawCommands) {
164
- if (typeof rawCommand !== "object" || rawCommand === null) {
165
- continue;
166
- }
167
- const name = rawCommand.name;
168
- const aliasOf = rawCommand.aliasOf;
169
- appendDeclaredCommand(declaredCommands, seen, name);
170
- appendDeclaredCommand(declaredCommands, seen, aliasOf);
171
- if (typeof name === "string" && typeof aliasOf === "string") {
172
- aliases[name] = aliasOf;
173
- }
174
- }
175
- }
176
- const permissions = pkg.permissions;
177
- if (permissions) {
178
- for (const commandName of permissions.full ?? []) {
179
- appendDeclaredCommand(declaredCommands, seen, commandName);
180
- }
181
- for (const commandName of permissions.readWrite ?? []) {
182
- appendDeclaredCommand(declaredCommands, seen, commandName);
183
- }
184
- if (Array.isArray(permissions.readOnly)) {
185
- for (const commandName of permissions.readOnly) {
186
- appendDeclaredCommand(declaredCommands, seen, commandName);
187
- }
188
- }
189
- for (const commandName of permissions.isolated ?? []) {
190
- appendDeclaredCommand(declaredCommands, seen, commandName);
191
- }
192
- }
193
- const commandDir = resolveLocalCommandDirFallback(pkg.commandDir, declaredCommands);
194
- return {
195
- commandDir,
196
- declaredCommands,
197
- aliases,
198
- };
199
- }
200
- function hasUsableCommandDir(commandDir, declaredCommands) {
201
- if (!existsSync(commandDir)) {
202
- return false;
203
- }
204
- return declaredCommands.every((commandName) => existsSync(join(commandDir, commandName)));
205
- }
206
- function resolveLocalCommandDirFallback(commandDir, declaredCommands) {
207
- if (declaredCommands.length === 0 ||
208
- hasUsableCommandDir(commandDir, declaredCommands) ||
209
- !hasUsableCommandDir(LOCAL_REGISTRY_COMMAND_DIR, declaredCommands)) {
210
- return commandDir;
211
- }
212
- return LOCAL_REGISTRY_COMMAND_DIR;
213
- }
214
- function collectRegistryPackagePermissions(commandPermissions, pkg) {
215
- const rawCommands = pkg.commands;
216
- if (!Array.isArray(rawCommands))
217
- return;
218
- for (const rawCommand of rawCommands) {
219
- if (typeof rawCommand !== "object" ||
220
- rawCommand === null ||
221
- !Object.hasOwn(rawCommand, "name") ||
222
- !Object.hasOwn(rawCommand, "permissionTier")) {
223
- continue;
224
- }
225
- const name = rawCommand.name;
226
- const permissionTier = rawCommand
227
- .permissionTier;
228
- if (typeof name !== "string" || !isPermissionTier(permissionTier))
229
- continue;
230
- registerPermission(commandPermissions, name, permissionTier);
231
- }
232
- }
233
- function collectTypedDescriptorPermissions(commandPermissions, pkg) {
234
- const permissions = pkg.permissions;
235
- if (!permissions)
236
- return;
237
- for (const commandName of permissions.full ?? []) {
238
- registerPermission(commandPermissions, commandName, "full");
239
- }
240
- for (const commandName of permissions.readWrite ?? []) {
241
- registerPermission(commandPermissions, commandName, "read-write");
242
- }
243
- if (Array.isArray(permissions.readOnly)) {
244
- for (const commandName of permissions.readOnly) {
245
- registerPermission(commandPermissions, commandName, "read-only");
246
- }
247
- }
248
- for (const commandName of permissions.isolated ?? []) {
249
- registerPermission(commandPermissions, commandName, "isolated");
250
- }
251
- }
252
- /**
253
- * Process an array of software descriptors at boot time.
254
- * Collects WASM command dirs, module access roots, and agent configurations.
255
- *
256
- * Any object with a `commandDir` property (e.g., registry packages) is treated
257
- * as a WASM command source. Typed descriptors with `type: "agent"` or `type: "tool"`
258
- * are processed for module mounting and agent registration.
259
- */
260
- export function processSoftware(software) {
261
- const commandDirs = [];
262
- const commandPackages = [];
263
- const commandPermissions = {};
264
- const softwareRoots = [];
265
- const seenSoftwareVmPaths = new Set();
266
- const agentConfigs = new Map();
267
- // Flatten nested arrays (meta-packages export arrays of sub-packages).
268
- const flat = software.flat();
269
- for (const pkg of flat) {
270
- if (!isTypedDescriptor(pkg)) {
271
- // Duck-typed: any object with commandDir is a WASM command source.
272
- const commandMetadata = collectCommandMetadata(pkg);
273
- commandDirs.push(commandMetadata.commandDir);
274
- commandPackages.push(commandMetadata);
275
- collectRegistryPackagePermissions(commandPermissions, pkg);
276
- continue;
277
- }
278
- switch (pkg.type) {
279
- case "wasm-commands": {
280
- const commandMetadata = collectCommandMetadata(pkg);
281
- commandDirs.push(commandMetadata.commandDir);
282
- commandPackages.push(commandMetadata);
283
- collectTypedDescriptorPermissions(commandPermissions, pkg);
284
- break;
285
- }
286
- case "agent": {
287
- // Collect module roots for all required npm packages.
288
- // Walks up directory tree to support flat (npm) and nested (pnpm) layouts.
289
- const ctx = createSoftwareContext(pkg.packageDir, pkg.requires);
290
- const declaringPackageName = readPackageName(pkg.packageDir);
291
- pushPackageSoftwareRoot(softwareRoots, seenSoftwareVmPaths, pkg.packageDir, `/root/node_modules/${declaringPackageName}`);
292
- for (const reqPkg of pkg.requires) {
293
- const hostDir = resolvePackageDir(pkg.packageDir, reqPkg);
294
- const vmDir = `/root/node_modules/${reqPkg}`;
295
- pushPackageSoftwareRoot(softwareRoots, seenSoftwareVmPaths, hostDir, vmDir);
296
- }
297
- // Compute static + dynamic env vars.
298
- const staticEnv = pkg.agent.staticEnv ?? {};
299
- const dynamicEnv = pkg.agent.env ? pkg.agent.env(ctx) : {};
300
- const combinedEnv = { ...staticEnv, ...dynamicEnv };
301
- // Register agent config.
302
- const agentConfig = {
303
- acpAdapter: pkg.agent.acpAdapter,
304
- agentPackage: pkg.agent.agentPackage,
305
- declaringPackageDir: pkg.packageDir,
306
- launchArgs: pkg.agent.launchArgs,
307
- defaultEnv: Object.keys(combinedEnv).length > 0 ? combinedEnv : undefined,
308
- };
309
- agentConfigs.set(pkg.agent.id, agentConfig);
310
- break;
311
- }
312
- case "tool": {
313
- // Collect module roots for all required npm packages.
314
- // Walks up directory tree to support flat (npm) and nested (pnpm) layouts.
315
- const declaringPackageName = readPackageName(pkg.packageDir);
316
- pushPackageSoftwareRoot(softwareRoots, seenSoftwareVmPaths, pkg.packageDir, `/root/node_modules/${declaringPackageName}`);
317
- for (const reqPkg of pkg.requires) {
318
- const hostDir = resolvePackageDir(pkg.packageDir, reqPkg);
319
- const vmDir = `/root/node_modules/${reqPkg}`;
320
- pushPackageSoftwareRoot(softwareRoots, seenSoftwareVmPaths, hostDir, vmDir);
321
- }
322
- // Tool bin registration is handled by the caller (AgentOs.create)
323
- // since it requires kernel access.
324
- break;
325
- }
326
- }
327
- }
328
- return {
329
- commandDirs,
330
- commandPackages,
331
- commandPermissions,
332
- softwareRoots,
333
- agentConfigs,
334
- };
335
- }
package/dist/runtime.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export type StdioChannel = "stdout" | "stderr";
2
- export type TimingMitigation = "off" | "freeze";
3
2
  export type PermissionMode = "allow" | "deny";
4
3
  export type PermissionDecision = PermissionMode;
5
4
  export interface VirtualDirEntry {
@@ -10,6 +9,7 @@ export interface VirtualDirEntry {
10
9
  export interface VirtualStat {
11
10
  mode: number;
12
11
  size: number;
12
+ sizeExact?: bigint;
13
13
  blocks: number;
14
14
  dev: number;
15
15
  rdev: number;
@@ -20,7 +20,9 @@ export interface VirtualStat {
20
20
  ctimeMs: number;
21
21
  birthtimeMs: number;
22
22
  ino: number;
23
+ inoExact?: bigint;
23
24
  nlink: number;
25
+ nlinkExact?: bigint;
24
26
  uid: number;
25
27
  gid: number;
26
28
  }
@@ -76,7 +78,7 @@ export type NetworkPermissions = PermissionMode | RulePermissions<PatternPermiss
76
78
  export type ChildProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
77
79
  export type ProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
78
80
  export type EnvPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
79
- export type ToolPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
81
+ export type BindingPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
80
82
  export interface ProcessInfo {
81
83
  pid: number;
82
84
  ppid: number;
@@ -86,25 +88,27 @@ export interface ProcessInfo {
86
88
  command: string;
87
89
  args: string[];
88
90
  cwd: string;
89
- status: "running" | "exited";
91
+ status: "running" | "stopped" | "exited";
90
92
  exitCode: number | null;
91
93
  startTime: number;
92
94
  exitTime: number | null;
93
95
  }
94
96
  export interface ManagedProcess {
95
97
  pid: number;
96
- writeStdin(data: Uint8Array | string): void;
97
- closeStdin(): void;
98
- kill(signal?: number): void;
98
+ writeStdin(data: Uint8Array | string): Promise<void>;
99
+ closeStdin(): Promise<void>;
100
+ kill(signal?: number): void | Promise<void>;
99
101
  wait(): Promise<number>;
100
102
  readonly exitCode: number | null;
101
103
  }
102
104
  export interface ShellHandle {
103
105
  pid: number;
104
- write(data: Uint8Array | string): void;
106
+ /** Sidecar-owned process correlation id. */
107
+ processId: string;
108
+ write(data: Uint8Array | string): Promise<void>;
105
109
  onData: ((data: Uint8Array) => void) | null;
106
- resize(cols: number, rows: number): void;
107
- kill(signal?: number): void;
110
+ resize(cols: number, rows: number): void | Promise<void>;
111
+ kill(signal?: number): void | Promise<void>;
108
112
  wait(): Promise<number>;
109
113
  }
110
114
  export interface OpenShellOptions {
@@ -116,221 +120,74 @@ export interface OpenShellOptions {
116
120
  rows?: number;
117
121
  onStderr?: (data: Uint8Array) => void;
118
122
  }
119
- export interface ConnectTerminalOptions extends OpenShellOptions {
120
- onData?: (data: Uint8Array) => void;
121
- }
122
- export interface ExecOptions {
123
+ interface ProcessLaunchOptions {
123
124
  env?: Record<string, string>;
124
125
  cwd?: string;
125
- stdin?: string | Uint8Array;
126
126
  timeout?: number;
127
127
  onStdout?: (data: Uint8Array) => void;
128
128
  onStderr?: (data: Uint8Array) => void;
129
+ }
130
+ export interface ExecOptions extends ProcessLaunchOptions {
131
+ stdin?: string | Uint8Array;
129
132
  captureStdio?: boolean;
130
- filePath?: string;
131
- cpuTimeLimitMs?: number;
132
- timingMitigation?: TimingMitigation;
133
133
  }
134
134
  export interface ExecResult {
135
135
  exitCode: number;
136
136
  stdout: string;
137
137
  stderr: string;
138
138
  }
139
- export interface RunResult<T = unknown> {
140
- value?: T;
141
- code: number;
142
- errorMessage?: string;
143
- }
144
- export interface KernelSpawnOptions extends ExecOptions {
145
- stdio?: "pipe" | "inherit";
146
- stdinFd?: number;
147
- stdoutFd?: number;
148
- stderrFd?: number;
139
+ export interface KernelSpawnOptions extends ProcessLaunchOptions {
149
140
  streamStdin?: boolean;
150
141
  }
151
142
  export type KernelExecOptions = ExecOptions;
152
143
  export type KernelExecResult = ExecResult;
153
- export type StatInfo = VirtualStat;
154
- export type DirEntry = VirtualDirEntry;
155
- export type StdioEvent = {
156
- channel: StdioChannel;
157
- message: string;
158
- };
159
- export type StdioHook = (event: StdioEvent) => void;
160
144
  export interface Permissions {
161
145
  fs?: FsPermissions;
162
146
  network?: NetworkPermissions;
163
147
  childProcess?: ChildProcessPermissions;
164
148
  process?: ProcessPermissions;
165
149
  env?: EnvPermissions;
166
- tool?: ToolPermissions;
167
- }
168
- export interface ResourceBudgets {
169
- maxOutputBytes?: number;
170
- maxBridgeCalls?: number;
171
- maxTimers?: number;
172
- maxChildProcesses?: number;
173
- maxHandles?: number;
174
- }
175
- export interface ProcessConfig {
176
- cwd?: string;
177
- env?: Record<string, string>;
178
- argv?: string[];
179
- stdinIsTTY?: boolean;
180
- stdoutIsTTY?: boolean;
181
- stderrIsTTY?: boolean;
182
- }
183
- export interface OSConfig {
184
- homedir?: string;
185
- tmpdir?: string;
186
- }
187
- export interface CommandExecutor {
188
- spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess;
189
- }
190
- export interface NetworkAdapter {
191
- fetch(url: string, options?: {
192
- method?: string;
193
- headers?: Record<string, string>;
194
- body?: unknown;
195
- }): Promise<{
196
- ok: boolean;
197
- status: number;
198
- statusText: string;
199
- headers: Record<string, string>;
200
- body: string;
201
- url: string;
202
- redirected: boolean;
203
- }>;
204
- dnsLookup(hostname: string): Promise<{
205
- address?: string;
206
- family?: number;
207
- error?: string;
208
- code?: string;
209
- }>;
210
- httpRequest(url: string, options?: {
211
- method?: string;
212
- headers?: Record<string, string>;
213
- body?: unknown;
214
- }): Promise<{
215
- status: number;
216
- statusText: string;
217
- headers: Record<string, string>;
218
- body: string;
219
- url: string;
220
- }>;
221
- }
222
- export interface SystemDriver {
223
- filesystem?: VirtualFileSystem;
224
- network?: NetworkAdapter;
225
- commandExecutor?: CommandExecutor;
226
- permissions?: Permissions;
227
- runtime: {
228
- process: ProcessConfig;
229
- os: OSConfig;
230
- };
231
- }
232
- export interface RuntimeDriverOptions {
233
- system: SystemDriver;
234
- runtime: {
235
- process: ProcessConfig;
236
- os: OSConfig;
237
- };
238
- memoryLimit?: number;
239
- cpuTimeLimitMs?: number;
240
- timingMitigation?: TimingMitigation;
241
- onStdio?: StdioHook;
242
- payloadLimits?: {
243
- base64TransferBytes?: number;
244
- jsonPayloadBytes?: number;
245
- };
246
- resourceBudgets?: ResourceBudgets;
247
- }
248
- export interface NodeRuntimeDriver {
249
- exec(code: string, options?: ExecOptions): Promise<ExecResult>;
250
- run<T = unknown>(code: string, filePath?: string): Promise<RunResult<T>>;
251
- dispose(): void;
252
- terminate?(): Promise<void>;
253
- readonly network?: Pick<NetworkAdapter, "fetch" | "dnsLookup" | "httpRequest">;
254
- }
255
- export interface NodeRuntimeDriverFactory {
256
- createRuntimeDriver(options: RuntimeDriverOptions): NodeRuntimeDriver;
150
+ binding?: BindingPermissions;
257
151
  }
258
152
  export interface KernelInterface {
259
153
  vfs: VirtualFileSystem;
260
154
  }
155
+ export interface KernelRecursiveDirEntry {
156
+ name: string;
157
+ path: string;
158
+ isDirectory: boolean;
159
+ isSymbolicLink: boolean;
160
+ size: number;
161
+ }
261
162
  export interface Kernel extends KernelInterface {
262
- mount(driver: KernelRuntimeDriver): Promise<void>;
263
163
  dispose(): Promise<void>;
264
164
  exec(command: string, options?: KernelExecOptions): Promise<KernelExecResult>;
265
- spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess;
266
- openShell(options?: OpenShellOptions): ShellHandle;
267
- connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
165
+ spawn(command: string, args: string[], options?: KernelSpawnOptions): Promise<ManagedProcess>;
166
+ openShell(options?: OpenShellOptions): Promise<ShellHandle>;
268
167
  mountFs(path: string, fs: VirtualFileSystem, options?: {
269
168
  readOnly?: boolean;
270
- }): void;
271
- unmountFs(path: string): void;
169
+ }): void | Promise<void>;
170
+ unmountFs(path: string): void | Promise<void>;
272
171
  readFile(path: string): Promise<Uint8Array>;
273
172
  writeFile(path: string, content: string | Uint8Array): Promise<void>;
274
- mkdir(path: string): Promise<void>;
173
+ mkdir(path: string, options?: {
174
+ recursive?: boolean;
175
+ }): Promise<void>;
275
176
  readdir(path: string): Promise<string[]>;
177
+ readdirRecursive(path: string, options?: {
178
+ maxDepth?: number;
179
+ }): Promise<KernelRecursiveDirEntry[]>;
276
180
  stat(path: string): Promise<VirtualStat>;
277
181
  exists(path: string): Promise<boolean>;
278
182
  removeFile(path: string): Promise<void>;
279
183
  removeDir(path: string): Promise<void>;
184
+ removePath(path: string, options?: {
185
+ recursive?: boolean;
186
+ }): Promise<void>;
280
187
  rename(oldPath: string, newPath: string): Promise<void>;
281
- readonly commands: ReadonlyMap<string, string>;
188
+ movePath(oldPath: string, newPath: string): Promise<void>;
282
189
  readonly processes: ReadonlyMap<number, ProcessInfo>;
283
190
  readonly env: Record<string, string>;
284
191
  readonly cwd: string;
285
- readonly socketTable: {
286
- hasHostNetworkAdapter(): boolean;
287
- findListener(_request: unknown): unknown | null;
288
- findBoundUdp(_request: unknown): unknown | null;
289
- };
290
- readonly processTable: {
291
- getSignalState(_pid: number): {
292
- handlers: Map<number, unknown>;
293
- };
294
- };
295
- readonly timerTable: Record<string, never>;
296
- readonly zombieTimerCount: number;
297
- }
298
- export interface BindingTree {
299
- [key: string]: BindingFunction | BindingTree;
300
- }
301
- export type BindingFunction = (...args: unknown[]) => unknown;
302
- export interface NodeDriverOptions {
303
- filesystem?: VirtualFileSystem;
304
- networkAdapter?: NetworkAdapter;
305
- commandExecutor?: CommandExecutor;
306
- permissions?: Permissions;
307
- processConfig?: ProcessConfig;
308
- osConfig?: OSConfig;
309
- }
310
- export interface DefaultNetworkAdapterOptions {
311
- loopbackExemptPorts?: number[];
312
- }
313
- export interface NodeRuntimeOptions {
314
- systemDriver?: SystemDriver;
315
- runtimeDriverFactory?: NodeRuntimeDriverFactory;
316
- permissions?: Partial<Permissions>;
317
- memoryLimit?: number;
318
- bindings?: BindingTree;
319
- loopbackExemptPorts?: number[];
320
- }
321
- export type NodeRuntimeDriverFactoryOptions = Record<string, never>;
322
- export type NodeExecutionDriverOptions = RuntimeDriverOptions;
323
- export interface KernelRuntimeDriver {
324
- readonly kind: "node" | "wasmvm";
325
- readonly name: string;
326
- readonly commands: string[];
327
- readonly commandDirs?: string[];
328
- }
329
- export type DriverProcess = ManagedProcess;
330
- export type ProcessContext = Record<string, never>;
331
- export type PermissionTier = "full" | "read-write" | "read-only" | "isolated";
332
- export interface WasmVmRuntimeOptions {
333
- wasmBinaryPath?: string;
334
- commandDirs?: string[];
335
- permissions?: Record<string, PermissionTier>;
336
192
  }
193
+ export {};