@rivet-dev/agentos-core 0.0.0-nathan-agentos-combined.e833bb7 → 0.0.0-provided-commands.1847f3b

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 CHANGED
@@ -112,7 +112,7 @@ await vm.dispose();
112
112
 
113
113
  | Method | Signature | Description |
114
114
  |--------|-----------|-------------|
115
- | `createSession` | `createSession(agentType: AgentType \| string, options?: CreateSessionOptions): Promise<{ sessionId: string }>` | Launch an agent and return a session ID |
115
+ | `createSession` | `createSession(agentType: AgentType, options?: CreateSessionOptions): Promise<{ sessionId: string }>` | Launch an agent and return a session ID |
116
116
  | `listSessions` | `listSessions(): SessionInfo[]` | List active sessions |
117
117
  | `destroySession` | `destroySession(sessionId: string): Promise<void>` | Gracefully cancel and close a session |
118
118
 
@@ -157,10 +157,7 @@ await vm.dispose();
157
157
  - `MountConfigCustom` — Caller-provided VirtualFileSystem
158
158
  - `NativeMountConfig` — Declarative sidecar mount plugin configuration
159
159
  - `MountConfigOverlay` — Copy-on-write overlay (lower + upper layers)
160
-
161
- **Companion Filesystem Packages**
162
- - `createGoogleDriveBackend()` — Declarative Google Drive native mount helper from `@secure-exec/google-drive`
163
- - `createS3Backend()` — Declarative S3-compatible native mount helper from `@secure-exec/s3`
160
+ - `chunkedS3MountPlugin()` — Declarative S3-compatible native mount plugin descriptor (from `@secure-exec/core/descriptors`)
164
161
 
165
162
  **MCP Servers**
166
163
  - `McpServerConfig` — Union of local and remote MCP configs
@@ -180,8 +177,8 @@ await vm.dispose();
180
177
  - `BatchReadResult` — Result of a batch read (path, content, error?)
181
178
 
182
179
  **Agent**
183
- - `AgentType` — `"pi" | "pi-cli" | "opencode" | "claude"`
184
- - `AgentConfig` — Agent configuration (acpAdapter, agentPackage, prepareInstructions)
180
+ - `AgentType` — `string` (a package manifest `name`, e.g. `"pi"`, `"claude"`); agents are resolved dynamically from the configured `/opt/agentos` package manifests, so any manifest `name` is valid
181
+ - `AgentConfig` — Agent configuration (adapterEntrypoint, launchArgs, defaultEnv)
185
182
  - `AgentRegistryEntry` — Registry entry (id, acpAdapter, agentPackage, installed)
186
183
 
187
184
  **Session**
@@ -46,15 +46,14 @@ export interface BatchReadResult {
46
46
  /** Entry in the agent registry, describing an available agent type. */
47
47
  export interface AgentRegistryEntry {
48
48
  id: string;
49
- acpAdapter: string;
50
- agentPackage: string;
51
49
  installed: boolean;
52
50
  }
53
- import { type AgentType } from "./agents.js";
51
+ import type { AgentType } from "./types.js";
54
52
  import type { ScheduleDriver } from "./cron/schedule-driver.js";
55
53
  import type { CronEventHandler, CronJob, CronJobInfo, CronJobOptions } from "./cron/types.js";
56
54
  import { type LayerStore, type OverlayFilesystemMode, type RootSnapshotExport, type SnapshotLayerHandle } from "./layers.js";
57
55
  import { type SoftwareInput } from "./packages.js";
56
+ import { type PackageRef, type SoftwarePackageRef } from "./agentos-package.js";
58
57
  import { type AgentOsSidecarPlacement } from "./sidecar/rpc-client.js";
59
58
  export interface AgentOsSharedSidecarOptions {
60
59
  pool?: string;
@@ -172,6 +171,10 @@ export interface AgentOsLimits {
172
171
  /** Guest JavaScript runtime buffering limits. */
173
172
  jsRuntime?: {
174
173
  v8HeapLimitMb?: number;
174
+ syncRpcWaitTimeoutMs?: number;
175
+ cpuTimeLimitMs?: number;
176
+ wallClockLimitMs?: number;
177
+ importCacheMaterializeTimeoutMs?: number;
175
178
  capturedOutputLimitBytes?: number;
176
179
  stdinBufferLimitBytes?: number;
177
180
  eventPayloadLimitBytes?: number;
@@ -181,6 +184,7 @@ export interface AgentOsLimits {
181
184
  python?: {
182
185
  outputBufferMaxBytes?: number;
183
186
  executionTimeoutMs?: number;
187
+ maxOldSpaceMb?: number;
184
188
  vfsRpcTimeoutMs?: number;
185
189
  };
186
190
  /** Guest WASM runtime limits. */
@@ -188,6 +192,8 @@ export interface AgentOsLimits {
188
192
  maxModuleFileBytes?: number;
189
193
  capturedOutputLimitBytes?: number;
190
194
  syncReadLimitBytes?: number;
195
+ prewarmTimeoutMs?: number;
196
+ runnerHeapLimitMb?: number;
191
197
  };
192
198
  }
193
199
  export interface AgentStderrEvent {
@@ -198,6 +204,57 @@ export interface AgentStderrEvent {
198
204
  chunk: Uint8Array;
199
205
  }
200
206
  export type AgentStderrHandler = (event: AgentStderrEvent) => void;
207
+ /**
208
+ * Auto-restart outcome reported on an {@link AgentExitEvent}. Mirrors the
209
+ * sidecar's `AcpAgentExitedEvent.restart` strings:
210
+ * - `"restarted"` — the adapter was respawned and the session was natively
211
+ * re-attached under the same session id; the session stays usable.
212
+ * - `"unsupported"` — the adapter does not advertise a native resume
213
+ * capability (`loadSession`/`resume`); the session was evicted.
214
+ * - `"failed"` — the respawn or re-attach errored; the session was evicted.
215
+ * - `"exhausted"` — the per-session restart budget was already spent; evicted.
216
+ */
217
+ export type AgentRestartOutcome = "restarted" | "unsupported" | "failed" | "exhausted";
218
+ /**
219
+ * An unexpected ACP adapter process exit — a crash from the host's
220
+ * perspective (any spontaneous exit without `closeSession()`, including exit
221
+ * code 0) — plus the sidecar's bounded auto-restart outcome.
222
+ */
223
+ export interface AgentExitEvent {
224
+ sessionId: string;
225
+ agentType: string;
226
+ /** Sidecar process id of the adapter that exited. */
227
+ processId: string;
228
+ pid: number | null;
229
+ /** Adapter exit code; `null` when the exit was observed indirectly. */
230
+ exitCode: number | null;
231
+ /** Auto-restart outcome; only `"restarted"` leaves the session usable. */
232
+ restart: AgentRestartOutcome;
233
+ /** Restarts consumed for this session so far. */
234
+ restartCount: number;
235
+ /** Per-session restart budget. */
236
+ maxRestarts: number;
237
+ }
238
+ export type AgentExitHandler = (event: AgentExitEvent) => void;
239
+ /**
240
+ * A near-capacity warning for one bounded limit (a queue/buffer, a saturating
241
+ * resource cap, or a memory envelope) inside the VM runtime. Delivered the moment
242
+ * usage crosses the runtime's warning threshold (~80%), once per crossing — the
243
+ * runtime applies edge-triggering + hysteresis, so this never spams.
244
+ */
245
+ export interface LimitWarning {
246
+ /** Stable limit name, e.g. `"javascript_event_channel"` or `"vm_open_fds"`. */
247
+ limit: string;
248
+ /** Limit class: `"queue"`, `"resource"`, or `"memory"`. */
249
+ category: string;
250
+ /** Current observed usage. */
251
+ observed: number;
252
+ /** Configured capacity. */
253
+ capacity: number;
254
+ /** Observed fill as a percentage of capacity (0–100). */
255
+ fillPercent: number;
256
+ }
257
+ export type LimitWarningHandler = (warning: LimitWarning) => void;
201
258
  /**
202
259
  * Public core VM options.
203
260
  *
@@ -208,11 +265,8 @@ export type AgentStderrHandler = (event: AgentStderrEvent) => void;
208
265
  */
209
266
  export interface AgentOsOptions {
210
267
  /**
211
- * Software to install in the VM. Each entry provides agents, tools,
212
- * or WASM commands. Any object with a `commandDir` property (e.g.,
213
- * registry packages like @agentos-software/coreutils) is treated
214
- * as a WASM command source automatically. Arrays are flattened, so
215
- * meta-packages that export arrays of sub-packages work directly.
268
+ * Software to install in the VM. Each entry is a package-dir ref. Arrays are
269
+ * flattened, so meta-packages that export arrays of sub-packages work directly.
216
270
  */
217
271
  software?: SoftwareInput[];
218
272
  /**
@@ -230,15 +284,18 @@ export interface AgentOsOptions {
230
284
  * Defaults to the hardened builtin set used by the native sidecar bridge.
231
285
  */
232
286
  allowedNodeBuiltins?: string[];
287
+ /**
288
+ * Opt in to a high-resolution monotonic guest clock (microsecond class)
289
+ * for guest Node processes. Default `false` keeps the security-oriented
290
+ * 1ms timer resolution — untrusted guest code should not get a precise
291
+ * timer (timing side channels). Enable only for trusted benchmarking or
292
+ * profiling workloads.
293
+ */
294
+ highResolutionTime?: boolean;
233
295
  /** Root filesystem configuration. Defaults to an overlay with the bundled base snapshot as its deepest lower. */
234
296
  rootFilesystem?: RootFilesystemConfig;
235
297
  /** Filesystems to mount at boot time. */
236
298
  mounts?: MountConfig[];
237
- /**
238
- * @deprecated Use `mounts: [nodeModulesMount(path)]` instead.
239
- * Compatibility alias for mounting `<moduleAccessCwd>/node_modules` at `/root/node_modules`.
240
- */
241
- moduleAccessCwd?: string;
242
299
  /** Additional instructions appended to the base OS system prompt injected at session start. */
243
300
  additionalInstructions?: string;
244
301
  /** Custom schedule driver for cron jobs. Defaults to TimerScheduleDriver. */
@@ -267,6 +324,21 @@ export interface AgentOsOptions {
267
324
  * `process.stderr`.
268
325
  */
269
326
  onAgentStderr?: AgentStderrHandler;
327
+ /**
328
+ * Called when the ACP adapter process behind a session exits without
329
+ * `closeSession()` — i.e. an adapter crash. The sidecar auto-restarts the
330
+ * adapter (bounded per session, natively re-attaching the same session id)
331
+ * and reports the outcome on the event; only `restart === "restarted"`
332
+ * leaves the session usable. Defaults to writing a warning line to
333
+ * `process.stderr`.
334
+ */
335
+ onAgentExit?: AgentExitHandler;
336
+ /**
337
+ * Called when a bounded limit inside the VM runtime approaches capacity
338
+ * (~80%, edge-triggered with hysteresis so it does not spam). Use it to alert
339
+ * on a slow consumer or a runaway guest before the limit is actually hit.
340
+ */
341
+ onLimitWarning?: LimitWarningHandler;
270
342
  }
271
343
  /** Configuration for a local MCP server (spawned as a child process). */
272
344
  export interface McpServerConfigLocal {
@@ -370,7 +442,6 @@ export declare class AgentOs {
370
442
  private _acpTerminals;
371
443
  private _acpTerminalCounter;
372
444
  private _softwareRoots;
373
- private _softwareAgentConfigs;
374
445
  private _cronManager;
375
446
  private _toolKits;
376
447
  private _toolReference;
@@ -378,12 +449,15 @@ export declare class AgentOs {
378
449
  private _hostMounts;
379
450
  private _env;
380
451
  private _rootFilesystem;
452
+ private readonly _additionalInstructions;
381
453
  private _sidecarLease;
382
454
  private readonly _sidecarClient;
383
455
  private readonly _sidecarSession;
384
456
  private readonly _sidecarVm;
385
457
  private readonly _disposeSidecarEventListener;
386
458
  private readonly _agentStderrHandler?;
459
+ private readonly _agentExitHandler?;
460
+ private readonly _limitWarningHandler?;
387
461
  private constructor();
388
462
  static createSidecar(options?: AgentOsCreateSidecarOptions): Promise<AgentOsSidecar>;
389
463
  static getSharedSidecar(options?: AgentOsSharedSidecarOptions): Promise<AgentOsSidecar>;
@@ -395,9 +469,9 @@ export declare class AgentOs {
395
469
  pid: number;
396
470
  };
397
471
  /** Write data to a process's stdin. */
398
- writeProcessStdin(pid: number, data: string | Uint8Array): void;
472
+ writeProcessStdin(pid: number, data: string | Uint8Array): Promise<void>;
399
473
  /** Close a process's stdin stream. */
400
- closeProcessStdin(pid: number): void;
474
+ closeProcessStdin(pid: number): Promise<void>;
401
475
  /** Subscribe to stdout data from a process. Returns an unsubscribe function. */
402
476
  onProcessStdout(pid: number, handler: (data: Uint8Array) => void): () => void;
403
477
  /** Subscribe to stderr data from a process. Returns an unsubscribe function. */
@@ -409,7 +483,6 @@ export declare class AgentOs {
409
483
  private _assertSafeAbsolutePath;
410
484
  private _assertWritableAbsolutePath;
411
485
  private _vfs;
412
- private _copyPath;
413
486
  readFile(path: string): Promise<Uint8Array>;
414
487
  writeFile(path: string, content: string | Uint8Array): Promise<void>;
415
488
  writeFiles(entries: BatchWriteEntry[]): Promise<BatchWriteResult[]>;
@@ -438,11 +511,17 @@ export declare class AgentOs {
438
511
  };
439
512
  connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
440
513
  /** Write data to a shell's PTY input. */
441
- writeShell(shellId: string, data: string | Uint8Array): void;
514
+ writeShell(shellId: string, data: string | Uint8Array): Promise<void>;
442
515
  /** Subscribe to data output from a shell. Returns an unsubscribe function. */
443
516
  onShellData(shellId: string, handler: (data: Uint8Array) => void): () => void;
444
517
  /** Notify a shell of terminal resize. */
445
518
  resizeShell(shellId: string, cols: number, rows: number): void;
519
+ /**
520
+ * Wait for a shell to exit and return its process exit code. Resolves
521
+ * immediately for a shell that has already exited (within the closed-shell
522
+ * retention window).
523
+ */
524
+ waitShell(shellId: string): Promise<number>;
446
525
  /** Kill a shell process and remove it from tracking. */
447
526
  closeShell(shellId: string): void;
448
527
  private _resolveVmPathToHostPath;
@@ -462,16 +541,53 @@ export declare class AgentOs {
462
541
  listSessions(): SessionInfo[];
463
542
  /** Internal helper: retrieve a session or throw. */
464
543
  private _requireSession;
465
- /** Returns all registered agents with their installation status. */
466
- listAgents(): AgentRegistryEntry[];
544
+ /**
545
+ * Dynamically link a software package into the RUNNING VM. The package's
546
+ * `bin/` commands appear under `/opt/agentos/bin` (on `$PATH`) and its `share/man`
547
+ * pages under MANPATH immediately — the `/opt/agentos` mount is host-backed, so
548
+ * writing into its staging dir is reflected live with no reboot. An `agent`
549
+ * block registers the package for `createSession(name)`. Persists for the VM's
550
+ * lifetime (and across a snapshot iff the volume persists).
551
+ */
552
+ linkSoftware(descriptor: PackageRef | SoftwarePackageRef): Promise<void>;
553
+ providedCommands(): Promise<{
554
+ packageName: string;
555
+ commands: string[];
556
+ }[]>;
557
+ /**
558
+ * Returns all registered agents with their installation status. Thin forwarder:
559
+ * sends `AcpListAgentsRequest` and maps the response. The sidecar enumerates the
560
+ * projected `/opt/agentos` packages (the client parses no manifests). Every such
561
+ * agent is a package materialized into the VM, so `installed` is always `true`.
562
+ */
563
+ listAgents(): Promise<AgentRegistryEntry[]>;
467
564
  private _syncSessionState;
468
565
  private _applySessionUpdate;
469
566
  private _recordSessionNotification;
470
567
  private _dispatchSessionEvent;
471
568
  private _subscribeSessionEvents;
569
+ /**
570
+ * Warn once per session (host-visible) that a tool-permission request was
571
+ * auto-denied because no `onPermissionRequest` handler is registered. Shared
572
+ * by both the bare-callback and JSON-RPC permission paths so the message and
573
+ * the once-per-session guard cannot drift between them.
574
+ */
575
+ private _warnNoPermissionHandlerOnce;
576
+ /** Best-effort human label for the tool named in a permission request. */
577
+ private _permissionToolLabel;
578
+ /**
579
+ * Emit a host-visible warning for a session through the same agent-process log
580
+ * channel that surfaces adapter stderr (`onAgentStderr`, default: process
581
+ * stderr). Used for agent-os-owned diagnostics — e.g. a permission request
582
+ * that was auto-denied because no host hook is registered — so they never fire
583
+ * silently inside the sidecar.
584
+ */
585
+ private _emitSessionWarning;
472
586
  private _recordAgentStderr;
587
+ private _recordAgentExit;
473
588
  private _applySyntheticConfigOverrides;
474
589
  private _handleSidecarEvent;
590
+ private _handleLimitWarning;
475
591
  private _handleAcpExtEvent;
476
592
  private _unsupportedConfigResponse;
477
593
  private _sendAcpRequest;
@@ -484,7 +600,7 @@ export declare class AgentOs {
484
600
  private _rejectPendingPermissionRepliesFromSession;
485
601
  private _closeSessionInternal;
486
602
  private _hydrateSessionState;
487
- createSession(agentType: AgentType | string, options?: CreateSessionOptions): Promise<{
603
+ createSession(agentType: AgentType, options?: CreateSessionOptions): Promise<{
488
604
  sessionId: string;
489
605
  }>;
490
606
  /**
@@ -502,23 +618,7 @@ export declare class AgentOs {
502
618
  * Resume depends on a durable root; on a non-durable (default in-memory) root
503
619
  * there is no surviving store and the fallback tier always runs.
504
620
  */
505
- resumeSession(sessionId: string, agentType: AgentType | string, options?: ResumeSessionOptions): Promise<ResumeSessionResult>;
506
- /**
507
- * Resolve the VM bin entry point of an ACP adapter package.
508
- * Reads from the host filesystem since kernel.readFile() resolves through
509
- * mounts; adapter package.json is read directly off the host dir backing
510
- * the relevant mount.
511
- */
512
- private _resolveAdapterBin;
513
- /**
514
- * Parent of the host directory backing the `/root/node_modules` mount, if
515
- * the caller supplied one (e.g. via `nodeModulesMount(...)`). Used as the
516
- * `resolvePackageDir` start dir for adapter/agent package resolution when no
517
- * software root matches. `nodeModulesMount` mounts `<dir>/node_modules`, so
518
- * the start dir is `<dir>` (one level above the node_modules tree).
519
- */
520
- private _nodeModulesHostRoot;
521
- private _resolvePackageBin;
621
+ resumeSession(sessionId: string, agentType: AgentType, options?: ResumeSessionOptions): Promise<ResumeSessionResult>;
522
622
  private _installSidecarRequestHandler;
523
623
  private _handleAcpExtSidecarRequest;
524
624
  private _dispatchAcpSidecarRequest;
@@ -545,11 +645,6 @@ export declare class AgentOs {
545
645
  private _handleAcpReleaseTerminal;
546
646
  private _handleAcpResizeTerminal;
547
647
  private _handleAcpPermissionCallback;
548
- /**
549
- * Resolve an agent config by ID. Package-provided configs take
550
- * precedence over the hardcoded AGENT_CONFIGS.
551
- */
552
- private _resolveAgentConfig;
553
648
  /**
554
649
  * Gracefully destroy a session: cancel any pending work, close the client,
555
650
  * and remove from tracking. Unlike close() which is abrupt, this attempts