@rivet-dev/agentos-core 0.2.14 → 0.2.15

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.
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A package is a self-contained directory produced by `@rivet-dev/agentos-toolchain
5
5
  * pack`. The HOST no longer projects it: the client forwards only the package
6
- * directory over the wire and the secure-exec sidecar owns the `/opt/agentos`
6
+ * directory over the wire and the agentos sidecar owns the `/opt/agentos`
7
7
  * projection. Package metadata lives in `<dir>/agentos-package.json`.
8
8
  *
9
9
  * This module is therefore only the client-facing package-dir surface plus the
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A package is a self-contained directory produced by `@rivet-dev/agentos-toolchain
5
5
  * pack`. The HOST no longer projects it: the client forwards only the package
6
- * directory over the wire and the secure-exec sidecar owns the `/opt/agentos`
6
+ * directory over the wire and the agentos sidecar owns the `/opt/agentos`
7
7
  * projection. Package metadata lives in `<dir>/agentos-package.json`.
8
8
  *
9
9
  * This module is therefore only the client-facing package-dir surface plus the
@@ -2,13 +2,13 @@
2
2
  * The base VM environment, baked in as a constant (verbatim from the single
3
3
  * `base-filesystem.json` the sidecar embeds). The host no longer reads that JSON
4
4
  * — the sidecar owns the base filesystem, and there is exactly one committed copy
5
- * of it (`secure-exec/crates/vfs/assets/base-filesystem.json`). Regenerate both
5
+ * of it (`agentos/crates/vfs/assets/base-filesystem.json`). Regenerate both
6
6
  * this constant and that file together with the build-tools snapshot script.
7
7
  */
8
8
  const BASE_ENVIRONMENT = Object.freeze({
9
9
  CHARSET: "UTF-8",
10
10
  HOME: "/home/agentos",
11
- HOSTNAME: "secure-exec",
11
+ HOSTNAME: "agentos",
12
12
  LANG: "C.UTF-8",
13
13
  LC_COLLATE: "C",
14
14
  LOGNAME: "agentos",
@@ -0,0 +1,70 @@
1
+ export interface CodeExecutionSpawnOptions {
2
+ cwd?: string;
3
+ env?: Record<string, string>;
4
+ stdin?: string | Uint8Array;
5
+ streamStdin?: boolean;
6
+ captureStdio?: boolean;
7
+ }
8
+ export interface CodeExecutionProcessOutput {
9
+ pid: number;
10
+ stream: "stdout" | "stderr";
11
+ data: Uint8Array;
12
+ }
13
+ export interface CodeExecutionVm {
14
+ spawn(command: string, args: string[], options?: CodeExecutionSpawnOptions): {
15
+ pid: number;
16
+ };
17
+ onProcessOutput(pid: number, handler: (event: CodeExecutionProcessOutput) => void): () => void;
18
+ waitProcess(pid: number): Promise<number>;
19
+ writeProcessStdin(pid: number, data: string | Uint8Array): Promise<void>;
20
+ closeProcessStdin(pid: number): Promise<void>;
21
+ killProcess(pid: number): void;
22
+ stopProcess(pid: number): void;
23
+ }
24
+ export interface CodeExecutionOptions {
25
+ cwd?: string;
26
+ env?: Record<string, string>;
27
+ argv?: string[];
28
+ stdin?: string | Uint8Array;
29
+ timeoutMs?: number;
30
+ signal?: AbortSignal;
31
+ onStdout?: (chunk: string) => void;
32
+ onStderr?: (chunk: string) => void;
33
+ }
34
+ export interface CodeExecutionResult {
35
+ success: boolean;
36
+ exitCode: number;
37
+ stdout: string;
38
+ stderr: string;
39
+ }
40
+ export interface GuestError {
41
+ name: string;
42
+ message: string;
43
+ stack?: string;
44
+ }
45
+ export type CodeEvaluationResult<T> = {
46
+ success: true;
47
+ exitCode: 0;
48
+ value: T;
49
+ stdout: string;
50
+ stderr: string;
51
+ } | {
52
+ success: false;
53
+ exitCode: number;
54
+ error: GuestError;
55
+ stdout: string;
56
+ stderr: string;
57
+ };
58
+ export interface CodeProcess {
59
+ readonly pid: number;
60
+ writeStdin(data: string | Uint8Array): Promise<void>;
61
+ closeStdin(): Promise<void>;
62
+ kill(signal?: "SIGTERM" | "SIGKILL"): void;
63
+ wait(): Promise<CodeExecutionResult>;
64
+ }
65
+ export interface SpawnCodeProcessOptions extends CodeExecutionOptions {
66
+ onComplete?: () => Promise<void>;
67
+ streamStdin?: boolean;
68
+ }
69
+ export declare function spawnCodeProcess(vm: CodeExecutionVm, command: string, args: string[], options?: SpawnCodeProcessOptions): CodeProcess;
70
+ export declare function executeArgv(vm: CodeExecutionVm, command: string, args: string[], options?: SpawnCodeProcessOptions): Promise<CodeExecutionResult>;
@@ -0,0 +1,115 @@
1
+ function toSpawnOptions(options) {
2
+ return {
3
+ cwd: options.cwd,
4
+ env: options.env,
5
+ stdin: options.stdin,
6
+ streamStdin: options.streamStdin ?? true,
7
+ captureStdio: true,
8
+ };
9
+ }
10
+ export function spawnCodeProcess(vm, command, args, options = {}) {
11
+ if (options.signal?.aborted) {
12
+ throw abortReason(options.signal);
13
+ }
14
+ if (options.timeoutMs !== undefined &&
15
+ (!Number.isFinite(options.timeoutMs) || options.timeoutMs < 0)) {
16
+ throw new RangeError("timeoutMs must be a finite, non-negative number");
17
+ }
18
+ const { pid } = vm.spawn(command, args, toSpawnOptions(options));
19
+ const stdoutDecoder = new TextDecoder();
20
+ const stderrDecoder = new TextDecoder();
21
+ let stdout = "";
22
+ let stderr = "";
23
+ let callbackError;
24
+ let aborted = false;
25
+ let finalized = false;
26
+ let waitPromise;
27
+ const unsubscribeOutput = vm.onProcessOutput(pid, (event) => {
28
+ try {
29
+ if (event.stream === "stdout") {
30
+ const text = stdoutDecoder.decode(event.data, { stream: true });
31
+ stdout += text;
32
+ options.onStdout?.(text);
33
+ }
34
+ else {
35
+ const text = stderrDecoder.decode(event.data, { stream: true });
36
+ stderr += text;
37
+ options.onStderr?.(text);
38
+ }
39
+ }
40
+ catch (error) {
41
+ callbackError ??= error;
42
+ vm.killProcess(pid);
43
+ }
44
+ });
45
+ const abort = () => {
46
+ aborted = true;
47
+ vm.killProcess(pid);
48
+ };
49
+ options.signal?.addEventListener("abort", abort, { once: true });
50
+ const timeout = options.timeoutMs === undefined
51
+ ? undefined
52
+ : setTimeout(() => vm.killProcess(pid), options.timeoutMs);
53
+ const finalize = async () => {
54
+ if (finalized)
55
+ return;
56
+ finalized = true;
57
+ unsubscribeOutput();
58
+ options.signal?.removeEventListener("abort", abort);
59
+ if (timeout !== undefined)
60
+ clearTimeout(timeout);
61
+ stdout += stdoutDecoder.decode();
62
+ stderr += stderrDecoder.decode();
63
+ await options.onComplete?.();
64
+ };
65
+ const wait = () => {
66
+ waitPromise ??= (async () => {
67
+ let exitCode;
68
+ try {
69
+ exitCode = await vm.waitProcess(pid);
70
+ }
71
+ catch (waitError) {
72
+ try {
73
+ await finalize();
74
+ }
75
+ catch (cleanupError) {
76
+ console.error("[agentos] process cleanup also failed after waitProcess rejected:", cleanupError);
77
+ }
78
+ throw waitError;
79
+ }
80
+ await finalize();
81
+ if (aborted && options.signal)
82
+ throw abortReason(options.signal);
83
+ if (callbackError !== undefined)
84
+ throw callbackError;
85
+ return {
86
+ success: exitCode === 0,
87
+ exitCode,
88
+ stdout,
89
+ stderr,
90
+ };
91
+ })();
92
+ return waitPromise;
93
+ };
94
+ return {
95
+ pid,
96
+ writeStdin: (data) => vm.writeProcessStdin(pid, data),
97
+ closeStdin: () => vm.closeProcessStdin(pid),
98
+ kill: (signal) => {
99
+ if (signal === "SIGKILL")
100
+ vm.killProcess(pid);
101
+ else
102
+ vm.stopProcess(pid);
103
+ },
104
+ wait,
105
+ };
106
+ }
107
+ function abortReason(signal) {
108
+ return signal.reason ?? new DOMException("Execution aborted", "AbortError");
109
+ }
110
+ export async function executeArgv(vm, command, args, options = {}) {
111
+ return spawnCodeProcess(vm, command, args, {
112
+ ...options,
113
+ streamStdin: false,
114
+ }).wait();
115
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  export { AgentOs, AgentOsSidecar } from "./agent-os.js";
2
+ export type * from "./language-execution.js";
2
3
  export { CronManager, InvalidScheduleError, PastScheduleError, TimerScheduleDriver, } from "./cron/index.js";
3
4
  export { createHostDirBackend, nodeModulesMount } from "./host-dir-mount.js";
4
5
  export { binding, MAX_BINDING_DESCRIPTION_LENGTH, bindings, validateBindings, } from "./bindings.js";
6
+ export type { Binding, BindingExample, Bindings } from "./bindings.js";
5
7
  export { agentOsLimitsSchema, agentOsOptionFieldSchemas, agentOsOptionsSchema, bindingSchema, mountConfigSchema, nativeMountConfigSchema, parseAgentOsOptions, permissionsSchema, rootFilesystemConfigSchema, sharedSidecarConfigSchema, sidecarConfigSchema, bindingsSchema, } from "./options-schema.js";
6
- export { createSnapshotExport, } from "./layers.js";
8
+ export { createSnapshotExport } from "./layers.js";
7
9
  export { defineSoftware } from "./packages.js";
8
10
  export { isPackageDescriptor, OPT_AGENTOS_BIN, OPT_AGENTOS_ROOT, tryReadAgentosPackageManifest, } from "./agentos-package.js";
9
11
  export { KernelError } from "./runtime-compat.js";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ export { CronManager, InvalidScheduleError, PastScheduleError, TimerScheduleDriv
4
4
  export { createHostDirBackend, nodeModulesMount } from "./host-dir-mount.js";
5
5
  export { binding, MAX_BINDING_DESCRIPTION_LENGTH, bindings, validateBindings, } from "./bindings.js";
6
6
  export { agentOsLimitsSchema, agentOsOptionFieldSchemas, agentOsOptionsSchema, bindingSchema, mountConfigSchema, nativeMountConfigSchema, parseAgentOsOptions, permissionsSchema, rootFilesystemConfigSchema, sharedSidecarConfigSchema, sidecarConfigSchema, bindingsSchema, } from "./options-schema.js";
7
- export { createSnapshotExport, } from "./layers.js";
7
+ export { createSnapshotExport } from "./layers.js";
8
8
  export { defineSoftware } from "./packages.js";
9
9
  export { isPackageDescriptor, OPT_AGENTOS_BIN, OPT_AGENTOS_ROOT, tryReadAgentosPackageManifest, } from "./agentos-package.js";
10
10
  export { KernelError } from "./runtime-compat.js";
@@ -0,0 +1,170 @@
1
+ import type { JsonValue } from "./session-api.js";
2
+ export type ExecutionSignal = "SIGHUP" | "SIGINT" | "SIGQUIT" | "SIGTERM" | "SIGKILL" | "SIGSTOP" | "SIGCONT" | "SIGUSR1" | "SIGUSR2";
3
+ export interface LanguageExecutionOptions {
4
+ contextId?: string;
5
+ cwd?: string;
6
+ env?: Record<string, string>;
7
+ args?: string[];
8
+ stdin?: string | Uint8Array;
9
+ timeoutMs?: number;
10
+ pty?: {
11
+ cols?: number;
12
+ rows?: number;
13
+ };
14
+ signal?: AbortSignal;
15
+ onStdout?: (chunk: Uint8Array) => void;
16
+ onStderr?: (chunk: Uint8Array) => void;
17
+ output?: ExecutionOutputOptions;
18
+ }
19
+ export type OutputCapture = "none" | "stderr" | "all";
20
+ export interface ExecutionOutputOptions {
21
+ capture?: OutputCapture;
22
+ retainEvents?: boolean;
23
+ }
24
+ export interface InlineExecutionOptions extends LanguageExecutionOptions {
25
+ inputs?: Record<string, JsonValue>;
26
+ }
27
+ export interface JavaScriptExecutionOptions extends InlineExecutionOptions {
28
+ format?: "module" | "commonjs";
29
+ filePath?: string;
30
+ }
31
+ export type JavaScriptEvaluationOptions = JavaScriptExecutionOptions;
32
+ export interface TypeScriptExecutionOptions extends InlineExecutionOptions {
33
+ filePath?: string;
34
+ tsconfigPath?: string;
35
+ compilerOptions?: Record<string, JsonValue>;
36
+ }
37
+ export type TypeScriptEvaluationOptions = TypeScriptExecutionOptions;
38
+ export interface TypeScriptFileExecutionOptions extends LanguageExecutionOptions {
39
+ tsconfigPath?: string;
40
+ compilerOptions?: Record<string, JsonValue>;
41
+ }
42
+ export interface TypeScriptCheckOptions {
43
+ contextId?: string;
44
+ cwd?: string;
45
+ filePath?: string;
46
+ tsconfigPath?: string;
47
+ compilerOptions?: Record<string, JsonValue>;
48
+ timeoutMs?: number;
49
+ signal?: AbortSignal;
50
+ output?: ExecutionOutputOptions;
51
+ }
52
+ export interface NpmProjectInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
53
+ frozen?: boolean;
54
+ }
55
+ export interface NpmPackageInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
56
+ dev?: boolean;
57
+ global?: boolean;
58
+ }
59
+ export interface PythonInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
60
+ upgrade?: boolean;
61
+ requirementsFile?: string;
62
+ indexUrl?: string;
63
+ extraIndexUrls?: string[];
64
+ }
65
+ export type ContextState = "idle" | "running" | "resetting" | "deleting" | "failed";
66
+ export type ExecutionOutcome = "succeeded" | "failed" | "cancelled" | "timed_out";
67
+ export interface ContextDescriptor {
68
+ contextId: string;
69
+ state: ContextState;
70
+ language?: "javascript" | "python";
71
+ createdAtMs: number;
72
+ lastStartedAtMs?: number;
73
+ lastCompletedAtMs?: number;
74
+ }
75
+ export interface ProcessDescriptor {
76
+ pid: number;
77
+ state: "running" | "exited";
78
+ language?: "javascript" | "python";
79
+ command?: string;
80
+ startedAtMs: number;
81
+ }
82
+ export interface ProcessExit {
83
+ pid: number;
84
+ outcome: "exited" | "signalled" | "timed_out";
85
+ exitCode?: number;
86
+ signal?: ExecutionSignal;
87
+ }
88
+ export interface SpawnOptions {
89
+ cwd?: string;
90
+ env?: Record<string, string>;
91
+ args?: string[];
92
+ stdin?: string | Uint8Array;
93
+ timeoutMs?: number;
94
+ pty?: {
95
+ cols?: number;
96
+ rows?: number;
97
+ };
98
+ signal?: AbortSignal;
99
+ onStdout?: (chunk: Uint8Array) => void;
100
+ onStderr?: (chunk: Uint8Array) => void;
101
+ output?: {
102
+ retainEvents?: boolean;
103
+ };
104
+ }
105
+ export type LanguageSpawnOptions = SpawnOptions;
106
+ export interface ExecutionErrorData {
107
+ code: string;
108
+ name: string;
109
+ message: string;
110
+ stack?: string;
111
+ details?: JsonValue;
112
+ }
113
+ interface CodeExecutionResultBase {
114
+ exitCode?: number;
115
+ stdout?: string;
116
+ stderr?: string;
117
+ stdoutTruncated?: boolean;
118
+ stderrTruncated?: boolean;
119
+ }
120
+ type ExecutionResultOutcome<TIdentity> = (CodeExecutionResultBase & {
121
+ outcome: "succeeded";
122
+ error?: never;
123
+ } & TIdentity) | (CodeExecutionResultBase & {
124
+ outcome: Exclude<ExecutionOutcome, "succeeded">;
125
+ error: ExecutionErrorData;
126
+ } & TIdentity);
127
+ export type CodeExecutionResult = ExecutionResultOutcome<Record<never, never>>;
128
+ export type CodeEvaluationResult<T = JsonValue> = (CodeExecutionResultBase & {
129
+ outcome: "succeeded";
130
+ error?: never;
131
+ value: T;
132
+ }) | (CodeExecutionResultBase & {
133
+ outcome: Exclude<ExecutionOutcome, "succeeded">;
134
+ error: ExecutionErrorData;
135
+ value?: never;
136
+ });
137
+ export interface TypeScriptDiagnostic {
138
+ code: number;
139
+ category: "error" | "warning" | "suggestion" | "message";
140
+ message: string;
141
+ filePath?: string;
142
+ line?: number;
143
+ column?: number;
144
+ }
145
+ export type TypeScriptCheckResult = (CodeExecutionResultBase & {
146
+ outcome: "succeeded";
147
+ error?: never;
148
+ hasErrors: boolean;
149
+ diagnostics: TypeScriptDiagnostic[];
150
+ }) | (CodeExecutionResultBase & {
151
+ outcome: Exclude<ExecutionOutcome, "succeeded">;
152
+ error: ExecutionErrorData;
153
+ hasErrors?: never;
154
+ diagnostics: TypeScriptDiagnostic[];
155
+ });
156
+ export interface ProcessOutputEvent<TChunk = Uint8Array> {
157
+ pid: number;
158
+ sequence: number;
159
+ channel: "stdout" | "stderr" | "pty";
160
+ chunk: TChunk;
161
+ timestampMs: number;
162
+ }
163
+ export interface OutputReplay<TChunk = Uint8Array> {
164
+ pid: number;
165
+ events: ProcessOutputEvent<TChunk>[];
166
+ nextCursor: string;
167
+ hasMore: boolean;
168
+ truncated: boolean;
169
+ }
170
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -138,7 +138,7 @@ export declare const agentOsLimitsSchema: z.ZodObject<{
138
138
  defaultBindingTimeoutMs: z.ZodOptional<z.ZodNumber>;
139
139
  maxBindingTimeoutMs: z.ZodOptional<z.ZodNumber>;
140
140
  maxRegisteredCollections: z.ZodOptional<z.ZodNumber>;
141
- maxRegisteredCollectionsPerVm: z.ZodOptional<z.ZodNumber>;
141
+ maxRegisteredBindingsPerVm: z.ZodOptional<z.ZodNumber>;
142
142
  maxBindingsPerCollection: z.ZodOptional<z.ZodNumber>;
143
143
  maxBindingSchemaBytes: z.ZodOptional<z.ZodNumber>;
144
144
  maxExamplesPerBinding: z.ZodOptional<z.ZodNumber>;
@@ -196,6 +196,11 @@ export declare const agentOsLimitsSchema: z.ZodObject<{
196
196
  runnerHeapLimitMb: z.ZodOptional<z.ZodNumber>;
197
197
  runnerCpuTimeLimitMs: z.ZodOptional<z.ZodNumber>;
198
198
  }, z.core.$strict>>;
199
+ execution: z.ZodOptional<z.ZodObject<{
200
+ completedTtlMs: z.ZodOptional<z.ZodNumber>;
201
+ maxCompletedExecutions: z.ZodOptional<z.ZodNumber>;
202
+ liveExecutionWarningThreshold: z.ZodOptional<z.ZodNumber>;
203
+ }, z.core.$strict>>;
199
204
  process: z.ZodOptional<z.ZodObject<{
200
205
  maxSpawnFileActions: z.ZodOptional<z.ZodNumber>;
201
206
  maxSpawnFileActionBytes: z.ZodOptional<z.ZodNumber>;
@@ -488,7 +493,7 @@ export declare const agentOsOptionFieldSchemas: {
488
493
  defaultBindingTimeoutMs: z.ZodOptional<z.ZodNumber>;
489
494
  maxBindingTimeoutMs: z.ZodOptional<z.ZodNumber>;
490
495
  maxRegisteredCollections: z.ZodOptional<z.ZodNumber>;
491
- maxRegisteredCollectionsPerVm: z.ZodOptional<z.ZodNumber>;
496
+ maxRegisteredBindingsPerVm: z.ZodOptional<z.ZodNumber>;
492
497
  maxBindingsPerCollection: z.ZodOptional<z.ZodNumber>;
493
498
  maxBindingSchemaBytes: z.ZodOptional<z.ZodNumber>;
494
499
  maxExamplesPerBinding: z.ZodOptional<z.ZodNumber>;
@@ -546,6 +551,11 @@ export declare const agentOsOptionFieldSchemas: {
546
551
  runnerHeapLimitMb: z.ZodOptional<z.ZodNumber>;
547
552
  runnerCpuTimeLimitMs: z.ZodOptional<z.ZodNumber>;
548
553
  }, z.core.$strict>>;
554
+ execution: z.ZodOptional<z.ZodObject<{
555
+ completedTtlMs: z.ZodOptional<z.ZodNumber>;
556
+ maxCompletedExecutions: z.ZodOptional<z.ZodNumber>;
557
+ liveExecutionWarningThreshold: z.ZodOptional<z.ZodNumber>;
558
+ }, z.core.$strict>>;
549
559
  process: z.ZodOptional<z.ZodObject<{
550
560
  maxSpawnFileActions: z.ZodOptional<z.ZodNumber>;
551
561
  maxSpawnFileActionBytes: z.ZodOptional<z.ZodNumber>;
@@ -128,7 +128,7 @@ export const agentOsLimitsSchema = z
128
128
  defaultBindingTimeoutMs: nonNegativeInteger.optional(),
129
129
  maxBindingTimeoutMs: nonNegativeInteger.optional(),
130
130
  maxRegisteredCollections: positiveInteger.optional(),
131
- maxRegisteredCollectionsPerVm: positiveInteger.optional(),
131
+ maxRegisteredBindingsPerVm: positiveInteger.optional(),
132
132
  maxBindingsPerCollection: positiveInteger.optional(),
133
133
  maxBindingSchemaBytes: positiveInteger.optional(),
134
134
  maxExamplesPerBinding: nonNegativeInteger.optional(),
@@ -204,6 +204,14 @@ export const agentOsLimitsSchema = z
204
204
  })
205
205
  .strict()
206
206
  .optional(),
207
+ execution: z
208
+ .object({
209
+ completedTtlMs: positiveInteger.optional(),
210
+ maxCompletedExecutions: positiveInteger.optional(),
211
+ liveExecutionWarningThreshold: positiveInteger.optional(),
212
+ })
213
+ .strict()
214
+ .optional(),
207
215
  process: z
208
216
  .object({
209
217
  maxSpawnFileActions: positiveInteger.optional(),
@@ -1,7 +1,7 @@
1
1
  import type { SoftwarePackageRef } from "./agentos-package.js";
2
2
  /**
3
3
  * Input type for the `software` option. Software is a self-contained package
4
- * directory that the secure-exec sidecar materializes into the `/opt/agentos`
4
+ * directory that the agentos sidecar materializes into the `/opt/agentos`
5
5
  * projection. Accepts a package-dir ref or an array of refs for meta-packages.
6
6
  */
7
7
  export type SoftwareEntry = SoftwarePackageRef;
@@ -1363,7 +1363,7 @@ class NativeKernel {
1363
1363
  throw new Error("kernel is not ready");
1364
1364
  }
1365
1365
  const sidecarMounts = commandDirs.map((commandDir, index) => serializeMountConfigForSidecar({
1366
- path: `/__secure_exec/commands/${index}`,
1366
+ path: `/__agentos/commands/${index}`,
1367
1367
  readOnly: true,
1368
1368
  plugin: {
1369
1369
  id: "host_dir",
@@ -236,13 +236,15 @@ export declare function writeAcpCloseSessionRequest(bc: bare.ByteCursor, x: AcpC
236
236
  * Resume a session that exists in durable storage but is not live in the current
237
237
  * VM (e.g. after a Rivet actor slept and woke with a fresh VM). The sidecar runs
238
238
  * the stateless resume state machine (native session/load when the agent supports
239
- * it, else a fresh session/new + transcript continuation preamble). `cwd`/`env`
240
- * describe the fresh adapter launch used by the fallback tier. `transcriptPath`,
241
- * when present, is a guest-readable path the fallback preamble points the agent at.
239
+ * it, else a fresh session/new + transcript continuation preamble). `runtime`,
240
+ * `cwd`, and `env` describe the fresh adapter launch used by the fallback tier.
241
+ * `transcriptPath`, when present, is a guest-readable path the fallback preamble
242
+ * points the agent at.
242
243
  */
243
244
  export type AcpResumeSessionRequest = {
244
245
  readonly sessionId: string;
245
246
  readonly agentType: string;
247
+ readonly runtime: AcpRuntimeKind;
246
248
  readonly transcriptPath: string | null;
247
249
  readonly cwd: string;
248
250
  readonly additionalDirectories: readonly string[];
@@ -373,6 +373,7 @@ export function readAcpResumeSessionRequest(bc) {
373
373
  return {
374
374
  sessionId: bare.readString(bc),
375
375
  agentType: bare.readString(bc),
376
+ runtime: readAcpRuntimeKind(bc),
376
377
  transcriptPath: read2(bc),
377
378
  cwd: bare.readString(bc),
378
379
  additionalDirectories: read0(bc),
@@ -383,6 +384,7 @@ export function readAcpResumeSessionRequest(bc) {
383
384
  export function writeAcpResumeSessionRequest(bc, x) {
384
385
  bare.writeString(bc, x.sessionId);
385
386
  bare.writeString(bc, x.agentType);
387
+ writeAcpRuntimeKind(bc, x.runtime);
386
388
  write2(bc, x.transcriptPath);
387
389
  bare.writeString(bc, x.cwd);
388
390
  write0(bc, x.additionalDirectories);
@@ -361,16 +361,16 @@ export class NativeSidecarKernelProxy {
361
361
  const parsedCommand = parseSimpleExecCommand(command);
362
362
  const runAndCapture = async (proc, stdinOverride, readExitCode) => {
363
363
  if (stdinOverride !== undefined) {
364
- proc.writeStdin(stdinOverride);
364
+ await proc.writeStdin(stdinOverride);
365
365
  }
366
366
  else if (options?.stdin !== undefined) {
367
- proc.writeStdin(options.stdin);
367
+ await proc.writeStdin(options.stdin);
368
368
  }
369
369
  // `kernel.exec()` is a non-interactive run-to-completion API: when the
370
370
  // caller does not opt into a streaming stdin handle, the guest process
371
371
  // should observe EOF after any provided input so commands like
372
372
  // `node -e ...` do not linger behind an inherited open stdin pipe.
373
- proc.closeStdin();
373
+ await proc.closeStdin();
374
374
  const waitPromise = proc.wait();
375
375
  const shellExitCode = typeof options?.timeout === "number"
376
376
  ? await new Promise((resolve) => {
@@ -438,9 +438,9 @@ export class NativeSidecarKernelProxy {
438
438
  const effectiveCwd = options?.cwd ?? this.defaultExecCwd ?? this.cwd;
439
439
  const runAndCapture = async (proc) => {
440
440
  if (options?.stdin !== undefined) {
441
- proc.writeStdin(options.stdin);
441
+ await proc.writeStdin(options.stdin);
442
442
  }
443
- proc.closeStdin();
443
+ await proc.closeStdin();
444
444
  const waitPromise = proc.wait();
445
445
  const exitCode = typeof options?.timeout === "number"
446
446
  ? await new Promise((resolve) => {
@@ -524,9 +524,9 @@ export class NativeSidecarKernelProxy {
524
524
  rejectWait,
525
525
  onStdout: new Set(options?.onStdout ? [options.onStdout] : []),
526
526
  onStderr: new Set(options?.onStderr ? [options.onStderr] : []),
527
- pendingStdin: [],
527
+ pendingStdin: options?.stdin === undefined ? [] : [options.stdin],
528
528
  stdinFlushPromise: null,
529
- pendingCloseStdin: false,
529
+ pendingCloseStdin: !options?.streamStdin,
530
530
  pendingKillSignal: null,
531
531
  waitWithFallbackPromise: null,
532
532
  hostExitObservedAt: null,
@@ -1001,7 +1001,9 @@ export class NativeSidecarKernelProxy {
1001
1001
  });
1002
1002
  const restoreRawMode = stdin.isTTY && typeof stdin.setRawMode === "function";
1003
1003
  const onStdinData = (data) => {
1004
- shell.write(data);
1004
+ void shell.write(data).catch((error) => {
1005
+ console.error("[agentos] failed to forward terminal stdin:", error);
1006
+ });
1005
1007
  };
1006
1008
  const onResize = () => {
1007
1009
  shell.resize(stdout.columns, stdout.rows);
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type { AgentOsCreateSidecarOptions, AgentOsLimits, AgentOsOptions, AgentOsSharedSidecarOptions, AgentOsSidecarConfig, AgentOsSidecarDescription, AgentExitEvent, AgentExitHandler, AgentRestartOutcome, AgentStderrEvent, AgentStderrHandler, AgentRegistryEntry, BatchReadResult, BatchWriteEntry, BatchWriteResult, DirEntry, DynamicMountDescriptor, ExportRootFilesystemOptions, HttpRequest, HttpResponse, LimitWarning, LimitWarningHandler, MountConfig, MountInfo, MountConfigJsonObject, MountConfigJsonPrimitive, MountConfigJsonValue, NativeMountConfig, NativeMountPluginDescriptor, NativeRootFilesystemConfig, OverlayMountConfig, OverlayRootFilesystemConfig, PlainMountConfig, ProcessTreeNode, ProcessExit, ProcessOutput, ReaddirEntry, ReaddirRecursiveOptions, RootFilesystemConfig, RootLowerInput, SpawnedProcessInfo, SpawnOptions, ShellData, ShellExit, ShellOptions, } from "./agent-os.js";
1
+ export type { AgentExitEvent, AgentExitHandler, AgentOsCreateSidecarOptions, AgentOsLimits, AgentOsOptions, AgentOsSharedSidecarOptions, AgentOsSidecarConfig, AgentOsSidecarDescription, AgentRegistryEntry, AgentRestartOutcome, AgentStderrEvent, AgentStderrHandler, BatchReadResult, BatchWriteEntry, BatchWriteResult, DirEntry, DynamicMountDescriptor, ExportRootFilesystemOptions, HttpRequest, HttpResponse, LimitWarning, LimitWarningHandler, MountConfig, MountConfigJsonObject, MountConfigJsonPrimitive, MountConfigJsonValue, MountInfo, NativeMountConfig, NativeMountPluginDescriptor, NativeRootFilesystemConfig, OverlayMountConfig, OverlayRootFilesystemConfig, PlainMountConfig, ProcessOutput, ProcessTreeNode, ReaddirEntry, ReaddirRecursiveOptions, RootFilesystemConfig, RootLowerInput, ShellData, ShellExit, ShellOptions, } from "./agent-os.js";
2
+ export type { CodeEvaluationResult, CodeExecutionResult, ContextDescriptor, ContextState, ExecutionErrorData, ExecutionSignal, InlineExecutionOptions, JavaScriptEvaluationOptions, JavaScriptExecutionOptions, LanguageExecutionOptions, LanguageSpawnOptions, NpmPackageInstallOptions, NpmProjectInstallOptions, OutputCapture, OutputReplay, ProcessDescriptor, ProcessExit, ProcessOutputEvent, PythonInstallOptions, SpawnOptions, TypeScriptCheckOptions, TypeScriptCheckResult, TypeScriptDiagnostic, TypeScriptEvaluationOptions, TypeScriptExecutionOptions, TypeScriptFileExecutionOptions, } from "./language-execution.js";
2
3
  export type * from "./session-api.js";
3
4
  /**
4
5
  * An agent type id — the `name` of an `/opt/agentos` agent package manifest
@@ -7,11 +8,11 @@ export type * from "./session-api.js";
7
8
  * passes only the name, so any manifest `name` is a valid agent type.
8
9
  */
9
10
  export type AgentType = string;
11
+ export type { AgentBlock, PackageDescriptor, PackageRef, SoftwarePackageRef, } from "./agentos-package.js";
12
+ export type { Binding, BindingExample, Bindings } from "./bindings.js";
10
13
  export type { CronAction, CronActionInfo, CronEvent, CronEventHandler, CronJob, CronJobInfo, CronJobOptions, ScheduleDriver, ScheduleEntry, ScheduleHandle, } from "./cron/index.js";
11
14
  export type { HostDirBackendOptions, HostDirMountPluginConfig, NodeModulesMountConfig, } from "./host-dir-mount.js";
12
- export type { Binding, BindingExample, Bindings } from "./bindings.js";
13
15
  export type { FilesystemSnapshotExport, LayerHandle, LayerStore, OverlayFilesystemMode, RootSnapshotExport, SnapshotImportSource, SnapshotLayerHandle, WritableLayerHandle, } from "./layers.js";
14
16
  export type { SoftwareInput, SoftwareRoot } from "./packages.js";
15
- export type { AgentBlock, PackageDescriptor, PackageRef, SoftwarePackageRef, } from "./agentos-package.js";
16
17
  export type { ChildProcessPermissions, ConnectTerminalOptions, EnvPermissions, ExecOptions, ExecResult, FsPermissionRule, FsPermissions, KernelExecOptions, KernelExecResult, KernelSpawnOptions, NetworkAccessRequest, NetworkPermissions, OpenShellOptions, PatternPermissionRule, PermissionDecision, PermissionMode, Permissions, ProcessInfo, RulePermissions, StdioChannel, TimingMitigation, VirtualDirEntry, VirtualFileSystem, VirtualStat, } from "./runtime.js";
17
18
  export type { AgentOsSandboxClient, AgentOsSandboxClientOptions, AgentOsSandboxCommonOptions, AgentOsSandboxInput, AgentOsSandboxOptions, AgentOsSandboxProcessInfo, AgentOsSandboxProcessLogs, AgentOsSandboxProcessResult, AgentOsSandboxProvider, AgentOsSandboxProviderOptions, SandboxMountPluginConfig, } from "./sandbox.js";