@rivet-dev/agentos-core 0.0.0-agentos-dylib-plugin.473700e

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 (75) hide show
  1. package/README.md +204 -0
  2. package/dist/agent-os.d.ts +560 -0
  3. package/dist/agent-os.js +3624 -0
  4. package/dist/agent-session-types.d.ts +67 -0
  5. package/dist/agent-session-types.js +1 -0
  6. package/dist/agents.d.ts +63 -0
  7. package/dist/agents.js +42 -0
  8. package/dist/base-filesystem.d.ts +34 -0
  9. package/dist/base-filesystem.js +173 -0
  10. package/dist/cron/cron-manager.d.ts +22 -0
  11. package/dist/cron/cron-manager.js +160 -0
  12. package/dist/cron/index.d.ts +5 -0
  13. package/dist/cron/index.js +3 -0
  14. package/dist/cron/parse-schedule.d.ts +25 -0
  15. package/dist/cron/parse-schedule.js +66 -0
  16. package/dist/cron/schedule-driver.d.ts +19 -0
  17. package/dist/cron/schedule-driver.js +1 -0
  18. package/dist/cron/timer-driver.d.ts +17 -0
  19. package/dist/cron/timer-driver.js +61 -0
  20. package/dist/cron/types.d.ts +55 -0
  21. package/dist/cron/types.js +1 -0
  22. package/dist/filesystem-snapshot.d.ts +14 -0
  23. package/dist/filesystem-snapshot.js +105 -0
  24. package/dist/host-dir-mount.d.ts +38 -0
  25. package/dist/host-dir-mount.js +34 -0
  26. package/dist/host-tools-zod.d.ts +7 -0
  27. package/dist/host-tools-zod.js +243 -0
  28. package/dist/host-tools.d.ts +45 -0
  29. package/dist/host-tools.js +26 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +10 -0
  32. package/dist/js-bridge.d.ts +3 -0
  33. package/dist/js-bridge.js +2 -0
  34. package/dist/json-rpc.d.ts +50 -0
  35. package/dist/json-rpc.js +22 -0
  36. package/dist/layers.d.ts +51 -0
  37. package/dist/layers.js +185 -0
  38. package/dist/overlay-filesystem.d.ts +19 -0
  39. package/dist/overlay-filesystem.js +645 -0
  40. package/dist/packages.d.ts +127 -0
  41. package/dist/packages.js +335 -0
  42. package/dist/runtime-compat.d.ts +471 -0
  43. package/dist/runtime-compat.js +2009 -0
  44. package/dist/runtime.d.ts +336 -0
  45. package/dist/runtime.js +1 -0
  46. package/dist/sidecar/agent-os-protocol.d.ts +219 -0
  47. package/dist/sidecar/agent-os-protocol.js +594 -0
  48. package/dist/sidecar/binary.d.ts +9 -0
  49. package/dist/sidecar/binary.js +30 -0
  50. package/dist/sidecar/cargo.d.ts +2 -0
  51. package/dist/sidecar/cargo.js +142 -0
  52. package/dist/sidecar/native-process-client.d.ts +2 -0
  53. package/dist/sidecar/native-process-client.js +1 -0
  54. package/dist/sidecar/permissions.d.ts +3 -0
  55. package/dist/sidecar/permissions.js +54 -0
  56. package/dist/sidecar/process.d.ts +6 -0
  57. package/dist/sidecar/process.js +8 -0
  58. package/dist/sidecar/rpc-client.d.ts +244 -0
  59. package/dist/sidecar/rpc-client.js +2028 -0
  60. package/dist/test/docker.d.ts +133 -0
  61. package/dist/test/docker.js +336 -0
  62. package/dist/test/file-system.d.ts +39 -0
  63. package/dist/test/file-system.js +562 -0
  64. package/dist/test/mock-s3.d.ts +42 -0
  65. package/dist/test/mock-s3.js +292 -0
  66. package/dist/test/runtime.d.ts +11 -0
  67. package/dist/test/runtime.js +9 -0
  68. package/dist/test/sandbox-agent.d.ts +9 -0
  69. package/dist/test/sandbox-agent.js +395 -0
  70. package/dist/test/terminal-harness.d.ts +27 -0
  71. package/dist/test/terminal-harness.js +122 -0
  72. package/dist/types.d.ts +10 -0
  73. package/dist/types.js +1 -0
  74. package/fixtures/AGENTOS_SYSTEM_PROMPT.md +21 -0
  75. package/package.json +111 -0
@@ -0,0 +1,3 @@
1
+ import { type LocalCompatMount, serializeMountConfigForSidecar as serializeMountConfig } from "./sidecar/rpc-client.js";
2
+ export type { LocalCompatMount };
3
+ export declare const serializeMountConfigForSidecar: typeof serializeMountConfig;
@@ -0,0 +1,2 @@
1
+ import { serializeMountConfigForSidecar as serializeMountConfig, } from "./sidecar/rpc-client.js";
2
+ export const serializeMountConfigForSidecar = serializeMountConfig;
@@ -0,0 +1,50 @@
1
+ export interface AcpTimeoutErrorData {
2
+ kind: "acp_timeout";
3
+ method: string;
4
+ id: number | string | null;
5
+ timeoutMs: number;
6
+ exitCode?: number;
7
+ killed?: boolean;
8
+ transportState?: string;
9
+ recentActivity: string[];
10
+ }
11
+ /**
12
+ * Structured error payload meaning "the session id is not known to the agent" —
13
+ * e.g. a `session/load` / `session/resume` against a session whose on-disk store did
14
+ * not survive a VM teardown. The sidecar normalizes the adapter's native error into
15
+ * this shape so the resume orchestration can distinguish "fall through to a fresh
16
+ * session" from a transport/timeout error (which must propagate). Mirrors the
17
+ * `acp_timeout` convention.
18
+ */
19
+ export interface UnknownSessionErrorData {
20
+ kind: "unknown_session";
21
+ /** Optional metadata. The discriminator is `kind` alone — the sidecar's
22
+ * normalized error carries only `kind`, so this stays optional to keep the
23
+ * sidecar and client contracts aligned. */
24
+ sessionId?: string;
25
+ }
26
+ export type JsonRpcErrorData = AcpTimeoutErrorData | UnknownSessionErrorData | Record<string, unknown>;
27
+ export interface JsonRpcRequest {
28
+ jsonrpc: "2.0";
29
+ id: number | string | null;
30
+ method: string;
31
+ params?: unknown;
32
+ }
33
+ export interface JsonRpcResponse {
34
+ jsonrpc: "2.0";
35
+ id: number | string | null;
36
+ result?: unknown;
37
+ error?: JsonRpcError;
38
+ }
39
+ export interface JsonRpcError {
40
+ code: number;
41
+ message: string;
42
+ data?: JsonRpcErrorData;
43
+ }
44
+ export interface JsonRpcNotification {
45
+ jsonrpc: "2.0";
46
+ method: string;
47
+ params?: unknown;
48
+ }
49
+ export declare function isAcpTimeoutErrorData(value: unknown): value is AcpTimeoutErrorData;
50
+ export declare function isUnknownSessionErrorData(value: unknown): value is UnknownSessionErrorData;
@@ -0,0 +1,22 @@
1
+ export function isAcpTimeoutErrorData(value) {
2
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
3
+ return false;
4
+ }
5
+ const record = value;
6
+ return (record.kind === "acp_timeout" &&
7
+ typeof record.method === "string" &&
8
+ (typeof record.id === "number" ||
9
+ typeof record.id === "string" ||
10
+ record.id === null) &&
11
+ typeof record.timeoutMs === "number" &&
12
+ Array.isArray(record.recentActivity) &&
13
+ record.recentActivity.every((entry) => typeof entry === "string"));
14
+ }
15
+ export function isUnknownSessionErrorData(value) {
16
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
17
+ return false;
18
+ }
19
+ const record = value;
20
+ return (record.kind === "unknown_session" &&
21
+ (record.sessionId === undefined || typeof record.sessionId === "string"));
22
+ }
@@ -0,0 +1,51 @@
1
+ import { type BaseFilesystemSnapshot } from "./base-filesystem.js";
2
+ import { type FilesystemEntry } from "./filesystem-snapshot.js";
3
+ import type { VirtualFileSystem } from "./runtime-compat.js";
4
+ export type OverlayFilesystemMode = "ephemeral" | "read-only";
5
+ export interface FilesystemSnapshotExport {
6
+ format: "agent-os-filesystem-snapshot-v1";
7
+ filesystem: {
8
+ entries: FilesystemEntry[];
9
+ };
10
+ }
11
+ export type RootSnapshotExport = {
12
+ kind: "snapshot-export";
13
+ source: FilesystemSnapshotExport;
14
+ };
15
+ export interface LayerHandle {
16
+ kind: "writable" | "snapshot";
17
+ storeId: string;
18
+ layerId: string;
19
+ }
20
+ export interface WritableLayerHandle extends LayerHandle {
21
+ kind: "writable";
22
+ leaseId: string;
23
+ }
24
+ export interface SnapshotLayerHandle extends LayerHandle {
25
+ kind: "snapshot";
26
+ }
27
+ export type SnapshotImportSource = {
28
+ kind: "base-filesystem-artifact";
29
+ source: BaseFilesystemSnapshot | unknown;
30
+ } | {
31
+ kind: "snapshot-export";
32
+ source: FilesystemSnapshotExport | unknown;
33
+ };
34
+ export interface LayerStore {
35
+ readonly storeId: string;
36
+ createWritableLayer(): Promise<WritableLayerHandle>;
37
+ importSnapshot(source: SnapshotImportSource): Promise<SnapshotLayerHandle>;
38
+ openSnapshotLayer(layerId: string): Promise<SnapshotLayerHandle>;
39
+ sealLayer(layer: WritableLayerHandle): Promise<SnapshotLayerHandle>;
40
+ createOverlayFilesystem(options: {
41
+ mode?: "ephemeral";
42
+ upper: WritableLayerHandle;
43
+ lowers: SnapshotLayerHandle[];
44
+ } | {
45
+ mode: "read-only";
46
+ lowers: SnapshotLayerHandle[];
47
+ }): VirtualFileSystem;
48
+ }
49
+ export declare function createSnapshotExport(entries: FilesystemEntry[]): RootSnapshotExport;
50
+ export declare function createInMemoryLayerStore(): LayerStore;
51
+ export declare function createDefaultRootLowerInput(): SnapshotImportSource;
package/dist/layers.js ADDED
@@ -0,0 +1,185 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { getBaseFilesystemSnapshot, } from "./base-filesystem.js";
3
+ import { createFilesystemFromEntries, snapshotVirtualFilesystem, } from "./filesystem-snapshot.js";
4
+ import { createOverlayBackend } from "./overlay-filesystem.js";
5
+ function cloneSnapshotHandle(storeId, layerId) {
6
+ return { kind: "snapshot", storeId, layerId };
7
+ }
8
+ function cloneWritableHandle(storeId, layerId, leaseId) {
9
+ return { kind: "writable", storeId, layerId, leaseId };
10
+ }
11
+ function isBaseFilesystemSnapshot(value) {
12
+ if (!value || typeof value !== "object") {
13
+ return false;
14
+ }
15
+ const filesystem = value.filesystem;
16
+ if (!filesystem || typeof filesystem !== "object") {
17
+ return false;
18
+ }
19
+ return Array.isArray(filesystem.entries);
20
+ }
21
+ function isFilesystemSnapshotExport(value) {
22
+ if (!value || typeof value !== "object") {
23
+ return false;
24
+ }
25
+ if (value.format !== "agent-os-filesystem-snapshot-v1") {
26
+ return false;
27
+ }
28
+ const filesystem = value.filesystem;
29
+ if (!filesystem || typeof filesystem !== "object") {
30
+ return false;
31
+ }
32
+ return Array.isArray(filesystem.entries);
33
+ }
34
+ function normalizeSnapshotExport(source) {
35
+ if (source.kind === "base-filesystem-artifact") {
36
+ if (!isBaseFilesystemSnapshot(source.source)) {
37
+ throw new Error("Invalid base filesystem artifact");
38
+ }
39
+ return {
40
+ format: "agent-os-filesystem-snapshot-v1",
41
+ filesystem: {
42
+ entries: source.source.filesystem.entries,
43
+ },
44
+ };
45
+ }
46
+ if (!isFilesystemSnapshotExport(source.source)) {
47
+ throw new Error("Invalid snapshot export");
48
+ }
49
+ return source.source;
50
+ }
51
+ export function createSnapshotExport(entries) {
52
+ return {
53
+ kind: "snapshot-export",
54
+ source: {
55
+ format: "agent-os-filesystem-snapshot-v1",
56
+ filesystem: { entries },
57
+ },
58
+ };
59
+ }
60
+ export function createInMemoryLayerStore() {
61
+ const storeId = `memory-layer-store:${randomUUID()}`;
62
+ const layers = new Map();
63
+ function getLayerState(handle) {
64
+ if (handle.storeId !== storeId) {
65
+ throw new Error(`Layer ${handle.layerId} belongs to store ${handle.storeId}, not ${storeId}`);
66
+ }
67
+ const state = layers.get(handle.layerId);
68
+ if (!state) {
69
+ throw new Error(`Unknown layer: ${handle.layerId}`);
70
+ }
71
+ if (state.kind !== handle.kind) {
72
+ throw new Error(`Layer kind mismatch for ${handle.layerId}`);
73
+ }
74
+ return state;
75
+ }
76
+ return {
77
+ storeId,
78
+ async createWritableLayer() {
79
+ const layerId = randomUUID();
80
+ const leaseId = randomUUID();
81
+ layers.set(layerId, {
82
+ kind: "writable",
83
+ fs: await createFilesystemFromEntries([
84
+ {
85
+ path: "/",
86
+ type: "directory",
87
+ mode: "0755",
88
+ uid: 0,
89
+ gid: 0,
90
+ },
91
+ ]),
92
+ leaseId,
93
+ valid: true,
94
+ activeOverlay: null,
95
+ });
96
+ return cloneWritableHandle(storeId, layerId, leaseId);
97
+ },
98
+ async importSnapshot(source) {
99
+ const snapshot = normalizeSnapshotExport(source);
100
+ const layerId = randomUUID();
101
+ layers.set(layerId, {
102
+ kind: "snapshot",
103
+ snapshot,
104
+ fs: await createFilesystemFromEntries(snapshot.filesystem.entries),
105
+ });
106
+ return cloneSnapshotHandle(storeId, layerId);
107
+ },
108
+ async openSnapshotLayer(layerId) {
109
+ const state = layers.get(layerId);
110
+ if (!state || state.kind !== "snapshot") {
111
+ throw new Error(`Unknown snapshot layer: ${layerId}`);
112
+ }
113
+ return cloneSnapshotHandle(storeId, layerId);
114
+ },
115
+ async sealLayer(layer) {
116
+ const state = getLayerState(layer);
117
+ if (state.kind !== "writable") {
118
+ throw new Error(`Layer ${layer.layerId} is not writable`);
119
+ }
120
+ if (!state.valid || state.leaseId !== layer.leaseId) {
121
+ throw new Error(`Writable layer ${layer.layerId} is no longer valid`);
122
+ }
123
+ const entries = await snapshotVirtualFilesystem(state.activeOverlay ?? state.fs);
124
+ const snapshot = createSnapshotExport(entries).source;
125
+ const layerId = randomUUID();
126
+ layers.set(layerId, {
127
+ kind: "snapshot",
128
+ snapshot,
129
+ fs: await createFilesystemFromEntries(snapshot.filesystem.entries),
130
+ });
131
+ state.valid = false;
132
+ state.activeOverlay = null;
133
+ return cloneSnapshotHandle(storeId, layerId);
134
+ },
135
+ createOverlayFilesystem(options) {
136
+ const lowers = options.lowers.map((lower) => {
137
+ const state = getLayerState(lower);
138
+ if (state.kind !== "snapshot") {
139
+ throw new Error(`Layer ${lower.layerId} is not a snapshot`);
140
+ }
141
+ return lower;
142
+ });
143
+ if (options.mode === "read-only") {
144
+ return createOverlayBackend({
145
+ mode: "read-only",
146
+ lowers: lowers.map((lower) => {
147
+ const state = getLayerState(lower);
148
+ if (state.kind !== "snapshot") {
149
+ throw new Error(`Layer ${lower.layerId} is not a snapshot`);
150
+ }
151
+ return state.fs;
152
+ }),
153
+ });
154
+ }
155
+ const upperState = getLayerState(options.upper);
156
+ if (upperState.kind !== "writable") {
157
+ throw new Error(`Layer ${options.upper.layerId} is not writable`);
158
+ }
159
+ if (!upperState.valid || upperState.leaseId !== options.upper.leaseId) {
160
+ throw new Error(`Writable layer ${options.upper.layerId} is no longer valid`);
161
+ }
162
+ if (upperState.activeOverlay) {
163
+ throw new Error(`Writable layer ${options.upper.layerId} is already attached to an overlay`);
164
+ }
165
+ const overlay = createOverlayBackend({
166
+ upper: upperState.fs,
167
+ lowers: lowers.map((lower) => {
168
+ const state = getLayerState(lower);
169
+ if (state.kind !== "snapshot") {
170
+ throw new Error(`Layer ${lower.layerId} is not a snapshot`);
171
+ }
172
+ return state.fs;
173
+ }),
174
+ });
175
+ upperState.activeOverlay = overlay;
176
+ return overlay;
177
+ },
178
+ };
179
+ }
180
+ export function createDefaultRootLowerInput() {
181
+ return {
182
+ kind: "base-filesystem-artifact",
183
+ source: getBaseFilesystemSnapshot(),
184
+ };
185
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Overlay (copy-on-write) filesystem backend.
3
+ *
4
+ * Layers an optional writable upper filesystem over zero or more lower
5
+ * filesystems. Reads resolve from highest precedence to lowest. Writes
6
+ * go to the writable upper only, with copy-up and whiteout behavior.
7
+ */
8
+ import { type VirtualFileSystem } from "./runtime-compat.js";
9
+ export interface OverlayBackendOptions {
10
+ /** Legacy single lower layer. */
11
+ lower?: VirtualFileSystem;
12
+ /** Lower layers ordered highest-precedence first. */
13
+ lowers?: VirtualFileSystem[];
14
+ /** Writable upper layer. Defaults to a fresh in-memory filesystem in ephemeral mode. */
15
+ upper?: VirtualFileSystem;
16
+ /** Overlay mode. Defaults to ephemeral. */
17
+ mode?: "ephemeral" | "read-only";
18
+ }
19
+ export declare function createOverlayBackend(options: OverlayBackendOptions): VirtualFileSystem;