@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.
Files changed (125) hide show
  1. package/README.md +43 -43
  2. package/dist/agent-os.d.ts +313 -226
  3. package/dist/agent-os.js +1418 -1545
  4. package/dist/agentos-package.d.ts +31 -0
  5. package/dist/agentos-package.js +91 -0
  6. package/dist/base-filesystem.d.ts +2 -15
  7. package/dist/base-filesystem.js +23 -171
  8. package/dist/{host-tools-zod.d.ts → bindings-zod.d.ts} +1 -1
  9. package/dist/{host-tools-zod.js → bindings-zod.js} +52 -25
  10. package/dist/bindings.d.ts +43 -0
  11. package/dist/bindings.js +34 -0
  12. package/dist/cron/cron-manager.js +43 -10
  13. package/dist/cron/index.d.ts +1 -1
  14. package/dist/cron/types.d.ts +26 -10
  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 -2
  18. package/dist/filesystem-snapshot.js +0 -43
  19. package/dist/generated/AcpLimitsConfig.d.ts +20 -0
  20. package/dist/generated/AcpLimitsConfig.js +2 -0
  21. package/dist/generated/BindingLimitsConfig.d.ts +10 -0
  22. package/dist/generated/BindingLimitsConfig.js +2 -0
  23. package/dist/generated/CreateVmConfig.d.ts +28 -0
  24. package/dist/generated/FsPermissionRule.d.ts +6 -0
  25. package/dist/generated/FsPermissionRule.js +1 -0
  26. package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
  27. package/dist/generated/FsPermissionRuleSet.js +1 -0
  28. package/dist/generated/FsPermissionScope.d.ts +3 -0
  29. package/dist/generated/FsPermissionScope.js +1 -0
  30. package/dist/generated/HttpLimitsConfig.d.ts +3 -0
  31. package/dist/generated/HttpLimitsConfig.js +2 -0
  32. package/dist/generated/JsModuleResolution.d.ts +1 -0
  33. package/dist/generated/JsModuleResolution.js +2 -0
  34. package/dist/generated/JsRuntimeConfig.d.ts +31 -0
  35. package/dist/generated/JsRuntimeConfig.js +1 -0
  36. package/dist/generated/JsRuntimeLimitsConfig.d.ts +11 -0
  37. package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
  38. package/dist/generated/JsRuntimePlatform.d.ts +1 -0
  39. package/dist/generated/JsRuntimePlatform.js +2 -0
  40. package/dist/generated/MountPluginDescriptor.d.ts +4 -0
  41. package/dist/generated/MountPluginDescriptor.js +2 -0
  42. package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
  43. package/dist/generated/NativeRootFilesystemConfig.js +1 -0
  44. package/dist/generated/PatternPermissionRule.d.ts +6 -0
  45. package/dist/generated/PatternPermissionRule.js +1 -0
  46. package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
  47. package/dist/generated/PatternPermissionRuleSet.js +1 -0
  48. package/dist/generated/PatternPermissionScope.d.ts +3 -0
  49. package/dist/generated/PatternPermissionScope.js +1 -0
  50. package/dist/generated/PermissionMode.d.ts +1 -0
  51. package/dist/generated/PermissionMode.js +2 -0
  52. package/dist/generated/PermissionsPolicy.d.ts +10 -0
  53. package/dist/generated/PermissionsPolicy.js +1 -0
  54. package/dist/generated/PluginLimitsConfig.d.ts +4 -0
  55. package/dist/generated/PluginLimitsConfig.js +2 -0
  56. package/dist/generated/ProcessLimitsConfig.d.ts +7 -0
  57. package/dist/generated/ProcessLimitsConfig.js +2 -0
  58. package/dist/generated/PythonLimitsConfig.d.ts +6 -0
  59. package/dist/generated/PythonLimitsConfig.js +2 -0
  60. package/dist/generated/ResourceLimitsConfig.d.ts +24 -0
  61. package/dist/generated/ResourceLimitsConfig.js +2 -0
  62. package/dist/generated/RootFilesystemConfig.d.ts +9 -0
  63. package/dist/generated/RootFilesystemConfig.js +1 -0
  64. package/dist/generated/RootFilesystemEntry.d.ts +13 -0
  65. package/dist/generated/RootFilesystemEntry.js +1 -0
  66. package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
  67. package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
  68. package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
  69. package/dist/generated/RootFilesystemEntryKind.js +2 -0
  70. package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
  71. package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
  72. package/dist/generated/RootFilesystemMode.d.ts +1 -0
  73. package/dist/generated/RootFilesystemMode.js +2 -0
  74. package/dist/generated/VmDnsConfig.d.ts +6 -0
  75. package/dist/generated/VmDnsConfig.js +2 -0
  76. package/dist/generated/VmGroupConfig.d.ts +5 -0
  77. package/dist/generated/VmGroupConfig.js +2 -0
  78. package/dist/generated/VmLimitsConfig.d.ts +20 -0
  79. package/dist/generated/VmLimitsConfig.js +1 -0
  80. package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
  81. package/dist/generated/VmListenPolicyConfig.js +2 -0
  82. package/dist/generated/VmUserAccountConfig.d.ts +9 -0
  83. package/dist/generated/VmUserAccountConfig.js +2 -0
  84. package/dist/generated/VmUserConfig.d.ts +19 -0
  85. package/dist/generated/VmUserConfig.js +1 -0
  86. package/dist/generated/WasmLimitsConfig.d.ts +8 -0
  87. package/dist/generated/WasmLimitsConfig.js +2 -0
  88. package/dist/host-dir-mount.d.ts +1 -1
  89. package/dist/index.d.ts +6 -5
  90. package/dist/index.js +5 -5
  91. package/dist/layers.d.ts +7 -4
  92. package/dist/layers.js +0 -176
  93. package/dist/options-schema.d.ts +556 -0
  94. package/dist/options-schema.js +386 -0
  95. package/dist/packages.d.ts +17 -116
  96. package/dist/packages.js +35 -322
  97. package/dist/runtime-compat.d.ts +33 -46
  98. package/dist/runtime-compat.js +197 -511
  99. package/dist/runtime.d.ts +42 -8
  100. package/dist/sandbox.d.ts +112 -0
  101. package/dist/sandbox.js +264 -0
  102. package/dist/session-api.d.ts +180 -0
  103. package/dist/session-api.js +1 -0
  104. package/dist/sidecar/agentos-protocol.d.ts +509 -20
  105. package/dist/sidecar/agentos-protocol.js +808 -81
  106. package/dist/sidecar/native-process-client.d.ts +6 -2
  107. package/dist/sidecar/native-process-client.js +8 -1
  108. package/dist/sidecar/permissions.d.ts +1 -1
  109. package/dist/sidecar/permissions.js +4 -4
  110. package/dist/sidecar/rpc-client.d.ts +100 -9
  111. package/dist/sidecar/rpc-client.js +445 -110
  112. package/dist/test/runtime.d.ts +2 -1
  113. package/dist/test/runtime.js +2 -1
  114. package/dist/test/terminal-harness.js +0 -3
  115. package/dist/types.d.ts +13 -7
  116. package/package.json +46 -35
  117. package/dist/agent-session-types.d.ts +0 -67
  118. package/dist/agents.d.ts +0 -63
  119. package/dist/agents.js +0 -42
  120. package/dist/host-tools.d.ts +0 -45
  121. package/dist/host-tools.js +0 -26
  122. package/dist/overlay-filesystem.d.ts +0 -19
  123. package/dist/overlay-filesystem.js +0 -645
  124. package/fixtures/AGENTOS_SYSTEM_PROMPT.md +0 -21
  125. /package/dist/{agent-session-types.js → generated/CreateVmConfig.js} +0 -0
@@ -1,13 +1,11 @@
1
- import type { NativeMountPluginDescriptor } from "@secure-exec/core/descriptors";
2
- import type { AgentCapabilities, AgentInfo, PermissionReply, PermissionRequestHandler, SessionConfigOption, SessionEventHandler, SessionModeState } from "./agent-session-types.js";
3
- import { type ToolKit } from "./host-tools.js";
4
- import type { JsonRpcResponse } from "./json-rpc.js";
1
+ import type { NativeMountPluginDescriptor } from "@rivet-dev/agentos-runtime-core/descriptors";
2
+ import type { VmUserConfig } from "@rivet-dev/agentos-runtime-core/vm-config";
3
+ import type { CancelPromptResult, HistoryPage, ListSessionsInput, OpenSessionInput, PermissionResponse, PermissionResponseResult, PromptInput, PromptResult as DurablePromptResult, ReadHistoryInput, SessionCapabilities, SessionAgentInfo, SessionConfig, SessionInfo as DurableSessionInfo, SessionPage, SessionStreamEntry, SessionTarget, SetSessionConfigOptionInput } from "./session-api.js";
4
+ import { type Bindings } from "./bindings.js";
5
5
  import type { ConnectTerminalOptions, Kernel, KernelExecOptions, KernelExecResult, ProcessInfo as KernelProcessInfo, KernelSpawnOptions, OpenShellOptions, Permissions, VirtualFileSystem, VirtualStat } from "./runtime-compat.js";
6
- export type { MountConfigJsonObject, MountConfigJsonPrimitive, MountConfigJsonValue, NativeMountPluginDescriptor, } from "@secure-exec/core/descriptors";
7
- export type { AgentCapabilities, AgentInfo, PermissionReply, PermissionRequest, PermissionRequestHandler, SessionConfigOption, SessionEventHandler, SessionInitData, SessionMode, SessionModeState, } from "./agent-session-types.js";
8
- export type { AcpTimeoutErrorData, JsonRpcError, JsonRpcErrorData, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, } from "./json-rpc.js";
9
- export { isAcpTimeoutErrorData } from "./json-rpc.js";
6
+ export type { MountConfigJsonObject, MountConfigJsonPrimitive, MountConfigJsonValue, NativeMountPluginDescriptor, } from "@rivet-dev/agentos-runtime-core/descriptors";
10
7
  export type { ConnectTerminalOptions } from "./runtime-compat.js";
8
+ export type * from "./session-api.js";
11
9
  /** Process tree node: extends kernel ProcessInfo with child references. */
12
10
  export interface ProcessTreeNode extends KernelProcessInfo {
13
11
  children: ProcessTreeNode[];
@@ -19,6 +17,64 @@ export interface DirEntry {
19
17
  type: "file" | "directory" | "symlink";
20
18
  size: number;
21
19
  }
20
+ /** One immediate child returned by a single readdirEntries operation. */
21
+ export interface ReaddirEntry {
22
+ name: string;
23
+ isDirectory: boolean;
24
+ isSymbolicLink: boolean;
25
+ }
26
+ /** Fully buffered request to an HTTP service listening inside the VM. */
27
+ export interface HttpRequest {
28
+ port: number;
29
+ path: string;
30
+ method?: string;
31
+ headers?: Record<string, string>;
32
+ body?: string | Uint8Array;
33
+ }
34
+ /** Fully buffered HTTP response from a service inside the VM. */
35
+ export interface HttpResponse {
36
+ status: number;
37
+ statusText: string;
38
+ headers: Record<string, string>;
39
+ body: Uint8Array;
40
+ }
41
+ export interface ProcessOutput {
42
+ pid: number;
43
+ stream: "stdout" | "stderr";
44
+ data: Uint8Array;
45
+ }
46
+ export interface ProcessExit {
47
+ pid: number;
48
+ exitCode: number;
49
+ }
50
+ export interface ShellData {
51
+ shellId: string;
52
+ data: Uint8Array;
53
+ }
54
+ export interface ShellExit {
55
+ shellId: string;
56
+ exitCode: number;
57
+ }
58
+ /** Sanitized live mount metadata. Plugin configuration is never exposed. */
59
+ export interface MountInfo {
60
+ path: string;
61
+ kind: string;
62
+ readOnly: boolean;
63
+ }
64
+ export interface ExportRootFilesystemOptions {
65
+ /** Maximum serialized snapshot bytes returned to this caller. */
66
+ maxBytes: number;
67
+ }
68
+ /** Portable, sidecar-owned dynamic mount descriptor. */
69
+ export interface DynamicMountDescriptor {
70
+ path: string;
71
+ plugin: NativeMountPluginDescriptor;
72
+ readOnly?: boolean;
73
+ }
74
+ /** Callback-free options accepted by the portable spawn API. */
75
+ export type SpawnOptions = Omit<KernelSpawnOptions, "onStdout" | "onStderr">;
76
+ /** Callback-free options accepted by the portable openShell API. */
77
+ export type ShellOptions = Omit<OpenShellOptions, "onStderr">;
22
78
  /** Options for readdirRecursive(). */
23
79
  export interface ReaddirRecursiveOptions {
24
80
  /** Maximum depth to recurse (0 = only immediate children). */
@@ -46,15 +102,13 @@ export interface BatchReadResult {
46
102
  /** Entry in the agent registry, describing an available agent type. */
47
103
  export interface AgentRegistryEntry {
48
104
  id: string;
49
- acpAdapter: string;
50
- agentPackage: string;
51
105
  installed: boolean;
52
106
  }
53
- import { type AgentType } from "./agents.js";
107
+ import { type PackageDescriptor } from "./agentos-package.js";
54
108
  import type { ScheduleDriver } from "./cron/schedule-driver.js";
55
109
  import type { CronEventHandler, CronJob, CronJobInfo, CronJobOptions } from "./cron/types.js";
56
110
  import { type LayerStore, type OverlayFilesystemMode, type RootSnapshotExport, type SnapshotLayerHandle } from "./layers.js";
57
- import { type SoftwareInput } from "./packages.js";
111
+ import type { SoftwareInput } from "./packages.js";
58
112
  import { type AgentOsSidecarPlacement } from "./sidecar/rpc-client.js";
59
113
  export interface AgentOsSharedSidecarOptions {
60
114
  pool?: string;
@@ -78,12 +132,28 @@ export interface AgentOsSidecarDescription {
78
132
  export type RootLowerInput = {
79
133
  kind: "bundled-base-filesystem";
80
134
  } | RootSnapshotExport;
81
- export interface RootFilesystemConfig {
135
+ export interface OverlayRootFilesystemConfig {
82
136
  type?: "overlay";
83
137
  mode?: OverlayFilesystemMode;
84
138
  disableDefaultBaseLayer?: boolean;
85
139
  lowers?: RootLowerInput[];
86
140
  }
141
+ /** Declarative sidecar-native root filesystem. */
142
+ export interface NativeRootFilesystemConfig {
143
+ type: "native";
144
+ plugin: NativeMountPluginDescriptor;
145
+ readOnly?: boolean;
146
+ }
147
+ export type RootFilesystemConfig = OverlayRootFilesystemConfig | NativeRootFilesystemConfig;
148
+ /** VM-scoped SQLite storage shared by VFS and AgentOS durable state. */
149
+ export type VmSqliteConfig = {
150
+ type: "actor_uds";
151
+ path: string;
152
+ token: string;
153
+ } | {
154
+ type: "sqlite_file";
155
+ path: string;
156
+ };
87
157
  /**
88
158
  * Compatibility path for arbitrary caller-supplied filesystems.
89
159
  * This maps to the sidecar `js_bridge` plugin during the migration.
@@ -93,6 +163,10 @@ export interface PlainMountConfig {
93
163
  path: string;
94
164
  /** The filesystem driver to mount. */
95
165
  driver: VirtualFileSystem;
166
+ /** Filesystem type exposed through guest mount discovery. */
167
+ guestFstype?: string;
168
+ /** Source name exposed through guest mount discovery. */
169
+ guestSource?: string;
96
170
  /** If true, write operations throw EROFS. */
97
171
  readOnly?: boolean;
98
172
  }
@@ -100,6 +174,10 @@ export interface PlainMountConfig {
100
174
  export interface NativeMountConfig {
101
175
  path: string;
102
176
  plugin: NativeMountPluginDescriptor;
177
+ /** Filesystem type exposed through guest mount discovery. */
178
+ guestFstype?: string;
179
+ /** Source name exposed through guest mount discovery. */
180
+ guestSource?: string;
103
181
  readOnly?: boolean;
104
182
  }
105
183
  export interface OverlayMountConfig {
@@ -145,33 +223,50 @@ export interface AgentOsLimits {
145
223
  };
146
224
  /** HTTP body buffering limits. */
147
225
  http?: {
148
- /** Cap on `vm.fetch()` buffered response bodies. Must be <= the sidecar wire frame cap. */
226
+ /** Cap on `vm.httpRequest()` buffered response bodies. Must be <= the sidecar wire frame cap. */
149
227
  maxFetchResponseBytes?: number;
150
228
  };
151
- /** Host-tool registration and invocation limits. */
152
- tools?: {
153
- defaultToolTimeoutMs?: number;
154
- maxToolTimeoutMs?: number;
155
- maxRegisteredToolkits?: number;
156
- maxRegisteredToolsPerVm?: number;
157
- maxToolsPerToolkit?: number;
158
- maxToolSchemaBytes?: number;
159
- maxToolExamplesPerTool?: number;
160
- maxToolExampleInputBytes?: number;
229
+ /** Host binding registration and invocation limits. */
230
+ bindings?: {
231
+ defaultBindingTimeoutMs?: number;
232
+ maxBindingTimeoutMs?: number;
233
+ maxRegisteredCollections?: number;
234
+ maxRegisteredCollectionsPerVm?: number;
235
+ maxBindingsPerCollection?: number;
236
+ maxBindingSchemaBytes?: number;
237
+ maxExamplesPerBinding?: number;
238
+ maxBindingExampleInputBytes?: number;
161
239
  };
162
240
  /** Mount plugin manifest size limits. */
163
241
  plugins?: {
164
242
  maxPersistedManifestBytes?: number;
165
243
  maxPersistedManifestFileBytes?: number;
166
244
  };
167
- /** ACP adapter buffering limits. */
245
+ /** ACP adapter, active-turn, history-retention, and page limits. */
168
246
  acp?: {
169
247
  maxReadLineBytes?: number;
170
248
  stdoutBufferByteLimit?: number;
249
+ maxCompletedMessageBytes?: number;
250
+ maxTurnOutputBytes?: number;
251
+ maxPromptBytes?: number;
252
+ maxPromptBlocks?: number;
253
+ maxFallbackContinuationBytes?: number;
254
+ maxSessionHistoryBytes?: number;
255
+ maxSessionHistoryEvents?: number;
256
+ maxHistoryPageEntries?: number;
257
+ maxSessionListEntries?: number;
258
+ };
259
+ /** Shared local-file/actor-UDS SQLite result materialization limit. */
260
+ sqlite?: {
261
+ maxResultBytes?: number;
171
262
  };
172
263
  /** Guest JavaScript runtime buffering limits. */
173
264
  jsRuntime?: {
174
265
  v8HeapLimitMb?: number;
266
+ syncRpcWaitTimeoutMs?: number;
267
+ cpuTimeLimitMs?: number;
268
+ wallClockLimitMs?: number;
269
+ importCacheMaterializeTimeoutMs?: number;
175
270
  capturedOutputLimitBytes?: number;
176
271
  stdinBufferLimitBytes?: number;
177
272
  eventPayloadLimitBytes?: number;
@@ -181,6 +276,7 @@ export interface AgentOsLimits {
181
276
  python?: {
182
277
  outputBufferMaxBytes?: number;
183
278
  executionTimeoutMs?: number;
279
+ maxOldSpaceMb?: number;
184
280
  vfsRpcTimeoutMs?: number;
185
281
  };
186
282
  /** Guest WASM runtime limits. */
@@ -188,15 +284,85 @@ export interface AgentOsLimits {
188
284
  maxModuleFileBytes?: number;
189
285
  capturedOutputLimitBytes?: number;
190
286
  syncReadLimitBytes?: number;
287
+ prewarmTimeoutMs?: number;
288
+ runnerHeapLimitMb?: number;
289
+ runnerCpuTimeLimitMs?: number;
191
290
  };
291
+ /** Process spawn, I/O, and lifecycle-event backlog limits. */
292
+ process?: {
293
+ maxSpawnFileActions?: number;
294
+ maxSpawnFileActionBytes?: number;
295
+ pendingStdinBytes?: number;
296
+ pendingEventCount?: number;
297
+ pendingEventBytes?: number;
298
+ };
299
+ }
300
+ export interface AgentStderrEvent {
301
+ sessionId: string;
302
+ agentType: string;
303
+ processId: string;
304
+ pid: number | null;
305
+ chunk: Uint8Array;
306
+ }
307
+ export type AgentStderrHandler = (event: AgentStderrEvent) => void;
308
+ /**
309
+ * Restart disposition reported on an {@link AgentExitEvent}. AgentOS never
310
+ * respawns an adapter or replays an interrupted request implicitly.
311
+ */
312
+ export type AgentRestartOutcome = "not_attempted";
313
+ /**
314
+ * An unexpected ACP adapter process exit — a crash from the host's
315
+ * perspective (any spontaneous exit before `unloadSession()`, including exit
316
+ * code 0). The live route is evicted and must be restored explicitly.
317
+ */
318
+ export interface AgentExitEvent {
319
+ sessionId: string;
320
+ agentType: string;
321
+ /** Sidecar process id of the adapter that exited. */
322
+ processId: string;
323
+ pid: number | null;
324
+ /** Adapter exit code; `null` when the exit was observed indirectly. */
325
+ exitCode: number | null;
326
+ /** Always `"not_attempted"`; AgentOS does not restart adapters implicitly. */
327
+ restart: AgentRestartOutcome;
328
+ /** Always zero. */
329
+ restartCount: number;
330
+ /** Always zero. */
331
+ maxRestarts: number;
192
332
  }
333
+ export type AgentExitHandler = (event: AgentExitEvent) => void;
334
+ /**
335
+ * A near-capacity warning for one bounded limit (a queue/buffer, a saturating
336
+ * resource cap, or a memory envelope) inside the VM runtime. Delivered the moment
337
+ * usage crosses the runtime's warning threshold (~80%), once per crossing — the
338
+ * runtime applies edge-triggering + hysteresis, so this never spams.
339
+ */
340
+ export interface LimitWarning {
341
+ /** Stable limit name, e.g. `"javascript_event_channel"` or `"vm_open_fds"`. */
342
+ limit: string;
343
+ /** Limit class: `"queue"`, `"resource"`, or `"memory"`. */
344
+ category: string;
345
+ /** Current observed usage. */
346
+ observed: number;
347
+ /** Configured capacity. */
348
+ capacity: number;
349
+ /** Observed fill as a percentage of capacity (0–100). */
350
+ fillPercent: number;
351
+ }
352
+ export type LimitWarningHandler = (warning: LimitWarning) => void;
353
+ /**
354
+ * Public core VM options.
355
+ *
356
+ * Keep this interface in sync with
357
+ * `packages/core/src/options-schema.ts::agentOsOptionsSchema`. The TypeScript
358
+ * Rivet actor accepts this surface directly alongside ordinary actor options.
359
+ */
193
360
  export interface AgentOsOptions {
361
+ /** Initial virtual Linux credentials and account record. Defaults to `1000:1000` (`agentos`). */
362
+ user?: VmUserConfig;
194
363
  /**
195
- * Software to install in the VM. Each entry provides agents, tools,
196
- * or WASM commands. Any object with a `commandDir` property (e.g.,
197
- * registry packages like @agentos-software/coreutils) is treated
198
- * as a WASM command source automatically. Arrays are flattened, so
199
- * meta-packages that export arrays of sub-packages work directly.
364
+ * Software to install in the VM. Each entry is a package-dir ref. Arrays are
365
+ * flattened, so meta-packages that export arrays of sub-packages work directly.
200
366
  */
201
367
  software?: SoftwareInput[];
202
368
  /**
@@ -214,21 +380,24 @@ export interface AgentOsOptions {
214
380
  * Defaults to the hardened builtin set used by the native sidecar bridge.
215
381
  */
216
382
  allowedNodeBuiltins?: string[];
383
+ /**
384
+ * Opt in to a high-resolution monotonic guest clock (microsecond class)
385
+ * for guest Node processes. Default `false` keeps the security-oriented
386
+ * 1ms timer resolution — untrusted guest code should not get a precise
387
+ * timer (timing side channels). Enable only for trusted benchmarking or
388
+ * profiling workloads.
389
+ */
390
+ highResolutionTime?: boolean;
391
+ /** Durable SQLite storage for VM-owned filesystem and session state. */
392
+ database?: VmSqliteConfig;
217
393
  /** Root filesystem configuration. Defaults to an overlay with the bundled base snapshot as its deepest lower. */
218
394
  rootFilesystem?: RootFilesystemConfig;
219
395
  /** Filesystems to mount at boot time. */
220
396
  mounts?: MountConfig[];
221
- /**
222
- * @deprecated Use `mounts: [nodeModulesMount(path)]` instead.
223
- * Compatibility alias for mounting `<moduleAccessCwd>/node_modules` at `/root/node_modules`.
224
- */
225
- moduleAccessCwd?: string;
226
- /** Additional instructions appended to the base OS system prompt injected at session start. */
227
- additionalInstructions?: string;
228
397
  /** Custom schedule driver for cron jobs. Defaults to TimerScheduleDriver. */
229
398
  scheduleDriver?: ScheduleDriver;
230
- /** Host-side toolkits available to agents inside the VM. */
231
- toolKits?: ToolKit[];
399
+ /** Host-side bindings available to agents inside the VM. */
400
+ bindings?: Bindings[];
232
401
  /**
233
402
  * Custom permission policy for the kernel. Controls access to filesystem,
234
403
  * network, child process, and environment operations. Defaults to allowAll.
@@ -244,86 +413,33 @@ export interface AgentOsOptions {
244
413
  * runtime's historical constants, so omitting this leaves behavior unchanged.
245
414
  */
246
415
  limits?: AgentOsLimits;
416
+ /**
417
+ * Called with stderr chunks from the top-level ACP-speaking agent process.
418
+ * The agent process uses stdout for ACP JSON-RPC protocol traffic, so only
419
+ * stderr is forwarded through this hook. Defaults to writing chunks to
420
+ * `process.stderr`.
421
+ */
422
+ onAgentStderr?: AgentStderrHandler;
423
+ /**
424
+ * Called when the ACP adapter process behind a session exits unexpectedly.
425
+ * The sidecar evicts the live
426
+ * route and never retries the adapter or interrupted request implicitly.
427
+ * Defaults to writing a warning line to `process.stderr`.
428
+ */
429
+ onAgentExit?: AgentExitHandler;
430
+ /**
431
+ * Called when a bounded limit inside the VM runtime approaches capacity
432
+ * (~80%, edge-triggered with hysteresis so it does not spam). Use it to alert
433
+ * on a slow consumer or a runaway guest before the limit is actually hit.
434
+ */
435
+ onLimitWarning?: LimitWarningHandler;
247
436
  }
248
- /** Configuration for a local MCP server (spawned as a child process). */
249
- export interface McpServerConfigLocal {
250
- type: "local";
251
- /** Command to launch the MCP server. */
252
- command: string;
253
- /** Arguments for the command. */
254
- args?: string[];
255
- /** Environment variables for the server process. */
256
- env?: Record<string, string>;
257
- }
258
- /** Configuration for a remote MCP server (connected via URL). */
259
- export interface McpServerConfigRemote {
260
- type: "remote";
261
- /** URL of the remote MCP server. */
262
- url: string;
263
- /** HTTP headers to include in requests to the server. */
264
- headers?: Record<string, string>;
265
- }
266
- export type McpServerConfig = McpServerConfigLocal | McpServerConfigRemote;
267
437
  export interface AgentOsRuntimeAdmin {
268
438
  kernel: Kernel;
269
439
  rootView: VirtualFileSystem;
270
440
  env: Record<string, string>;
271
441
  sidecar: AgentOsSidecar;
272
442
  }
273
- export interface CreateSessionOptions {
274
- /** Working directory for the agent session inside the VM. */
275
- cwd?: string;
276
- /** Environment variables to pass to the agent process. */
277
- env?: Record<string, string>;
278
- /** MCP servers to make available to the agent during the session. */
279
- mcpServers?: McpServerConfig[];
280
- /** Skip OS instructions injection entirely (default false). */
281
- skipOsInstructions?: boolean;
282
- /** Additional instructions appended to the base OS instructions. */
283
- additionalInstructions?: string;
284
- }
285
- /**
286
- * Options for {@link AgentOs.resumeSession}.
287
- *
288
- * Resume depends on a durable root: after a Rivet actor sleeps (VM destroyed) and
289
- * wakes (fresh VM, actor SQLite intact) the caller can keep prompting an existing
290
- * session. On a non-durable (default in-memory) root there is no surviving store,
291
- * so the sidecar's universal fallback tier always runs and the transcript pointer
292
- * is the only continuity mechanism.
293
- */
294
- export interface ResumeSessionOptions {
295
- /**
296
- * Guest-readable path to the reconstructed transcript. When present, the
297
- * fallback tier arms a continuation preamble pointing the agent at it.
298
- */
299
- transcriptPath?: string;
300
- /** Working directory for the resumed agent session (default `/home/user`). */
301
- cwd?: string;
302
- /** Environment variables to pass to the resumed agent process. */
303
- env?: Record<string, string>;
304
- }
305
- /** Result from {@link AgentOs.resumeSession}. */
306
- export interface ResumeSessionResult {
307
- /**
308
- * The live ACP session id in the fresh VM: equal to the requested id for
309
- * native loads, or a freshly assigned id for the fallback tier — the caller
310
- * remaps `external -> live`.
311
- */
312
- sessionId: string;
313
- /** `"native"` (session/load|resume) or `"fallback"` (session/new + preamble). */
314
- mode: string;
315
- }
316
- export interface SessionInfo {
317
- sessionId: string;
318
- agentType: string;
319
- }
320
- /** Result from AgentOs.prompt(). */
321
- export interface PromptResult {
322
- /** Raw JSON-RPC response from the ACP adapter. */
323
- response: JsonRpcResponse;
324
- /** Accumulated agent text output from streamed message chunks. */
325
- text: string;
326
- }
327
443
  /** Information about a process spawned via AgentOs.spawn(). */
328
444
  export interface SpawnedProcessInfo {
329
445
  pid: number;
@@ -335,10 +451,8 @@ export interface SpawnedProcessInfo {
335
451
  export declare class AgentOs {
336
452
  #private;
337
453
  readonly sidecar: AgentOsSidecar;
338
- private _sessions;
339
- private _closedSessionIds;
340
- private _sessionClosePromises;
341
- private _pendingSessionRequestResolvers;
454
+ private _durableSessionEventHandlers;
455
+ private _agentExitHandlers;
342
456
  private _processes;
343
457
  private _shells;
344
458
  private _closedShellIds;
@@ -347,10 +461,9 @@ export declare class AgentOs {
347
461
  private _acpTerminals;
348
462
  private _acpTerminalCounter;
349
463
  private _softwareRoots;
350
- private _softwareAgentConfigs;
351
464
  private _cronManager;
352
- private _toolKits;
353
- private _toolReference;
465
+ private _bindings;
466
+ private _bindingReference;
354
467
  private _permissions;
355
468
  private _hostMounts;
356
469
  private _env;
@@ -360,6 +473,9 @@ export declare class AgentOs {
360
473
  private readonly _sidecarSession;
361
474
  private readonly _sidecarVm;
362
475
  private readonly _disposeSidecarEventListener;
476
+ private readonly _agentStderrHandler?;
477
+ private readonly _agentExitHandler?;
478
+ private readonly _limitWarningHandler?;
363
479
  private constructor();
364
480
  static createSidecar(options?: AgentOsCreateSidecarOptions): Promise<AgentOsSidecar>;
365
481
  static getSharedSidecar(options?: AgentOsSharedSidecarOptions): Promise<AgentOsSidecar>;
@@ -367,25 +483,22 @@ export declare class AgentOs {
367
483
  exec(command: string, options?: KernelExecOptions): Promise<KernelExecResult>;
368
484
  execArgv(command: string, args?: readonly string[], options?: KernelExecOptions): Promise<KernelExecResult>;
369
485
  private _trackProcess;
370
- spawn(command: string, args: string[], options?: KernelSpawnOptions): {
486
+ spawn(command: string, args: string[], options?: SpawnOptions): {
371
487
  pid: number;
372
488
  };
373
489
  /** Write data to a process's stdin. */
374
- writeProcessStdin(pid: number, data: string | Uint8Array): void;
490
+ writeProcessStdin(pid: number, data: string | Uint8Array): Promise<void>;
375
491
  /** Close a process's stdin stream. */
376
- closeProcessStdin(pid: number): void;
377
- /** Subscribe to stdout data from a process. Returns an unsubscribe function. */
378
- onProcessStdout(pid: number, handler: (data: Uint8Array) => void): () => void;
379
- /** Subscribe to stderr data from a process. Returns an unsubscribe function. */
380
- onProcessStderr(pid: number, handler: (data: Uint8Array) => void): () => void;
492
+ closeProcessStdin(pid: number): Promise<void>;
493
+ /** Subscribe to stdout and stderr from a process. */
494
+ onProcessOutput(pid: number, handler: (event: ProcessOutput) => void): () => void;
381
495
  /** Subscribe to process exit. Returns an unsubscribe function. */
382
- onProcessExit(pid: number, handler: (exitCode: number) => void): () => void;
496
+ onProcessExit(pid: number, handler: (event: ProcessExit) => void): () => void;
383
497
  /** Wait for a process to exit. Returns the exit code. */
384
498
  waitProcess(pid: number): Promise<number>;
385
499
  private _assertSafeAbsolutePath;
386
500
  private _assertWritableAbsolutePath;
387
501
  private _vfs;
388
- private _copyPath;
389
502
  readFile(path: string): Promise<Uint8Array>;
390
503
  writeFile(path: string, content: string | Uint8Array): Promise<void>;
391
504
  writeFiles(entries: BatchWriteEntry[]): Promise<BatchWriteResult[]>;
@@ -396,29 +509,49 @@ export declare class AgentOs {
396
509
  recursive?: boolean;
397
510
  }): Promise<void>;
398
511
  readdir(path: string): Promise<string[]>;
512
+ readdirEntries(path: string): Promise<ReaddirEntry[]>;
399
513
  readdirRecursive(path: string, options?: ReaddirRecursiveOptions): Promise<DirEntry[]>;
400
514
  stat(path: string): Promise<VirtualStat>;
401
515
  exists(path: string): Promise<boolean>;
402
- snapshotRootFilesystem(): Promise<RootSnapshotExport>;
403
- mountFs(path: string, driver: VirtualFileSystem, options?: {
404
- readOnly?: boolean;
405
- }): void;
406
- unmountFs(path: string): void;
516
+ exportRootFilesystem(options: ExportRootFilesystemOptions): Promise<RootSnapshotExport>;
517
+ /**
518
+ * Mount a filesystem into the running VM. Resolves once the mount has been
519
+ * delivered to the native sidecar, so guest code can use it immediately
520
+ * after the returned promise settles; a delivery failure rejects instead of
521
+ * leaving the mount silently host-only.
522
+ */
523
+ mountFs(descriptor: DynamicMountDescriptor): Promise<void>;
524
+ unmountFs(path: string): Promise<void>;
525
+ listMounts(): Promise<MountInfo[]>;
407
526
  move(from: string, to: string): Promise<void>;
408
- delete(path: string, options?: {
527
+ remove(path: string, options?: {
409
528
  recursive?: boolean;
410
529
  }): Promise<void>;
411
- fetch(port: number, request: Request): Promise<Response>;
412
- openShell(options?: OpenShellOptions): {
530
+ httpRequest(request: HttpRequest): Promise<HttpResponse>;
531
+ openShell(options?: ShellOptions): {
413
532
  shellId: string;
414
533
  };
415
534
  connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
416
535
  /** Write data to a shell's PTY input. */
417
- writeShell(shellId: string, data: string | Uint8Array): void;
418
- /** Subscribe to data output from a shell. Returns an unsubscribe function. */
419
- onShellData(shellId: string, handler: (data: Uint8Array) => void): () => void;
536
+ writeShell(shellId: string, data: string | Uint8Array): Promise<void>;
537
+ /**
538
+ * Subscribe to ordered PTY output (stdout and stderr). Returns an unsubscribe
539
+ * function. `OpenShellOptions.onStderr` is a diagnostic tap for callers that
540
+ * need channel identity; do not render both surfaces.
541
+ */
542
+ onShellData(shellId: string, handler: (event: ShellData) => void): () => void;
543
+ /** Subscribe to the stderr-only diagnostic stream for a shell. */
544
+ onShellStderr(shellId: string, handler: (event: ShellData) => void): () => void;
545
+ /** Subscribe to shell exit. */
546
+ onShellExit(shellId: string, handler: (event: ShellExit) => void): () => void;
420
547
  /** Notify a shell of terminal resize. */
421
548
  resizeShell(shellId: string, cols: number, rows: number): void;
549
+ /**
550
+ * Wait for a shell to exit and return its process exit code. Resolves
551
+ * immediately for a shell that has already exited (within the closed-shell
552
+ * retention window).
553
+ */
554
+ waitShell(shellId: string): Promise<number>;
422
555
  /** Kill a shell process and remove it from tracking. */
423
556
  closeShell(shellId: string): void;
424
557
  private _resolveVmPathToHostPath;
@@ -434,73 +567,50 @@ export declare class AgentOs {
434
567
  stopProcess(pid: number): void;
435
568
  /** Send SIGKILL to force-kill a process. No-op if already exited. */
436
569
  killProcess(pid: number): void;
437
- /** Returns all active sessions with their IDs and agent types. */
438
- listSessions(): SessionInfo[];
439
- /** Internal helper: retrieve a session or throw. */
440
- private _requireSession;
441
- /** Returns all registered agents with their installation status. */
442
- listAgents(): AgentRegistryEntry[];
443
- private _syncSessionState;
444
- private _applySessionUpdate;
445
- private _recordSessionNotification;
446
- private _dispatchSessionEvent;
447
- private _subscribeSessionEvents;
448
- private _applySyntheticConfigOverrides;
449
- private _handleSidecarEvent;
450
- private _handleAcpExtEvent;
451
- private _unsupportedConfigResponse;
452
- private _sendAcpRequest;
453
- private _sendSessionRequest;
454
- private _setSessionConfigByCategory;
455
- private _removeSession;
456
- private _abortPendingSessionRequests;
457
- private _cancelPendingPromptRequests;
458
- private _rejectPendingPermissionReplies;
459
- private _rejectPendingPermissionRepliesFromSession;
460
- private _closeSessionInternal;
461
- private _hydrateSessionState;
462
- createSession(agentType: AgentType | string, options?: CreateSessionOptions): Promise<{
463
- sessionId: string;
464
- }>;
465
- /**
466
- * Resume a session that exists in durable storage but is not live in this VM
467
- * (e.g. after a Rivet actor slept and woke with a fresh VM). Thin forwarder:
468
- * resolves the agent config + adapter entrypoint exactly as {@link createSession}
469
- * does, then forwards a single `AcpResumeSessionRequest` to the sidecar, which
470
- * owns the resume state machine (native `session/load` when the agent supports
471
- * it, else `session/new` + a transcript-continuation preamble). The returned
472
- * `sessionId` is the live id in this VM (equal to the requested id for native
473
- * loads, freshly assigned for the fallback); the caller remaps `external -> live`.
474
- * The new live session is registered + hydrated locally so subsequent prompts
475
- * route to it.
476
- *
477
- * Resume depends on a durable root; on a non-durable (default in-memory) root
478
- * there is no surviving store and the fallback tier always runs.
479
- */
480
- resumeSession(sessionId: string, agentType: AgentType | string, options?: ResumeSessionOptions): Promise<ResumeSessionResult>;
570
+ openSession(input: OpenSessionInput): Promise<void>;
571
+ getSession(input?: SessionTarget): Promise<DurableSessionInfo>;
572
+ listSessions(input?: ListSessionsInput): Promise<SessionPage>;
573
+ deleteSession(input?: SessionTarget): Promise<void>;
574
+ unloadSession(input?: SessionTarget): Promise<void>;
575
+ prompt(input: PromptInput): Promise<DurablePromptResult>;
576
+ cancelPrompt(input?: SessionTarget): Promise<CancelPromptResult>;
577
+ respondPermission(input: PermissionResponse): Promise<PermissionResponseResult>;
578
+ readHistory(input?: ReadHistoryInput): Promise<HistoryPage>;
579
+ getSessionConfig(input?: SessionTarget): Promise<SessionConfig>;
580
+ setSessionConfigOption(input: SetSessionConfigOptionInput): Promise<SessionConfig>;
581
+ getSessionCapabilities(input?: SessionTarget): Promise<SessionCapabilities | null>;
582
+ getSessionAgentInfo(input?: SessionTarget): Promise<SessionAgentInfo | null>;
481
583
  /**
482
- * Resolve the VM bin entry point of an ACP adapter package.
483
- * Reads from the host filesystem since kernel.readFile() resolves through
484
- * mounts; adapter package.json is read directly off the host dir backing
485
- * the relevant mount.
584
+ * Dynamically link a software package into the RUNNING VM. The package's
585
+ * `bin/` commands appear under `/opt/agentos/bin` (on `$PATH`) and its `share/man`
586
+ * pages under MANPATH immediately — the `/opt/agentos` mount is host-backed, so
587
+ * writing into its staging dir is reflected live with no reboot. An `agent`
588
+ * block registers the package for `openSession({ agent: name })`. Persists for the VM's
589
+ * lifetime (and across a snapshot iff the volume persists).
486
590
  */
487
- private _resolveAdapterBin;
591
+ linkSoftware(descriptor: PackageDescriptor): Promise<void>;
592
+ listSoftware(): Promise<{
593
+ packageName: string;
594
+ commands: string[];
595
+ }[]>;
488
596
  /**
489
- * Parent of the host directory backing the `/root/node_modules` mount, if
490
- * the caller supplied one (e.g. via `nodeModulesMount(...)`). Used as the
491
- * `resolvePackageDir` start dir for adapter/agent package resolution when no
492
- * software root matches. `nodeModulesMount` mounts `<dir>/node_modules`, so
493
- * the start dir is `<dir>` (one level above the node_modules tree).
597
+ * Returns all registered agents with their installation status. Thin forwarder:
598
+ * sends `AcpListAgentsRequest` and maps the response. The sidecar enumerates the
599
+ * projected `/opt/agentos` packages (the client parses no manifests). Every such
600
+ * agent is a package materialized into the VM, so `installed` is always `true`.
494
601
  */
495
- private _nodeModulesHostRoot;
496
- private _resolvePackageBin;
602
+ listAgents(): Promise<AgentRegistryEntry[]>;
603
+ private _recordAgentStderr;
604
+ private _recordAgentExit;
605
+ private _handleSidecarEvent;
606
+ private _handleLimitWarning;
607
+ private _handleAcpExtEvent;
608
+ private _emitDurableSessionEvent;
609
+ private _sendAcpRequest;
497
610
  private _installSidecarRequestHandler;
498
611
  private _handleAcpExtSidecarRequest;
499
612
  private _dispatchAcpSidecarRequest;
500
613
  private _handleSupportedAcpSidecarRequest;
501
- private _normalizeAcpPermissionOptionId;
502
- private _buildAcpPermissionResult;
503
- private _handleAcpPermissionRequest;
504
614
  private _acpParams;
505
615
  private _requireAcpStringParam;
506
616
  private _optionalAcpStringParam;
@@ -519,34 +629,11 @@ export declare class AgentOs {
519
629
  private _handleAcpKillTerminal;
520
630
  private _handleAcpReleaseTerminal;
521
631
  private _handleAcpResizeTerminal;
522
- private _handleAcpPermissionCallback;
523
- /**
524
- * Resolve an agent config by ID. Package-provided configs take
525
- * precedence over the hardcoded AGENT_CONFIGS.
526
- */
527
- private _resolveAgentConfig;
528
- /**
529
- * Gracefully destroy a session: cancel any pending work, close the client,
530
- * and remove from tracking. Unlike close() which is abrupt, this attempts
531
- * a graceful shutdown sequence.
532
- */
533
- destroySession(sessionId: string): Promise<void>;
534
- prompt(sessionId: string, text: string): Promise<PromptResult>;
535
- /** Cancel ongoing agent work for a session. */
536
- cancelSession(sessionId: string): Promise<JsonRpcResponse>;
537
- closeSession(sessionId: string): void;
538
- respondPermission(sessionId: string, permissionId: string, reply: PermissionReply): Promise<JsonRpcResponse>;
539
- setSessionMode(sessionId: string, modeId: string): Promise<JsonRpcResponse>;
540
- getSessionModes(sessionId: string): SessionModeState | null;
541
- setSessionModel(sessionId: string, model: string): Promise<JsonRpcResponse>;
542
- setSessionThoughtLevel(sessionId: string, level: string): Promise<JsonRpcResponse>;
543
- getSessionConfigOptions(sessionId: string): SessionConfigOption[];
544
- getSessionCapabilities(sessionId: string): AgentCapabilities | null;
545
- getSessionAgentInfo(sessionId: string): AgentInfo | null;
546
- rawSessionSend(sessionId: string, method: string, params?: Record<string, unknown>): Promise<JsonRpcResponse>;
547
- rawSend(sessionId: string, method: string, params?: Record<string, unknown>): Promise<JsonRpcResponse>;
548
- onSessionEvent(sessionId: string, handler: SessionEventHandler): () => void;
549
- onPermissionRequest(sessionId: string, handler: PermissionRequestHandler): () => void;
632
+ onSessionEvent(handler: (entry: SessionStreamEntry) => void): () => void;
633
+ onSessionEvent(sessionId: string | undefined, handler: (entry: SessionStreamEntry) => void): () => void;
634
+ /** Subscribe to unexpected adapter exits without changing session liveness. */
635
+ onAgentExit(handler: AgentExitHandler): () => void;
636
+ onAgentExit(sessionId: string | undefined, handler: AgentExitHandler): () => void;
550
637
  /** Schedule a cron job. Returns a handle with the job ID and a cancel method. */
551
638
  scheduleCron(options: CronJobOptions): CronJob;
552
639
  /** List all registered cron jobs. */