@rivet-dev/agentos-core 0.2.4 → 0.2.5-rc.1

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
@@ -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
@@ -46,15 +46,20 @@ 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;
49
+ /** npm adapter package (legacy agents) — absent for `/opt/agentos` packages. */
50
+ acpAdapter?: string;
51
+ /** npm agent package (legacy agents) — absent for `/opt/agentos` packages. */
52
+ agentPackage?: string;
53
+ /** Pre-resolved adapter command path for an `/opt/agentos` agent package. */
54
+ adapterEntrypoint?: string;
51
55
  installed: boolean;
52
56
  }
53
- import { type AgentType } from "./agents.js";
57
+ import type { AgentType } from "./agents.js";
54
58
  import type { ScheduleDriver } from "./cron/schedule-driver.js";
55
59
  import type { CronEventHandler, CronJob, CronJobInfo, CronJobOptions } from "./cron/types.js";
56
60
  import { type LayerStore, type OverlayFilesystemMode, type RootSnapshotExport, type SnapshotLayerHandle } from "./layers.js";
57
61
  import { type SoftwareInput } from "./packages.js";
62
+ import { type PackageRef, type SoftwarePackageRef } from "./agentos-package.js";
58
63
  import { type AgentOsSidecarPlacement } from "./sidecar/rpc-client.js";
59
64
  export interface AgentOsSharedSidecarOptions {
60
65
  pool?: string;
@@ -198,6 +203,38 @@ export interface AgentStderrEvent {
198
203
  chunk: Uint8Array;
199
204
  }
200
205
  export type AgentStderrHandler = (event: AgentStderrEvent) => void;
206
+ /**
207
+ * Auto-restart outcome reported on an {@link AgentExitEvent}. Mirrors the
208
+ * sidecar's `AcpAgentExitedEvent.restart` strings:
209
+ * - `"restarted"` — the adapter was respawned and the session was natively
210
+ * re-attached under the same session id; the session stays usable.
211
+ * - `"unsupported"` — the adapter does not advertise a native resume
212
+ * capability (`loadSession`/`resume`); the session was evicted.
213
+ * - `"failed"` — the respawn or re-attach errored; the session was evicted.
214
+ * - `"exhausted"` — the per-session restart budget was already spent; evicted.
215
+ */
216
+ export type AgentRestartOutcome = "restarted" | "unsupported" | "failed" | "exhausted";
217
+ /**
218
+ * An unexpected ACP adapter process exit — a crash from the host's
219
+ * perspective (any spontaneous exit without `closeSession()`, including exit
220
+ * code 0) — plus the sidecar's bounded auto-restart outcome.
221
+ */
222
+ export interface AgentExitEvent {
223
+ sessionId: string;
224
+ agentType: string;
225
+ /** Sidecar process id of the adapter that exited. */
226
+ processId: string;
227
+ pid: number | null;
228
+ /** Adapter exit code; `null` when the exit was observed indirectly. */
229
+ exitCode: number | null;
230
+ /** Auto-restart outcome; only `"restarted"` leaves the session usable. */
231
+ restart: AgentRestartOutcome;
232
+ /** Restarts consumed for this session so far. */
233
+ restartCount: number;
234
+ /** Per-session restart budget. */
235
+ maxRestarts: number;
236
+ }
237
+ export type AgentExitHandler = (event: AgentExitEvent) => void;
201
238
  /**
202
239
  * A near-capacity warning for one bounded limit (a queue/buffer, a saturating
203
240
  * resource cap, or a memory envelope) inside the VM runtime. Delivered the moment
@@ -227,11 +264,8 @@ export type LimitWarningHandler = (warning: LimitWarning) => void;
227
264
  */
228
265
  export interface AgentOsOptions {
229
266
  /**
230
- * Software to install in the VM. Each entry provides agents, tools,
231
- * or WASM commands. Any object with a `commandDir` property (e.g.,
232
- * registry packages like @agentos-software/coreutils) is treated
233
- * as a WASM command source automatically. Arrays are flattened, so
234
- * meta-packages that export arrays of sub-packages work directly.
267
+ * Software to install in the VM. Each entry is a package-dir ref. Arrays are
268
+ * flattened, so meta-packages that export arrays of sub-packages work directly.
235
269
  */
236
270
  software?: SoftwareInput[];
237
271
  /**
@@ -249,6 +283,14 @@ export interface AgentOsOptions {
249
283
  * Defaults to the hardened builtin set used by the native sidecar bridge.
250
284
  */
251
285
  allowedNodeBuiltins?: string[];
286
+ /**
287
+ * Opt in to a high-resolution monotonic guest clock (microsecond class)
288
+ * for guest Node processes. Default `false` keeps the security-oriented
289
+ * 1ms timer resolution — untrusted guest code should not get a precise
290
+ * timer (timing side channels). Enable only for trusted benchmarking or
291
+ * profiling workloads.
292
+ */
293
+ highResolutionTime?: boolean;
252
294
  /** Root filesystem configuration. Defaults to an overlay with the bundled base snapshot as its deepest lower. */
253
295
  rootFilesystem?: RootFilesystemConfig;
254
296
  /** Filesystems to mount at boot time. */
@@ -286,6 +328,15 @@ export interface AgentOsOptions {
286
328
  * `process.stderr`.
287
329
  */
288
330
  onAgentStderr?: AgentStderrHandler;
331
+ /**
332
+ * Called when the ACP adapter process behind a session exits without
333
+ * `closeSession()` — i.e. an adapter crash. The sidecar auto-restarts the
334
+ * adapter (bounded per session, natively re-attaching the same session id)
335
+ * and reports the outcome on the event; only `restart === "restarted"`
336
+ * leaves the session usable. Defaults to writing a warning line to
337
+ * `process.stderr`.
338
+ */
339
+ onAgentExit?: AgentExitHandler;
289
340
  /**
290
341
  * Called when a bounded limit inside the VM runtime approaches capacity
291
342
  * (~80%, edge-triggered with hysteresis so it does not spam). Use it to alert
@@ -392,6 +443,8 @@ export declare class AgentOs {
392
443
  private _closedShellIds;
393
444
  private _pendingShellExitPromises;
394
445
  private _shellCounter;
446
+ /** Command names linked into `/opt/agentos/bin` at runtime (via the sidecar). */
447
+ private _linkedCommands;
395
448
  private _acpTerminals;
396
449
  private _acpTerminalCounter;
397
450
  private _softwareRoots;
@@ -410,6 +463,7 @@ export declare class AgentOs {
410
463
  private readonly _sidecarVm;
411
464
  private readonly _disposeSidecarEventListener;
412
465
  private readonly _agentStderrHandler?;
466
+ private readonly _agentExitHandler?;
413
467
  private readonly _limitWarningHandler?;
414
468
  private constructor();
415
469
  static createSidecar(options?: AgentOsCreateSidecarOptions): Promise<AgentOsSidecar>;
@@ -422,9 +476,9 @@ export declare class AgentOs {
422
476
  pid: number;
423
477
  };
424
478
  /** Write data to a process's stdin. */
425
- writeProcessStdin(pid: number, data: string | Uint8Array): void;
479
+ writeProcessStdin(pid: number, data: string | Uint8Array): Promise<void>;
426
480
  /** Close a process's stdin stream. */
427
- closeProcessStdin(pid: number): void;
481
+ closeProcessStdin(pid: number): Promise<void>;
428
482
  /** Subscribe to stdout data from a process. Returns an unsubscribe function. */
429
483
  onProcessStdout(pid: number, handler: (data: Uint8Array) => void): () => void;
430
484
  /** Subscribe to stderr data from a process. Returns an unsubscribe function. */
@@ -465,11 +519,17 @@ export declare class AgentOs {
465
519
  };
466
520
  connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
467
521
  /** Write data to a shell's PTY input. */
468
- writeShell(shellId: string, data: string | Uint8Array): void;
522
+ writeShell(shellId: string, data: string | Uint8Array): Promise<void>;
469
523
  /** Subscribe to data output from a shell. Returns an unsubscribe function. */
470
524
  onShellData(shellId: string, handler: (data: Uint8Array) => void): () => void;
471
525
  /** Notify a shell of terminal resize. */
472
526
  resizeShell(shellId: string, cols: number, rows: number): void;
527
+ /**
528
+ * Wait for a shell to exit and return its process exit code. Resolves
529
+ * immediately for a shell that has already exited (within the closed-shell
530
+ * retention window).
531
+ */
532
+ waitShell(shellId: string): Promise<number>;
473
533
  /** Kill a shell process and remove it from tracking. */
474
534
  closeShell(shellId: string): void;
475
535
  private _resolveVmPathToHostPath;
@@ -489,6 +549,15 @@ export declare class AgentOs {
489
549
  listSessions(): SessionInfo[];
490
550
  /** Internal helper: retrieve a session or throw. */
491
551
  private _requireSession;
552
+ /**
553
+ * Dynamically link a software package into the RUNNING VM. The package's
554
+ * `bin/` commands appear under `/opt/agentos/bin` (on `$PATH`) and its `share/man`
555
+ * pages under MANPATH immediately — the `/opt/agentos` mount is host-backed, so
556
+ * writing into its staging dir is reflected live with no reboot. An `agent`
557
+ * block registers the package for `createSession(name)`. Persists for the VM's
558
+ * lifetime (and across a snapshot iff the volume persists).
559
+ */
560
+ linkSoftware(descriptor: PackageRef | SoftwarePackageRef): Promise<void>;
492
561
  /** Returns all registered agents with their installation status. */
493
562
  listAgents(): AgentRegistryEntry[];
494
563
  private _syncSessionState;
@@ -496,7 +565,25 @@ export declare class AgentOs {
496
565
  private _recordSessionNotification;
497
566
  private _dispatchSessionEvent;
498
567
  private _subscribeSessionEvents;
568
+ /**
569
+ * Warn once per session (host-visible) that a tool-permission request was
570
+ * auto-denied because no `onPermissionRequest` handler is registered. Shared
571
+ * by both the bare-callback and JSON-RPC permission paths so the message and
572
+ * the once-per-session guard cannot drift between them.
573
+ */
574
+ private _warnNoPermissionHandlerOnce;
575
+ /** Best-effort human label for the tool named in a permission request. */
576
+ private _permissionToolLabel;
577
+ /**
578
+ * Emit a host-visible warning for a session through the same agent-process log
579
+ * channel that surfaces adapter stderr (`onAgentStderr`, default: process
580
+ * stderr). Used for agent-os-owned diagnostics — e.g. a permission request
581
+ * that was auto-denied because no host hook is registered — so they never fire
582
+ * silently inside the sidecar.
583
+ */
584
+ private _emitSessionWarning;
499
585
  private _recordAgentStderr;
586
+ private _recordAgentExit;
500
587
  private _applySyntheticConfigOverrides;
501
588
  private _handleSidecarEvent;
502
589
  private _handleLimitWarning;
@@ -531,22 +618,6 @@ export declare class AgentOs {
531
618
  * there is no surviving store and the fallback tier always runs.
532
619
  */
533
620
  resumeSession(sessionId: string, agentType: AgentType | string, options?: ResumeSessionOptions): Promise<ResumeSessionResult>;
534
- /**
535
- * Resolve the VM bin entry point of an ACP adapter package.
536
- * Reads from the host filesystem since kernel.readFile() resolves through
537
- * mounts; adapter package.json is read directly off the host dir backing
538
- * the relevant mount.
539
- */
540
- private _resolveAdapterBin;
541
- /**
542
- * Parent of the host directory backing the `/root/node_modules` mount, if
543
- * the caller supplied one (e.g. via `nodeModulesMount(...)`). Used as the
544
- * `resolvePackageDir` start dir for adapter/agent package resolution when no
545
- * software root matches. `nodeModulesMount` mounts `<dir>/node_modules`, so
546
- * the start dir is `<dir>` (one level above the node_modules tree).
547
- */
548
- private _nodeModulesHostRoot;
549
- private _resolvePackageBin;
550
621
  private _installSidecarRequestHandler;
551
622
  private _handleAcpExtSidecarRequest;
552
623
  private _dispatchAcpSidecarRequest;
@@ -574,8 +645,9 @@ export declare class AgentOs {
574
645
  private _handleAcpResizeTerminal;
575
646
  private _handleAcpPermissionCallback;
576
647
  /**
577
- * Resolve an agent config by ID. Package-provided configs take
578
- * precedence over the hardcoded AGENT_CONFIGS.
648
+ * Resolve an agent config by ID. Agents are /opt/agentos packages
649
+ * registered from their manifests (explicit software at create, or lazily
650
+ * linked dependency agents) — there is no hardcoded fallback config.
579
651
  */
580
652
  private _resolveAgentConfig;
581
653
  /**