@codeworksh/harness 0.0.1-dev.20260825093030 → 0.0.1-dev.20260907170816

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.
@@ -0,0 +1,668 @@
1
+ import { Context, Effect, Layer, Option, Schema, Stream } from "effect";
2
+ //#region src/sandbox/errors.d.ts
3
+ declare const SandboxNotFoundError_base: Schema.Class<SandboxNotFoundError, Schema.TaggedStruct<"SandboxNotFoundError", {
4
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
5
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
6
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
7
+ };
8
+ }>, import("effect/Cause").YieldableError>;
9
+ /**
10
+ * Lifecycle errors are confined to the control plane. Once a mount succeeds,
11
+ * consumers continue to see only FileSystemError and ShellError.
12
+ */
13
+ declare class SandboxNotFoundError extends SandboxNotFoundError_base {}
14
+ declare const SandboxDriverNotRegisteredError_base: Schema.Class<SandboxDriverNotRegisteredError, Schema.TaggedStruct<"SandboxDriverNotRegisteredError", {
15
+ readonly driver: Schema.String;
16
+ readonly registered: Schema.optional<Schema.$Array<Schema.String>>;
17
+ }>, import("effect/Cause").YieldableError>;
18
+ declare class SandboxDriverNotRegisteredError extends SandboxDriverNotRegisteredError_base {}
19
+ declare const SandboxDriverRegistrationError_base: Schema.Class<SandboxDriverRegistrationError, Schema.TaggedStruct<"SandboxDriverRegistrationError", {
20
+ readonly driver: Schema.String;
21
+ readonly reason: Schema.String;
22
+ }>, import("effect/Cause").YieldableError>;
23
+ declare class SandboxDriverRegistrationError extends SandboxDriverRegistrationError_base {}
24
+ declare const SandboxDriverLoadError_base: Schema.Class<SandboxDriverLoadError, Schema.TaggedStruct<"SandboxDriverLoadError", {
25
+ readonly specifier: Schema.String;
26
+ readonly phase: Schema.Literals<readonly ["resolve", "import", "module", "api-version", "options", "factory", "registration"]>;
27
+ readonly driver: Schema.optional<Schema.String>;
28
+ readonly reason: Schema.String;
29
+ }>, import("effect/Cause").YieldableError>;
30
+ declare class SandboxDriverLoadError extends SandboxDriverLoadError_base {}
31
+ declare const SandboxBusyError_base: Schema.Class<SandboxBusyError, Schema.TaggedStruct<"SandboxBusyError", {
32
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
33
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
34
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
35
+ };
36
+ readonly refCount: Schema.Int;
37
+ }>, import("effect/Cause").YieldableError>;
38
+ declare class SandboxBusyError extends SandboxBusyError_base {}
39
+ declare const SandboxMustBeStoppedError_base: Schema.Class<SandboxMustBeStoppedError, Schema.TaggedStruct<"SandboxMustBeStoppedError", {
40
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
41
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
42
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
43
+ };
44
+ readonly status: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
45
+ }>, import("effect/Cause").YieldableError>;
46
+ declare class SandboxMustBeStoppedError extends SandboxMustBeStoppedError_base {}
47
+ declare const SandboxRemovedError_base: Schema.Class<SandboxRemovedError, Schema.TaggedStruct<"SandboxRemovedError", {
48
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
49
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
50
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
51
+ };
52
+ readonly removedAt: Schema.optional<Schema.DateTimeUtc>;
53
+ }>, import("effect/Cause").YieldableError>;
54
+ declare class SandboxRemovedError extends SandboxRemovedError_base {}
55
+ declare const SandboxUnavailError_base: Schema.Class<SandboxUnavailError, Schema.TaggedStruct<"SandboxUnavailError", {
56
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
57
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
58
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
59
+ };
60
+ readonly reason: Schema.String;
61
+ }>, import("effect/Cause").YieldableError>;
62
+ declare class SandboxUnavailError extends SandboxUnavailError_base {}
63
+ declare const SandboxUnsupportedError_base: Schema.Class<SandboxUnsupportedError, Schema.TaggedStruct<"SandboxUnsupportedError", {
64
+ readonly id: Schema.optional<Schema.brand<Schema.String, "SandboxInstance.ID"> & {
65
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
66
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
67
+ }>;
68
+ readonly driver: Schema.String;
69
+ readonly operation: Schema.String;
70
+ }>, import("effect/Cause").YieldableError>;
71
+ declare class SandboxUnsupportedError extends SandboxUnsupportedError_base {}
72
+ declare const SandboxTransitionConflictError_base: Schema.Class<SandboxTransitionConflictError, Schema.TaggedStruct<"SandboxTransitionConflictError", {
73
+ readonly id: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
74
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
75
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
76
+ };
77
+ readonly expected: Schema.$Array<Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>>;
78
+ readonly actual: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
79
+ }>, import("effect/Cause").YieldableError>;
80
+ declare class SandboxTransitionConflictError extends SandboxTransitionConflictError_base {}
81
+ declare const SandboxProviderError_base: Schema.Class<SandboxProviderError, Schema.TaggedStruct<"SandboxProviderError", {
82
+ readonly driver: Schema.String;
83
+ readonly operation: Schema.String;
84
+ readonly sanitized: Schema.Struct<{
85
+ readonly name: Schema.String;
86
+ readonly message: Schema.String;
87
+ readonly code: Schema.optional<Schema.String>;
88
+ }>;
89
+ }>, import("effect/Cause").YieldableError>;
90
+ /**
91
+ * A lifecycle failure safe to serialize, persist, or log.
92
+ *
93
+ * The raw SDK defect is deliberately absent from the schema. It is retained on
94
+ * a non-enumerable symbol by {@link providerError}, so Effect's default
95
+ * formatting and JSON serialization cannot expose credentials nested in it.
96
+ */
97
+ declare class SandboxProviderError extends SandboxProviderError_base {}
98
+ declare const providerErrorCause: (error: SandboxProviderError) => unknown;
99
+ declare const providerErrorIsNotFound: (error: SandboxProviderError) => boolean;
100
+ type Redactor = (value: string) => string;
101
+ /**
102
+ * Conservative text redaction shared by every driver sanitizer.
103
+ *
104
+ * Disclaimer: This can really leak. Its never safe
105
+ *
106
+ * Configured secrets are removed exactly. Common authorization/header and URL
107
+ * query shapes are masked as a second line of defence for values the caller did
108
+ * not explicitly seed.
109
+ *
110
+ * Note: add support for diff regex as needed.
111
+ */
112
+ declare const makeRedactor: (secrets?: Iterable<string>) => Redactor;
113
+ declare const sanitizeError: (cause: unknown, redact?: Redactor) => PersistedError;
114
+ declare const providerError: (input: {
115
+ readonly driver: string;
116
+ readonly operation: string;
117
+ readonly cause: unknown;
118
+ readonly redact?: Redactor;
119
+ readonly sanitize?: (cause: unknown, redact: Redactor) => PersistedError;
120
+ readonly notFound?: boolean;
121
+ }) => SandboxProviderError;
122
+ type SandboxMountError = SandboxNotFoundError | SandboxDriverNotRegisteredError | SandboxUnavailError | SandboxRemovedError | SandboxProviderError;
123
+ type SandboxCreateError = SandboxDriverNotRegisteredError | SandboxDriverRegistrationError | SandboxProviderError;
124
+ type SandboxRegisterError = SandboxDriverNotRegisteredError | SandboxDriverRegistrationError | SandboxUnsupportedError | SandboxProviderError;
125
+ type SandboxReadError = never;
126
+ type SandboxRefreshError = SandboxNotFoundError | SandboxDriverNotRegisteredError | SandboxUnavailError | SandboxUnsupportedError | SandboxProviderError;
127
+ type SandboxWakeError = SandboxRefreshError | SandboxRemovedError;
128
+ type SandboxStopError = SandboxWakeError | SandboxBusyError | SandboxTransitionConflictError;
129
+ type SandboxDestroyError = SandboxStopError | SandboxMustBeStoppedError;
130
+ declare namespace filesystem_d_exports {
131
+ export { FileStat, FileSystemError, Interface, OperationUnsupportedError, Provider, RmOptions, filesystem_d_exports as SandboxFileSystem, Service$1 as Service, fromProvider, isNotFoundError, validateRmOptions, withCwd };
132
+ }
133
+ declare const OperationUnsupportedError_base: Schema.Class<OperationUnsupportedError, Schema.TaggedStruct<"OperationUnsupportedError", {
134
+ readonly operation: Schema.String;
135
+ readonly message: Schema.String;
136
+ }>, import("effect/Cause").YieldableError>;
137
+ /**
138
+ * The runtime filesystem contract, independent of any backend.
139
+ *
140
+ * Two surfaces, deliberately:
141
+ * - {@link Provider} is what a backend implements — plain promises that reject,
142
+ * matching every SDK we wrap.
143
+ * - {@link Interface} is what the harness consumes — Effect with a typed error
144
+ * channel and tracing spans. {@link fromProvider} bridges the two exactly
145
+ * once, so no consumer ever writes `Effect.tryPromise` against a filesystem.
146
+ *
147
+ * Implementations:
148
+ * - Local:
149
+ * implement it over a VFS (`./local`);
150
+ * local filesystem use OS primitives; hence have broader filesytem capabilities.
151
+ *
152
+ * - Remote:
153
+ * implement it over a provider (`./remote`).
154
+ * remote filesytems depends on the interface provided by the remote provider; hence can have limited filesytem capabilities.
155
+ *
156
+ * `isFile`/`isDirectory` are required booleans; size, mtime, and isSymbolicLink are omitted when the
157
+ * backend cannot report them — never fabricated.
158
+ *
159
+ * **Paths are POSIX, and the harness is Unix-only (for now!).** Every path uses `/`
160
+ * separators on both the host and inside a sandbox — Windows is not supported,
161
+ * so no translation layer exists. Consumers must use the shared Effect POSIX
162
+ * path implementation, never the platform default, or a host running the harness would
163
+ * impose its own flavour on a remote sandbox's paths. Relative paths resolve
164
+ * against the backend's configured `cwd`.
165
+ */
166
+ declare class OperationUnsupportedError extends OperationUnsupportedError_base {}
167
+ declare const FileSystemError_base: Schema.Class<FileSystemError, Schema.TaggedStruct<"SandboxFileSystemError", {
168
+ readonly method: Schema.String;
169
+ readonly path: Schema.String;
170
+ readonly cause: Schema.optional<Schema.Defect>;
171
+ }>, import("effect/Cause").YieldableError>;
172
+ /** A backend operation failed. `cause` carries the provider's own rejection. */
173
+ declare class FileSystemError extends FileSystemError_base {}
174
+ interface FileStat {
175
+ readonly isFile: boolean;
176
+ readonly isDirectory: boolean;
177
+ readonly isSymbolicLink?: boolean;
178
+ readonly size?: number;
179
+ readonly mtime?: Date;
180
+ }
181
+ interface RmOptions {
182
+ readonly recursive?: boolean;
183
+ readonly force?: boolean;
184
+ }
185
+ /** Whether a provider failure means the path itself is definitively absent. */
186
+ declare const isNotFoundError: (cause: unknown) => boolean;
187
+ /**
188
+ * The backend-facing contract. Backends author plain promises and let them
189
+ * reject; {@link fromProvider} turns rejections into typed failures.
190
+ */
191
+ interface Provider {
192
+ readonly readFile: (path: string) => Promise<string>;
193
+ readonly readFileBuffer: (path: string) => Promise<Uint8Array>;
194
+ /**
195
+ * Write the file. Parents may be missing — do not create them here;
196
+ * {@link fromProvider} owns that guarantee for every backend.
197
+ */
198
+ readonly writeFile: (path: string, content: string | Uint8Array) => Promise<void>;
199
+ readonly stat: (path: string) => Promise<FileStat>;
200
+ readonly readdir: (path: string) => Promise<string[]>;
201
+ readonly exists: (path: string) => Promise<boolean>;
202
+ readonly mkdir: (path: string, options?: {
203
+ recursive?: boolean;
204
+ }) => Promise<void>;
205
+ readonly rm: (path: string, options?: RmOptions) => Promise<void>;
206
+ /**
207
+ * Metadata for the directory entry itself rather than a symlink's target.
208
+ * Optional: a backend whose `stat` has mixed symlink semantics implements it
209
+ * so symlink identity is asked for explicitly, never inferred.
210
+ */
211
+ readonly lstat?: (path: string) => Promise<FileStat>;
212
+ }
213
+ /**
214
+ * The consumer-facing contract. `exists` distinguishes "absent" from "could not
215
+ * tell": a backend failure is a typed failure, not `false`, so a caller acting
216
+ * on absence never acts on a network blip. Use `SandboxFs.existsOrFalse` where
217
+ * a best-effort answer really is wanted.
218
+ */
219
+ interface Interface {
220
+ readonly readFile: (path: string) => Effect.Effect<string, FileSystemError>;
221
+ readonly readFileBuffer: (path: string) => Effect.Effect<Uint8Array, FileSystemError>;
222
+ /** Creates missing parent directories, on every backend. */
223
+ readonly writeFile: (path: string, content: string | Uint8Array) => Effect.Effect<void, FileSystemError>;
224
+ readonly stat: (path: string) => Effect.Effect<FileStat, FileSystemError>;
225
+ readonly readdir: (path: string) => Effect.Effect<string[], FileSystemError>;
226
+ readonly exists: (path: string) => Effect.Effect<boolean, FileSystemError>;
227
+ readonly mkdir: (path: string, options?: {
228
+ recursive?: boolean;
229
+ }) => Effect.Effect<void, FileSystemError>;
230
+ readonly rm: (path: string, options?: RmOptions) => Effect.Effect<void, FileSystemError | OperationUnsupportedError>;
231
+ readonly lstat?: (path: string) => Effect.Effect<FileStat, FileSystemError>;
232
+ }
233
+ declare const Service_base$1: Context.ServiceClass<Service$1, "@codeworksh/harness/sandbox/fs/filesystem/Service", Interface>;
234
+ /** The runtime filesystem service — the live {@link Interface} for the active sandbox. */
235
+ declare class Service$1 extends Service_base$1 {}
236
+ /**
237
+ * Reject `rm` options a provider does not implement, before any mutation. Only
238
+ * `recursive` and `force` are part of the contract; anything else is refused
239
+ * loudly rather than silently ignored.
240
+ */
241
+ declare const validateRmOptions: (options: RmOptions | undefined, operation?: string) => Effect.Effect<void, OperationUnsupportedError>;
242
+ /**
243
+ * Lift a {@link Provider} into the runtime {@link Interface}: one place that
244
+ * converts rejections into {@link FileSystemError}, validates `rm` options,
245
+ * creates missing parents on write, and names a tracing span per operation.
246
+ */
247
+ declare const fromProvider: (provider: Provider) => Interface;
248
+ /**
249
+ * Bind a cwd-neutral filesystem to one mount's working directory.
250
+ *
251
+ * The counterpart of `Shell.withCwd`, and the reason relative paths mean the
252
+ * same thing to both: a shared transport stays rooted at the namespace root, so
253
+ * resolution happens here, per mount, rather than inside a VFS whose `chdir` is
254
+ * global state two mounts would fight over.
255
+ */
256
+ declare const withCwd: (fs: Interface, cwd: string) => Interface;
257
+ //#endregion
258
+ //#region src/sandbox/shell/shell.d.ts
259
+ declare const ShellError_base: Schema.Class<ShellError, Schema.TaggedStruct<"ShellError", {
260
+ readonly command: Schema.String;
261
+ readonly cause: Schema.optional<Schema.Defect>;
262
+ }>, import("effect/Cause").YieldableError>;
263
+ /**
264
+ * The pluggable execution contract. Local sandboxes usually get a Shell through
265
+ * just-bash over the local `Local.Vfs`; remote sandboxes provide their own
266
+ * native Shell. Either way the rest of the harness depends only on this service
267
+ * tag.
268
+ */
269
+ declare class ShellError extends ShellError_base {}
270
+ interface ExecResult {
271
+ readonly stdout: string;
272
+ readonly stderr: string;
273
+ readonly exitCode: number;
274
+ }
275
+ /**
276
+ * One options shape for every entry point. `cwd` is the operation-level
277
+ * override: it wins over the mount's working directory, and a relative value
278
+ * resolves against it. Neither mutates shared state, so concurrent commands in
279
+ * one mount can run in different directories.
280
+ */
281
+ interface ShellOptions {
282
+ readonly env?: Record<string, string>;
283
+ readonly cwd?: string;
284
+ }
285
+ /**
286
+ * A streamed chunk of command output, terminated by a single `exit` carrying the
287
+ * exit code. (A backend-level mirror of the tool layer's event; kept here so
288
+ * `sandbox/` does not depend on `tools/`.)
289
+ */
290
+ type ExecChunk = {
291
+ readonly _tag: "stdout";
292
+ readonly bytes: Uint8Array;
293
+ } | {
294
+ readonly _tag: "stderr";
295
+ readonly bytes: Uint8Array;
296
+ } | {
297
+ readonly _tag: "exit";
298
+ readonly exitCode: number;
299
+ };
300
+ /**
301
+ * The command-execution capability a sandbox exposes. For an in-process
302
+ * backend this is just-bash; for a remote backend it is the sandbox's own
303
+ * shell. The {@link Shell} service tag carries this interface.
304
+ */
305
+ interface ISandboxExe {
306
+ readonly exec: (command: string, options?: ShellOptions) => Effect.Effect<ExecResult, ShellError>;
307
+ /**
308
+ * Run a program with an explicit argument vector, bypassing shell word
309
+ * splitting. Callers that build commands from untrusted values — branch
310
+ * names, file paths — must use this instead of interpolating into
311
+ * {@link exec}, where a space or `$(…)` would change what runs.
312
+ *
313
+ * Backends whose transport only accepts a string quote the vector with
314
+ * {@link quote}; backends that spawn directly pass it through untouched.
315
+ */
316
+ readonly execArgv: (argv: ReadonlyArray<string>, options?: ShellOptions) => Effect.Effect<ExecResult, ShellError>;
317
+ /**
318
+ * Optional streaming output: stdout/stderr chunks then a terminal `exit`.
319
+ * Backends that can stream (e.g. Vercel) implement it; `ToolShell.fromSandboxShell`
320
+ * bridges it to `ToolShell.stream` so the bash tool streams over them too.
321
+ */
322
+ readonly stream?: (command: string, options?: ShellOptions) => Stream.Stream<ExecChunk, ShellError>;
323
+ }
324
+ /**
325
+ * POSIX single-quote escaping: wrap in `'…'` and rewrite each embedded quote as
326
+ * `'\''`. Everything inside single quotes is literal to the shell, so this is
327
+ * safe for arbitrary bytes.
328
+ */
329
+ declare const quote: (value: string) => string;
330
+ /** Render an argument vector as one shell-safe command string. */
331
+ declare const quoteArgv: (argv: ReadonlyArray<string>) => string;
332
+ /**
333
+ * Complete a string-only backend: `execArgv` quotes the vector and runs it
334
+ * through `exec`. Backends that spawn a real argument vector (Vercel) implement
335
+ * `execArgv` themselves instead, so the args never meet a shell parser at all.
336
+ *
337
+ * `cwd` rides the options rather than a `cd <dir> && …` prefix. Every backend
338
+ * we wrap takes a working directory natively, and the prefix form cannot tell a
339
+ * failed `cd` from a failed command — both arrive as one exit code.
340
+ */
341
+ declare const fromExec: (backend: Omit<ISandboxExe, "execArgv">) => ISandboxExe;
342
+ declare const Shell_base: Context.ServiceClass<Shell$1, "@codeworksh/harness/sandbox/shell/shell", ISandboxExe>;
343
+ /** Execution service — the live {@link ISandboxExe} for the active sandbox. */
344
+ declare class Shell$1 extends Shell_base {}
345
+ //#endregion
346
+ //#region src/sandbox/io.d.ts
347
+ /**
348
+ * `SandboxIO` is a **mount**: a filesystem, a shell, and the identity and
349
+ * working directory they act on.
350
+ *
351
+ * It is the whole vocabulary a consumer needs. Project, Git, Copy, Location, and
352
+ * every tool ask for `SandboxIO.FileSystem`, `SandboxIO.Shell`, and
353
+ * `SandboxIO.Current` — never for a driver, an address, or a provider SDK — so
354
+ * a host directory, an in-memory VFS, and a remote microVM are interchangeable
355
+ * behind one contract.
356
+ *
357
+ * The mount neither creates nor destroys infrastructure. `SandboxInstance` is
358
+ * the durable namespace it acts on — a device, which exists whether or not
359
+ * anything has it mounted — and `Sandbox.Controller` is the only path that
360
+ * creates, stops, or destroys one.
361
+ */
362
+ /**
363
+ * The filesystem tag. Re-exported here so consumers import one namespace —
364
+ * Project, Git, Copy, and the runner ask for `SandboxIO.FileSystem`, never for
365
+ * the module that happens to define it. Code *inside* `sandbox/` keeps importing
366
+ * the tag directly, since `io.ts` is built on top of it.
367
+ */
368
+ declare const FileSystem$1: typeof Service$1;
369
+ type FileSystem$1 = Service$1;
370
+ /** The shell tag. Re-exported here so consumers import one namespace. */
371
+ declare const Shell: typeof Shell$1;
372
+ type Shell = Shell$1;
373
+ /**
374
+ * What a mount sees: immutable identity, plus the working directory resolved for
375
+ * *this* mount.
376
+ *
377
+ * Nothing mutable belongs here. `status`, `usage`, and reference counts all
378
+ * change while a mount is open, so a mount-time snapshot of them would be wrong
379
+ * by construction — runtime code that needs live management state asks the
380
+ * control plane. The driver's own resource locator is likewise absent: consumers
381
+ * never parse a Vercel name or a Daytona id.
382
+ */
383
+ interface Identity {
384
+ readonly id: ID;
385
+ readonly driver: Name;
386
+ readonly kind: Kind;
387
+ /** Absolute, and always a path in *this* namespace. */
388
+ readonly cwd: string;
389
+ }
390
+ declare const Current_base: Context.ServiceClass<Current, "@codeworksh/harness/sandbox/io/Current", Identity>;
391
+ /** Identity and working directory of the current mount. */
392
+ declare class Current extends Current_base {}
393
+ /** Everything a mount provides. */
394
+ type Provides = Current | Service$1 | Shell$1;
395
+ /** A built mount. */
396
+ type Layer$1<E = never, RIn = never> = Layer.Layer<Provides, E, RIn>;
397
+ //#endregion
398
+ //#region src/sandbox/driver.d.ts
399
+ /** Version of the loadable sandbox-driver module ABI. */
400
+ declare const apiVersion: 1;
401
+ type ApiVersion = typeof apiVersion;
402
+ /** Open driver identity. Adding a driver never extends a union in core. */
403
+ declare const Name: Schema.brand<Schema.String, "SandboxDriver.Name">;
404
+ type Name = typeof Name.Type;
405
+ /** A path whose coordinate system is the mounted namespace. */
406
+ declare const AbsolutePath: Schema.brand<Schema.String, "SandboxDriver.AbsolutePath">;
407
+ type AbsolutePath = typeof AbsolutePath.Type;
408
+ declare const RuntimeConfigBase: Schema.Struct<{
409
+ readonly defaultCwd: Schema.brand<Schema.String, "SandboxDriver.AbsolutePath">;
410
+ }>;
411
+ interface RuntimeConfigBase extends Schema.Schema.Type<typeof RuntimeConfigBase> {}
412
+ interface Capabilities {
413
+ readonly inspect: boolean;
414
+ readonly reattach: boolean;
415
+ readonly wake: boolean;
416
+ readonly stop: boolean;
417
+ readonly destroy: boolean;
418
+ readonly cancels: boolean;
419
+ }
420
+ interface Observed {
421
+ readonly status: Status;
422
+ readonly providerStatus?: string | undefined;
423
+ readonly metadata?: Readonly<Record<string, string>> | undefined;
424
+ }
425
+ interface Provisioned<RuntimeConfig extends RuntimeConfigBase> {
426
+ readonly providerResourceId?: string | undefined;
427
+ readonly providerStatus?: string | undefined;
428
+ readonly runtimeConfig: RuntimeConfig;
429
+ readonly metadata?: Readonly<Record<string, string>> | undefined;
430
+ }
431
+ interface RuntimeInput<RuntimeConfig extends RuntimeConfigBase> {
432
+ readonly id: ID;
433
+ readonly providerResourceId: Option.Option<string>;
434
+ readonly runtimeConfig: RuntimeConfig;
435
+ }
436
+ interface Driver<CreateConfig, RuntimeConfig extends RuntimeConfigBase> {
437
+ readonly name: Name;
438
+ readonly kind: Exclude<Kind, "local">;
439
+ readonly capabilities: Capabilities;
440
+ readonly createConfigCodec: Schema.Codec<CreateConfig, unknown>;
441
+ readonly runtimeConfigCodec: Schema.Codec<RuntimeConfig, unknown>;
442
+ readonly create: (input: {
443
+ readonly instanceId: ID;
444
+ readonly config: CreateConfig;
445
+ }) => Effect.Effect<Provisioned<RuntimeConfig>, SandboxProviderError>;
446
+ readonly runtimeConfigFor?: ((input: {
447
+ readonly providerResourceId: string;
448
+ readonly overrides?: Partial<RuntimeConfig> | undefined;
449
+ }) => Effect.Effect<RuntimeConfig, SandboxProviderError>) | undefined;
450
+ readonly attach: (input: RuntimeInput<RuntimeConfig>) => Layer.Layer<FileSystem$1 | Shell, SandboxProviderError>;
451
+ readonly inspect?: (input: RuntimeInput<RuntimeConfig>) => Effect.Effect<Observed, SandboxProviderError>;
452
+ readonly wake?: (input: RuntimeInput<RuntimeConfig>) => Effect.Effect<Observed, SandboxProviderError>;
453
+ readonly stop?: (input: RuntimeInput<RuntimeConfig>) => Effect.Effect<Observed, SandboxProviderError>;
454
+ readonly destroy?: (input: RuntimeInput<RuntimeConfig>) => Effect.Effect<void, SandboxProviderError>;
455
+ }
456
+ type Definition<CreateConfig, RuntimeConfig extends RuntimeConfigBase> = Pick<Driver<CreateConfig, RuntimeConfig>, "name" | "createConfigCodec" | "runtimeConfigCodec">;
457
+ /** Registry-only erased shape. Driver authors construct it via {@link driver}. */
458
+ interface Registered {
459
+ readonly name: Name;
460
+ readonly kind: Exclude<Kind, "local">;
461
+ readonly capabilities: Capabilities;
462
+ readonly createConfigCodec: Schema.Codec<unknown, unknown>;
463
+ readonly runtimeConfigCodec: Schema.Codec<RuntimeConfigBase, unknown>;
464
+ readonly create: (input: {
465
+ readonly instanceId: ID;
466
+ readonly config: unknown;
467
+ }) => Effect.Effect<Provisioned<RuntimeConfigBase>, SandboxProviderError>;
468
+ readonly runtimeConfigFor?: ((input: {
469
+ readonly providerResourceId: string;
470
+ readonly overrides?: Readonly<Record<string, unknown>> | undefined;
471
+ }) => Effect.Effect<RuntimeConfigBase, SandboxProviderError>) | undefined;
472
+ readonly attach: (input: RuntimeInput<RuntimeConfigBase>) => Layer.Layer<FileSystem$1 | Shell, SandboxProviderError>;
473
+ readonly inspect?: (input: RuntimeInput<RuntimeConfigBase>) => Effect.Effect<Observed, SandboxProviderError>;
474
+ readonly wake?: (input: RuntimeInput<RuntimeConfigBase>) => Effect.Effect<Observed, SandboxProviderError>;
475
+ readonly stop?: (input: RuntimeInput<RuntimeConfigBase>) => Effect.Effect<Observed, SandboxProviderError>;
476
+ readonly destroy?: (input: RuntimeInput<RuntimeConfigBase>) => Effect.Effect<void, SandboxProviderError>;
477
+ }
478
+ type Source = "core" | "builtin" | "package" | "file";
479
+ interface Registration {
480
+ readonly registered: Registered;
481
+ readonly apiVersion: ApiVersion;
482
+ readonly source: Source;
483
+ }
484
+ interface Module<Options> {
485
+ readonly apiVersion: ApiVersion;
486
+ readonly name: Name;
487
+ readonly options: Schema.Codec<Options, unknown>;
488
+ readonly make: (options: Options) => Registration;
489
+ }
490
+ interface ModuleDefinition<Options> {
491
+ readonly apiVersion: ApiVersion;
492
+ readonly name: string | Name;
493
+ readonly options: Schema.Codec<Options, unknown>;
494
+ readonly make: (options: Options) => Registration;
495
+ }
496
+ /** Define the default export of a loadable sandbox package. */
497
+ declare const defineModule: <Options>(value: ModuleDefinition<Options>) => Module<Options>;
498
+ /** Construct a driver and its registry contribution. */
499
+ declare const driver: <CreateConfig, RuntimeConfig extends RuntimeConfigBase>(value: Driver<CreateConfig, RuntimeConfig>) => Driver<CreateConfig, RuntimeConfig> & Registration;
500
+ declare namespace instance_d_exports {
501
+ export { ID, Info, Kind, Ownership, PersistedError, instance_d_exports as SandboxInstance, Status, Usage, fromColumn, fromField, isMountable, mountable, toColumn, toField };
502
+ }
503
+ /**
504
+ * A Sandbox instance is a **durable filesystem namespace** plus whatever compute
505
+ * acts on it — a device in Unix terms, which exists whether or not anything has
506
+ * it mounted. `Sandbox.Controller` is the only thing that creates,
507
+ * stops, or destroys one; this module is just its identity and state model.
508
+ *
509
+ * The application ID is deliberately separate from the driver's own resource
510
+ * locator: callers never parse a Vercel name or a Daytona ID, driver formats may
511
+ * change, and a destroyed resource must stay identifiable in Project/Session
512
+ * history. A missing resource is never recreated under an existing ID — a new
513
+ * resource is a new namespace and therefore a new ID.
514
+ */
515
+ declare const ID: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
516
+ /**
517
+ * The host. Reserved, and never written to a column — see {@link toColumn}.
518
+ * It exists at runtime so nothing has to branch on "is this the host": it is
519
+ * what identity reads, what logs show, and what the transport cache keys on.
520
+ */
521
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
522
+ /** A fresh identity for a namespace nothing has named yet. */
523
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
524
+ };
525
+ type ID = typeof ID.Type;
526
+ /**
527
+ * The storage boundary for namespace references, in one place.
528
+ *
529
+ * The host filesystem exists whether or not a row describes it, so it gets no
530
+ * row and `NULL` is the only spelling of it — the Unix analogue is exact, since
531
+ * `/` has no entry in the mount table you consult to find other mounts. That
532
+ * makes a session or directory writable before any namespace is registered (the
533
+ * foreign key is skipped on NULL), makes `SET sandbox_instance_id = NULL` a
534
+ * meaningful "revert to the host", and leaves the host impossible to tombstone,
535
+ * collect, or destroy, because there is nothing to point at.
536
+ *
537
+ * Two SQLite consequences ride on this and break correctness silently if missed:
538
+ * unique indexes treat NULLs as distinct, so every uniqueness constraint
539
+ * spanning a namespace column coalesces to `'local'`; and `= NULL` never
540
+ * matches, so namespace-scoped reads use `IS`.
541
+ */
542
+ declare const toColumn: (id: ID) => string | null;
543
+ declare const fromColumn: (value: string | null) => ID;
544
+ /**
545
+ * The same mapping for row models, whose optional columns are `Option` rather
546
+ * than `null`. Kept beside {@link toColumn} so the boundary stays one place:
547
+ * `toColumn`/`fromColumn` for SQL parameters, these for `Model.FieldOption`.
548
+ */
549
+ declare const toField: (id: ID) => Option.Option<ID>;
550
+ declare const fromField: (value: Option.Option<ID>) => ID;
551
+ /**
552
+ * Filesystem-class taxonomy, mirroring Unix: disk, tmpfs/procfs, NFS/CIFS.
553
+ * Stored on the row rather than derived from the registered driver, so reading
554
+ * an instance never depends on the registry — which matters most when a driver
555
+ * is *not* configured and you need to list or clean up its rows.
556
+ */
557
+ declare const Kind: Schema.Literals<readonly ["local", "virtual", "remote"]>;
558
+ type Kind = typeof Kind.Type;
559
+ declare const Ownership: Schema.Literals<readonly ["managed", "external"]>;
560
+ type Ownership = typeof Ownership.Type;
561
+ /**
562
+ * Lifecycle state, in ZFS pool vocabulary. This is the **last observed** value,
563
+ * not live driver truth: Daytona auto-stops and auto-archives, Vercel sandboxes
564
+ * expire on their own timeout, so drift is normal. `stateObservedAt` carries the
565
+ * freshness and `Controller.refresh` updates it without waking anything.
566
+ *
567
+ * `removed` and `unavail` are deliberately distinct. `removed` means we deleted
568
+ * it; `unavail` means the driver claims it is gone. A "not found" is frequently a
569
+ * misclassification — wrong region, wrong API url, a revoked key answering 404,
570
+ * eventual consistency right after create — so it must never be recorded as if we
571
+ * had destroyed the resource ourselves.
572
+ */
573
+ declare const Status: Schema.Literals<readonly ["provisioning", "online", "offline", "suspending", "removing", "removed", "unavail", "faulted"]>;
574
+ type Status = typeof Status.Type;
575
+ /**
576
+ * The statuses a `mount` may proceed from. This is the predicate every
577
+ * conditional write depends on, so it is enumerated once here rather than
578
+ * restated as prose at each call site.
579
+ *
580
+ * `offline` qualifies because mounting wakes.
581
+ * `faulted` qualifies because a fault is a *usability* condition, not an identity one — see {@link Status}.
582
+ *
583
+ * There is no `resuming`: it would exist to be observed by nothing, since
584
+ * mounting wakes, `offline` is already mountable, and waking is not destructive
585
+ * so it needs no claim. `suspending` and `removing` stay because they *are*
586
+ * compare-and-set claims, blocking a concurrent mount mid-destruction.
587
+ */
588
+ declare const mountable: ReadonlySet<Status>;
589
+ declare const isMountable: (status: Status) => boolean;
590
+ /**
591
+ * Reference state, derived — never stored. `busy` carries its `umount` meaning:
592
+ * something holds this and destruction must not proceed unforced.
593
+ *
594
+ * `pinned` is the kernel sense of the word: never reclaimable. It short-circuits
595
+ * counting entirely for instances that cannot be stopped or destroyed (the local
596
+ * host), which is what keeps them out of any future collector by construction
597
+ * rather than by an ownership check happening to catch them.
598
+ */
599
+ declare const Usage: Schema.Literals<readonly ["idle", "busy", "pinned"]>;
600
+ type Usage = typeof Usage.Type;
601
+ /** Sanitized driver failure. The only error shape allowed to be persisted or logged. */
602
+ declare const PersistedError: Schema.Struct<{
603
+ readonly name: Schema.String;
604
+ readonly message: Schema.String;
605
+ readonly code: Schema.optional<Schema.String>;
606
+ }>;
607
+ type PersistedError = typeof PersistedError.Type;
608
+ /** Durable metadata, safe to return and persist. Assembled by the control plane. */
609
+ interface Info {
610
+ readonly id: ID;
611
+ readonly driver: Name;
612
+ readonly kind: Kind;
613
+ readonly providerResourceId: Option.Option<string>;
614
+ readonly ownership: Ownership;
615
+ readonly status: Status;
616
+ readonly usage: Usage;
617
+ /** References held by *this* control plane. Process-local; see the transport cache. */
618
+ readonly refCount: number;
619
+ readonly providerStatus: Option.Option<string>;
620
+ readonly metadata: Readonly<Record<string, string>>;
621
+ readonly lastError: Option.Option<PersistedError>;
622
+ readonly createdAt: Date;
623
+ readonly updatedAt: Date;
624
+ readonly stateObservedAt: Date;
625
+ readonly lastMountedAt: Option.Option<Date>;
626
+ readonly lastUnmountedAt: Option.Option<Date>;
627
+ readonly lastUsedAt: Option.Option<Date>;
628
+ readonly removedAt: Option.Option<Date>;
629
+ }
630
+ declare namespace driver_d_exports {
631
+ export { AbsolutePath, ApiVersion, Capabilities, Definition, Driver, Module, ModuleDefinition, Name, Observed, Provisioned, Registration, RuntimeConfigBase as RuntimeConfig, RuntimeConfigBase, RuntimeInput, driver_d_exports as SandboxDriver, apiVersion, driver, defineModule as module };
632
+ }
633
+ declare namespace io_d_exports {
634
+ export { Current, FileSystem$1 as FileSystem, Identity, Layer$1 as Layer, Provides, io_d_exports as SandboxIO, Shell };
635
+ }
636
+ declare namespace error_d_exports {
637
+ export { Redactor, SandboxProviderError, makeRedactor, providerError, providerErrorCause, providerErrorIsNotFound, sanitizeError };
638
+ }
639
+ declare namespace resource_d_exports {
640
+ export { resource_d_exports as SandboxResource, Service };
641
+ }
642
+ declare const Service_base: Context.ServiceClass<Service, "@codeworksh/harness/sandbox/resource/Service", {
643
+ readonly providerResourceId: string;
644
+ }>;
645
+ /**
646
+ * The driver's own locator for the attached resource — a Vercel sandbox name, a
647
+ * Daytona sandbox id.
648
+ *
649
+ * Deliberately *not* on `SandboxIO.Current`: consumers never parse one,
650
+ * and keeps it separate from the application id precisely so a driver's format can
651
+ * change without touching identity.
652
+ *
653
+ * It exists for the control plane, which records it as `provider_resource_id`,
654
+ * and for tests that reattach to the same resource.
655
+ *
656
+ * One tag for every driver rather than one per driver. A mount has exactly one
657
+ * driver, so there is nothing to disambiguate, and the control plane has to read
658
+ * the locator without knowing which driver produced it — keeps the
659
+ * driver name open, so anything keyed on a closed `"vercel" | "daytona"` set is
660
+ * a bug waiting for the third driver.
661
+ */
662
+ declare class Service extends Service_base {}
663
+ declare namespace shell_d_exports {
664
+ export { ExecChunk, ExecResult, ISandboxExe, Shell$1 as Shell, ShellError, ShellOptions, fromExec, quote, quoteArgv };
665
+ }
666
+ //#endregion
667
+ export { SandboxDriverNotRegisteredError as A, Layer$1 as C, SandboxCreateError as D, filesystem_d_exports as E, SandboxRegisterError as F, SandboxStopError as I, SandboxWakeError as L, SandboxMountError as M, SandboxReadError as N, SandboxDestroyError as O, SandboxRefreshError as P, Identity as S, FileSystemError as T, Name as _, driver_d_exports as a, RuntimeConfigBase as b, Status as c, AbsolutePath as d, ApiVersion as f, Module as g, Driver as h, io_d_exports as i, SandboxDriverRegistrationError as j, SandboxDriverLoadError as k, Usage as l, Definition as m, resource_d_exports as n, ID as o, Capabilities as p, error_d_exports as r, Info as s, shell_d_exports as t, instance_d_exports as u, Registered as v, Provides as w, Source as x, Registration as y };
668
+ //# sourceMappingURL=sandbox-DnL9UPzZ.d.mts.map