@rivet-dev/agentos-core 0.0.0-integrate-dylib-into-main.815fcda → 0.0.0-main.29b0797
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -43
- package/dist/agent-os.d.ts +313 -226
- package/dist/agent-os.js +1418 -1545
- package/dist/agentos-package.d.ts +31 -0
- package/dist/agentos-package.js +91 -0
- package/dist/base-filesystem.d.ts +2 -15
- package/dist/base-filesystem.js +23 -171
- package/dist/{host-tools-zod.d.ts → bindings-zod.d.ts} +1 -1
- package/dist/{host-tools-zod.js → bindings-zod.js} +52 -25
- package/dist/bindings.d.ts +43 -0
- package/dist/bindings.js +34 -0
- package/dist/cron/cron-manager.js +43 -10
- package/dist/cron/index.d.ts +1 -1
- package/dist/cron/types.d.ts +26 -10
- package/dist/default-software.d.ts +8 -0
- package/dist/default-software.js +10 -0
- package/dist/filesystem-snapshot.d.ts +1 -2
- package/dist/filesystem-snapshot.js +0 -43
- package/dist/generated/AcpLimitsConfig.d.ts +20 -0
- package/dist/generated/AcpLimitsConfig.js +2 -0
- package/dist/generated/BindingLimitsConfig.d.ts +10 -0
- package/dist/generated/BindingLimitsConfig.js +2 -0
- package/dist/generated/CreateVmConfig.d.ts +28 -0
- package/dist/generated/FsPermissionRule.d.ts +6 -0
- package/dist/generated/FsPermissionRule.js +1 -0
- package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
- package/dist/generated/FsPermissionRuleSet.js +1 -0
- package/dist/generated/FsPermissionScope.d.ts +3 -0
- package/dist/generated/FsPermissionScope.js +1 -0
- package/dist/generated/HttpLimitsConfig.d.ts +3 -0
- package/dist/generated/HttpLimitsConfig.js +2 -0
- package/dist/generated/JsModuleResolution.d.ts +1 -0
- package/dist/generated/JsModuleResolution.js +2 -0
- package/dist/generated/JsRuntimeConfig.d.ts +31 -0
- package/dist/generated/JsRuntimeConfig.js +1 -0
- package/dist/generated/JsRuntimeLimitsConfig.d.ts +11 -0
- package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
- package/dist/generated/JsRuntimePlatform.d.ts +1 -0
- package/dist/generated/JsRuntimePlatform.js +2 -0
- package/dist/generated/MountPluginDescriptor.d.ts +4 -0
- package/dist/generated/MountPluginDescriptor.js +2 -0
- package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
- package/dist/generated/NativeRootFilesystemConfig.js +1 -0
- package/dist/generated/PatternPermissionRule.d.ts +6 -0
- package/dist/generated/PatternPermissionRule.js +1 -0
- package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
- package/dist/generated/PatternPermissionRuleSet.js +1 -0
- package/dist/generated/PatternPermissionScope.d.ts +3 -0
- package/dist/generated/PatternPermissionScope.js +1 -0
- package/dist/generated/PermissionMode.d.ts +1 -0
- package/dist/generated/PermissionMode.js +2 -0
- package/dist/generated/PermissionsPolicy.d.ts +10 -0
- package/dist/generated/PermissionsPolicy.js +1 -0
- package/dist/generated/PluginLimitsConfig.d.ts +4 -0
- package/dist/generated/PluginLimitsConfig.js +2 -0
- package/dist/generated/ProcessLimitsConfig.d.ts +7 -0
- package/dist/generated/ProcessLimitsConfig.js +2 -0
- package/dist/generated/PythonLimitsConfig.d.ts +6 -0
- package/dist/generated/PythonLimitsConfig.js +2 -0
- package/dist/generated/ResourceLimitsConfig.d.ts +24 -0
- package/dist/generated/ResourceLimitsConfig.js +2 -0
- package/dist/generated/RootFilesystemConfig.d.ts +9 -0
- package/dist/generated/RootFilesystemConfig.js +1 -0
- package/dist/generated/RootFilesystemEntry.d.ts +13 -0
- package/dist/generated/RootFilesystemEntry.js +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
- package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
- package/dist/generated/RootFilesystemEntryKind.js +2 -0
- package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
- package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
- package/dist/generated/RootFilesystemMode.d.ts +1 -0
- package/dist/generated/RootFilesystemMode.js +2 -0
- package/dist/generated/VmDnsConfig.d.ts +6 -0
- package/dist/generated/VmDnsConfig.js +2 -0
- package/dist/generated/VmGroupConfig.d.ts +5 -0
- package/dist/generated/VmGroupConfig.js +2 -0
- package/dist/generated/VmLimitsConfig.d.ts +20 -0
- package/dist/generated/VmLimitsConfig.js +1 -0
- package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
- package/dist/generated/VmListenPolicyConfig.js +2 -0
- package/dist/generated/VmUserAccountConfig.d.ts +9 -0
- package/dist/generated/VmUserAccountConfig.js +2 -0
- package/dist/generated/VmUserConfig.d.ts +19 -0
- package/dist/generated/VmUserConfig.js +1 -0
- package/dist/generated/WasmLimitsConfig.d.ts +8 -0
- package/dist/generated/WasmLimitsConfig.js +2 -0
- package/dist/host-dir-mount.d.ts +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -5
- package/dist/layers.d.ts +7 -4
- package/dist/layers.js +0 -176
- package/dist/options-schema.d.ts +556 -0
- package/dist/options-schema.js +386 -0
- package/dist/packages.d.ts +17 -116
- package/dist/packages.js +35 -322
- package/dist/runtime-compat.d.ts +33 -46
- package/dist/runtime-compat.js +197 -511
- package/dist/runtime.d.ts +42 -8
- package/dist/sandbox.d.ts +112 -0
- package/dist/sandbox.js +264 -0
- package/dist/session-api.d.ts +180 -0
- package/dist/session-api.js +1 -0
- package/dist/sidecar/agentos-protocol.d.ts +509 -20
- package/dist/sidecar/agentos-protocol.js +808 -81
- package/dist/sidecar/native-process-client.d.ts +6 -2
- package/dist/sidecar/native-process-client.js +8 -1
- package/dist/sidecar/permissions.d.ts +1 -1
- package/dist/sidecar/permissions.js +4 -4
- package/dist/sidecar/rpc-client.d.ts +100 -9
- package/dist/sidecar/rpc-client.js +445 -110
- package/dist/test/runtime.d.ts +2 -1
- package/dist/test/runtime.js +2 -1
- package/dist/test/terminal-harness.js +0 -3
- package/dist/types.d.ts +13 -7
- package/package.json +46 -35
- package/dist/agent-session-types.d.ts +0 -67
- package/dist/agents.d.ts +0 -63
- package/dist/agents.js +0 -42
- package/dist/host-tools.d.ts +0 -45
- package/dist/host-tools.js +0 -26
- package/dist/overlay-filesystem.d.ts +0 -19
- package/dist/overlay-filesystem.js +0 -645
- package/fixtures/AGENTOS_SYSTEM_PROMPT.md +0 -21
- /package/dist/{agent-session-types.js → generated/CreateVmConfig.js} +0 -0
package/dist/packages.js
CHANGED
|
@@ -1,335 +1,48 @@
|
|
|
1
|
-
import { existsSync, readFileSync,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { tryReadAgentosPackageManifest } from "./agentos-package.js";
|
|
113
4
|
// ── defineSoftware ───────────────────────────────────────────────────
|
|
114
5
|
/**
|
|
115
|
-
* Define a software descriptor.
|
|
116
|
-
*
|
|
6
|
+
* Define a software descriptor. A type-safe identity function that validates the
|
|
7
|
+
* package-dir reference at compile time. The sidecar materializes the package into
|
|
8
|
+
* the `/opt/agentos` projection.
|
|
117
9
|
*/
|
|
118
10
|
export function defineSoftware(desc) {
|
|
119
11
|
return desc;
|
|
120
12
|
}
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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")) {
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the agent-SDK snapshot bundle (an esbuild IIFE at
|
|
15
|
+
* `<dir>/dist/sdk-snapshot.js`) for the first snapshot-enabled agent package in
|
|
16
|
+
* the software set. Returns its source so it can be evaluated once into the
|
|
17
|
+
* per-sidecar V8 startup snapshot (`jsRuntime.snapshotUserlandCode`) and reused
|
|
18
|
+
* across sessions. Returns `undefined` when no agent opts in (`agent.snapshot`)
|
|
19
|
+
* or the bundle is absent -- the runtime then keeps the per-session import path.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveAgentSnapshotBundle(software) {
|
|
22
|
+
const descriptors = software.flat();
|
|
23
|
+
for (const entry of descriptors) {
|
|
24
|
+
// Only transition package DIRS are readable host-side (their
|
|
25
|
+
// agentos-package.json is the toolchain-input manifest). Packed
|
|
26
|
+
// `.aospkg` refs carry the bundle inside the mount tar; the sidecar
|
|
27
|
+
// reads it from the packed vbare manifest's snapshotBundlePath.
|
|
28
|
+
const path = entry.packagePath;
|
|
29
|
+
if (path === undefined || !statIsDirectory(path))
|
|
223
30
|
continue;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const permissionTier = rawCommand
|
|
227
|
-
.permissionTier;
|
|
228
|
-
if (typeof name !== "string" || !isPermissionTier(permissionTier))
|
|
31
|
+
const manifest = tryReadAgentosPackageManifest(path);
|
|
32
|
+
if (!manifest?.agent?.snapshot)
|
|
229
33
|
continue;
|
|
230
|
-
|
|
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");
|
|
34
|
+
const bundlePath = join(path, "dist", "sdk-snapshot.js");
|
|
35
|
+
if (existsSync(bundlePath)) {
|
|
36
|
+
return readFileSync(bundlePath, "utf-8");
|
|
246
37
|
}
|
|
247
38
|
}
|
|
248
|
-
|
|
249
|
-
registerPermission(commandPermissions, commandName, "isolated");
|
|
250
|
-
}
|
|
39
|
+
return undefined;
|
|
251
40
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
}
|
|
41
|
+
function statIsDirectory(path) {
|
|
42
|
+
try {
|
|
43
|
+
return statSync(path).isDirectory();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
327
47
|
}
|
|
328
|
-
return {
|
|
329
|
-
commandDirs,
|
|
330
|
-
commandPackages,
|
|
331
|
-
commandPermissions,
|
|
332
|
-
softwareRoots,
|
|
333
|
-
agentConfigs,
|
|
334
|
-
};
|
|
335
48
|
}
|
package/dist/runtime-compat.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NodeModulesMountConfig } from "./host-dir-mount.js";
|
|
1
2
|
export declare const AF_INET = 2;
|
|
2
3
|
export declare const AF_UNIX = 1;
|
|
3
4
|
export declare const SOCK_STREAM = 1;
|
|
@@ -15,6 +16,7 @@ export interface VirtualDirEntry {
|
|
|
15
16
|
export interface VirtualStat {
|
|
16
17
|
mode: number;
|
|
17
18
|
size: number;
|
|
19
|
+
sizeExact?: bigint;
|
|
18
20
|
blocks: number;
|
|
19
21
|
dev: number;
|
|
20
22
|
rdev: number;
|
|
@@ -25,7 +27,9 @@ export interface VirtualStat {
|
|
|
25
27
|
ctimeMs: number;
|
|
26
28
|
birthtimeMs: number;
|
|
27
29
|
ino: number;
|
|
30
|
+
inoExact?: bigint;
|
|
28
31
|
nlink: number;
|
|
32
|
+
nlinkExact?: bigint;
|
|
29
33
|
uid: number;
|
|
30
34
|
gid: number;
|
|
31
35
|
}
|
|
@@ -50,7 +54,9 @@ export interface VirtualFileSystem {
|
|
|
50
54
|
lstat(path: string): Promise<VirtualStat>;
|
|
51
55
|
link(oldPath: string, newPath: string): Promise<void>;
|
|
52
56
|
chmod(path: string, mode: number): Promise<void>;
|
|
53
|
-
chown(path: string, uid: number, gid: number
|
|
57
|
+
chown(path: string, uid: number, gid: number, options?: {
|
|
58
|
+
followSymlinks?: boolean;
|
|
59
|
+
}): Promise<void>;
|
|
54
60
|
utimes(path: string, atime: number, mtime: number): Promise<void>;
|
|
55
61
|
truncate(path: string, length: number): Promise<void>;
|
|
56
62
|
pread(path: string, offset: number, length: number): Promise<Uint8Array>;
|
|
@@ -81,7 +87,7 @@ export type NetworkPermissions = PermissionMode | RulePermissions<PatternPermiss
|
|
|
81
87
|
export type ChildProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
|
|
82
88
|
export type ProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
|
|
83
89
|
export type EnvPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
|
|
84
|
-
export type
|
|
90
|
+
export type BindingPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
|
|
85
91
|
export interface ProcessInfo {
|
|
86
92
|
pid: number;
|
|
87
93
|
ppid: number;
|
|
@@ -98,15 +104,16 @@ export interface ProcessInfo {
|
|
|
98
104
|
}
|
|
99
105
|
export interface ManagedProcess {
|
|
100
106
|
pid: number;
|
|
101
|
-
writeStdin(data: Uint8Array | string): void
|
|
102
|
-
closeStdin(): void
|
|
107
|
+
writeStdin(data: Uint8Array | string): Promise<void>;
|
|
108
|
+
closeStdin(): Promise<void>;
|
|
103
109
|
kill(signal?: number): void;
|
|
104
110
|
wait(): Promise<number>;
|
|
105
111
|
readonly exitCode: number | null;
|
|
106
112
|
}
|
|
107
113
|
export interface ShellHandle {
|
|
108
114
|
pid: number;
|
|
109
|
-
write(data: Uint8Array | string): void
|
|
115
|
+
write(data: Uint8Array | string): Promise<void>;
|
|
116
|
+
/** Ordered PTY output containing stdout and stderr exactly once. */
|
|
110
117
|
onData: ((data: Uint8Array) => void) | null;
|
|
111
118
|
resize(cols: number, rows: number): void;
|
|
112
119
|
kill(signal?: number): void;
|
|
@@ -119,6 +126,7 @@ export interface OpenShellOptions {
|
|
|
119
126
|
cwd?: string;
|
|
120
127
|
cols?: number;
|
|
121
128
|
rows?: number;
|
|
129
|
+
/** Optional stderr-only diagnostic tap; do not render it alongside `onData`. */
|
|
122
130
|
onStderr?: (data: Uint8Array) => void;
|
|
123
131
|
}
|
|
124
132
|
export interface ConnectTerminalOptions extends OpenShellOptions {
|
|
@@ -168,7 +176,7 @@ export interface Permissions {
|
|
|
168
176
|
childProcess?: ChildProcessPermissions;
|
|
169
177
|
process?: ProcessPermissions;
|
|
170
178
|
env?: EnvPermissions;
|
|
171
|
-
|
|
179
|
+
binding?: BindingPermissions;
|
|
172
180
|
}
|
|
173
181
|
export interface ResourceBudgets {
|
|
174
182
|
maxOutputBytes?: number;
|
|
@@ -229,6 +237,7 @@ export interface SystemDriver {
|
|
|
229
237
|
network?: NetworkAdapter;
|
|
230
238
|
commandExecutor?: CommandExecutor;
|
|
231
239
|
permissions?: Permissions;
|
|
240
|
+
mounts: readonly NodeModulesMountConfig[];
|
|
232
241
|
runtime: {
|
|
233
242
|
process: ProcessConfig;
|
|
234
243
|
os: OSConfig;
|
|
@@ -263,6 +272,13 @@ export interface NodeRuntimeDriverFactory {
|
|
|
263
272
|
export interface KernelInterface {
|
|
264
273
|
vfs: VirtualFileSystem;
|
|
265
274
|
}
|
|
275
|
+
export interface KernelRecursiveDirEntry {
|
|
276
|
+
name: string;
|
|
277
|
+
path: string;
|
|
278
|
+
isDirectory: boolean;
|
|
279
|
+
isSymbolicLink: boolean;
|
|
280
|
+
size: number;
|
|
281
|
+
}
|
|
266
282
|
export interface Kernel extends KernelInterface {
|
|
267
283
|
mount(driver: KernelRuntimeDriver): Promise<void>;
|
|
268
284
|
dispose(): Promise<void>;
|
|
@@ -272,17 +288,24 @@ export interface Kernel extends KernelInterface {
|
|
|
272
288
|
connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
|
|
273
289
|
mountFs(path: string, fs: VirtualFileSystem, options?: {
|
|
274
290
|
readOnly?: boolean;
|
|
275
|
-
}): void
|
|
276
|
-
unmountFs(path: string): void
|
|
291
|
+
}): void | Promise<void>;
|
|
292
|
+
unmountFs(path: string): void | Promise<void>;
|
|
277
293
|
readFile(path: string): Promise<Uint8Array>;
|
|
278
294
|
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
279
295
|
mkdir(path: string): Promise<void>;
|
|
280
296
|
readdir(path: string): Promise<string[]>;
|
|
297
|
+
readdirRecursive(path: string, options?: {
|
|
298
|
+
maxDepth?: number;
|
|
299
|
+
}): Promise<KernelRecursiveDirEntry[]>;
|
|
281
300
|
stat(path: string): Promise<VirtualStat>;
|
|
282
301
|
exists(path: string): Promise<boolean>;
|
|
283
302
|
removeFile(path: string): Promise<void>;
|
|
284
303
|
removeDir(path: string): Promise<void>;
|
|
304
|
+
removePath(path: string, options?: {
|
|
305
|
+
recursive?: boolean;
|
|
306
|
+
}): Promise<void>;
|
|
285
307
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
308
|
+
movePath(oldPath: string, newPath: string): Promise<void>;
|
|
286
309
|
readonly commands: ReadonlyMap<string, string>;
|
|
287
310
|
readonly processes: ReadonlyMap<number, ProcessInfo>;
|
|
288
311
|
readonly env: Record<string, string>;
|
|
@@ -304,17 +327,14 @@ export interface BindingTree {
|
|
|
304
327
|
[key: string]: BindingFunction | BindingTree;
|
|
305
328
|
}
|
|
306
329
|
export type BindingFunction = (...args: unknown[]) => unknown;
|
|
307
|
-
export interface ModuleAccessOptions {
|
|
308
|
-
cwd?: string;
|
|
309
|
-
}
|
|
310
330
|
export interface NodeDriverOptions {
|
|
311
331
|
filesystem?: VirtualFileSystem;
|
|
312
332
|
networkAdapter?: NetworkAdapter;
|
|
313
333
|
commandExecutor?: CommandExecutor;
|
|
314
334
|
permissions?: Permissions;
|
|
335
|
+
mounts?: readonly NodeModulesMountConfig[];
|
|
315
336
|
processConfig?: ProcessConfig;
|
|
316
337
|
osConfig?: OSConfig;
|
|
317
|
-
moduleAccess?: ModuleAccessOptions;
|
|
318
338
|
}
|
|
319
339
|
export interface DefaultNetworkAdapterOptions {
|
|
320
340
|
loopbackExemptPorts?: number[];
|
|
@@ -345,40 +365,6 @@ export declare class KernelError extends Error {
|
|
|
345
365
|
readonly code: string;
|
|
346
366
|
constructor(code: string, message: string);
|
|
347
367
|
}
|
|
348
|
-
export declare class InMemoryFileSystem implements VirtualFileSystem {
|
|
349
|
-
private readonly entries;
|
|
350
|
-
constructor();
|
|
351
|
-
readFile(targetPath: string): Promise<Uint8Array>;
|
|
352
|
-
readTextFile(targetPath: string): Promise<string>;
|
|
353
|
-
readDir(targetPath: string): Promise<string[]>;
|
|
354
|
-
readDirWithTypes(targetPath: string): Promise<VirtualDirEntry[]>;
|
|
355
|
-
writeFile(targetPath: string, content: string | Uint8Array): Promise<void>;
|
|
356
|
-
createDir(targetPath: string): Promise<void>;
|
|
357
|
-
mkdir(targetPath: string, options?: {
|
|
358
|
-
recursive?: boolean;
|
|
359
|
-
}): Promise<void>;
|
|
360
|
-
exists(targetPath: string): Promise<boolean>;
|
|
361
|
-
stat(targetPath: string): Promise<VirtualStat>;
|
|
362
|
-
removeFile(targetPath: string): Promise<void>;
|
|
363
|
-
removeDir(targetPath: string): Promise<void>;
|
|
364
|
-
rename(oldPath: string, newPath: string): Promise<void>;
|
|
365
|
-
realpath(targetPath: string): Promise<string>;
|
|
366
|
-
symlink(target: string, linkPath: string): Promise<void>;
|
|
367
|
-
readlink(targetPath: string): Promise<string>;
|
|
368
|
-
lstat(targetPath: string): Promise<VirtualStat>;
|
|
369
|
-
link(oldPath: string, newPath: string): Promise<void>;
|
|
370
|
-
chmod(targetPath: string, mode: number): Promise<void>;
|
|
371
|
-
chown(targetPath: string, uid: number, gid: number): Promise<void>;
|
|
372
|
-
utimes(targetPath: string, atime: number, mtime: number): Promise<void>;
|
|
373
|
-
truncate(targetPath: string, length: number): Promise<void>;
|
|
374
|
-
pread(targetPath: string, offset: number, length: number): Promise<Uint8Array>;
|
|
375
|
-
pwrite(targetPath: string, offset: number, data: Uint8Array): Promise<void>;
|
|
376
|
-
private resolvePath;
|
|
377
|
-
private resolveEntry;
|
|
378
|
-
private newDirectory;
|
|
379
|
-
private toStat;
|
|
380
|
-
}
|
|
381
|
-
export declare function createInMemoryFileSystem(): InMemoryFileSystem;
|
|
382
368
|
export declare class NodeFileSystem implements VirtualFileSystem {
|
|
383
369
|
readonly rootPath: string;
|
|
384
370
|
constructor(options: {
|
|
@@ -472,4 +458,5 @@ export declare function createKernel(options: {
|
|
|
472
458
|
readOnly?: boolean;
|
|
473
459
|
}>;
|
|
474
460
|
syncFilesystemOnDispose?: boolean;
|
|
461
|
+
maxFilesystemBytes?: number;
|
|
475
462
|
}): Kernel;
|