@effect-agent/sandbox-local 0.1.0-beta.91 → 0.1.0-beta.92

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.
@@ -52,7 +52,7 @@ const exitError = (message, cause, exitCode = -1) => SandboxExitError.make({
52
52
  const environmentFromAllowlist = Effect.fn("LocalSandbox.environmentFromAllowlist")(function* (request) {
53
53
  const environment = {};
54
54
  for (const name of request.environment.allow) {
55
- const value = yield* Config.option(Config.string(name)).pipe(Effect.mapError((error) => spawnError(request, `Could not read allowed environment variable '${name}': ${error.message}`, error)));
55
+ const value = yield* Config.option(Config.String(name)).pipe(Effect.mapError((error) => spawnError(request, `Could not read allowed environment variable '${name}': ${error.message}`, error)));
56
56
  if (Option.isSome(value)) environment[name] = value.value;
57
57
  }
58
58
  return environment;
@@ -1 +1 @@
1
- {"version":3,"file":"LocalSandbox.mjs","names":[],"sources":["../src/LocalSandbox.ts"],"sourcesContent":["import { NodeServices } from \"@effect/platform-node\";\nimport { Clock, Config, Duration, Effect, Layer, Option, Ref, Stream } from \"effect\";\nimport {\n SANDBOX_DIAGNOSTIC_MAX_LENGTH,\n Sandbox,\n SandboxExited,\n SandboxExitError,\n SandboxImplementation,\n SandboxOutput,\n SandboxOutputLimitError,\n SandboxResourceUse,\n SandboxSpawnError,\n SandboxStarted,\n SandboxTimeoutError,\n SandboxUnsupportedRequestError,\n type SandboxEvent,\n type SandboxExecute,\n type SandboxRequest,\n} from \"effect-agent/sandbox\";\nimport { ChildProcess } from \"effect/unstable/process\";\nimport { ChildProcessSpawner } from \"effect/unstable/process/ChildProcessSpawner\";\n\n/**\n * The only implementation identity produced by this package. It deliberately states that local\n * process execution is unisolated development tooling, not a security sandbox.\n */\nexport const unisolatedImplementation = SandboxImplementation.make({\n isolation: \"unisolated\",\n identity: \"local-process\",\n});\n\ntype OutputStream = \"stdout\" | \"stderr\";\ntype OutputCounts = Readonly<Record<OutputStream, number>>;\n\nconst zeroOutput: OutputCounts = { stdout: 0, stderr: 0 };\n\nconst boundedDiagnostic = (message: string): string =>\n message.slice(0, SANDBOX_DIAGNOSTIC_MAX_LENGTH);\n\nconst unsupported = (\n feature: Parameters<typeof SandboxUnsupportedRequestError.make>[0][\"feature\"],\n message: string,\n) =>\n SandboxUnsupportedRequestError.make({\n implementation: unisolatedImplementation,\n feature,\n message: boundedDiagnostic(message),\n });\n\nconst validateRequest = Effect.fn(\"LocalSandbox.validateRequest\")(function* (\n request: SandboxRequest,\n) {\n if (\n request.runtime.kind !== \"unisolated-process\" ||\n request.runtime.identity !== unisolatedImplementation.identity\n ) {\n return yield* unsupported(\n \"runtime\",\n \"The local process runner only accepts runtime kind 'unisolated-process' with identity 'local-process'.\",\n );\n }\n if (request.mounts.length > 0) {\n return yield* unsupported(\n \"mounts\",\n \"The unisolated local process runner cannot enforce mount access modes.\",\n );\n }\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* unsupported(\n \"network\",\n \"The unisolated local process runner cannot enforce workload network policy.\",\n );\n }\n if (request.limits.cpuCores !== undefined) {\n return yield* unsupported(\n \"cpu-limit\",\n \"The unisolated local process runner cannot enforce CPU limits.\",\n );\n }\n if (request.limits.memoryBytes !== undefined) {\n return yield* unsupported(\n \"memory-limit\",\n \"The unisolated local process runner cannot enforce memory limits.\",\n );\n }\n if (request.secretHandles.length > 0) {\n return yield* unsupported(\n \"secret-handles\",\n \"The unisolated local process runner does not resolve secret handles into an environment.\",\n );\n }\n if (request.artifactRules.length > 0) {\n return yield* unsupported(\n \"artifacts\",\n \"The unisolated local process runner does not collect artifacts.\",\n );\n }\n});\n\nconst spawnError = (request: SandboxRequest, message: string, cause?: unknown) =>\n SandboxSpawnError.make({\n implementation: unisolatedImplementation,\n command: request.command,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst exitError = (message: string, cause?: unknown, exitCode = -1) =>\n SandboxExitError.make({\n implementation: unisolatedImplementation,\n exitCode,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst environmentFromAllowlist = Effect.fn(\"LocalSandbox.environmentFromAllowlist\")(function* (\n request: SandboxRequest,\n) {\n const environment: Record<string, string> = {};\n\n for (const name of request.environment.allow) {\n const value = yield* Config.option(Config.string(name)).pipe(\n Effect.mapError((error) =>\n spawnError(\n request,\n `Could not read allowed environment variable '${name}': ${error.message}`,\n error,\n ),\n ),\n );\n\n if (Option.isSome(value)) {\n environment[name] = value.value;\n }\n }\n\n return environment;\n});\n\nconst outputEvent = (\n counts: Ref.Ref<OutputCounts>,\n stream: OutputStream,\n bytes: Uint8Array,\n decoder: TextDecoder,\n limit: number,\n): Effect.Effect<SandboxOutput, SandboxOutputLimitError> =>\n Ref.modify(counts, (current) => {\n const streamBytes = current[stream] + bytes.byteLength;\n const next = { ...current, [stream]: streamBytes };\n\n return [next.stdout + next.stderr, next] as const;\n }).pipe(\n Effect.flatMap((observed) =>\n observed > limit\n ? Effect.fail(\n SandboxOutputLimitError.make({\n implementation: unisolatedImplementation,\n stream,\n limit,\n observed,\n }),\n )\n : Effect.succeed(\n SandboxOutput.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n stream,\n text: decoder.decode(bytes, { stream: true }),\n bytes: bytes.byteLength,\n }),\n ),\n ),\n );\n\n/**\n * Emits any text the streaming decoder still holds once its source stream ends. The final decode\n * must run at end-of-stream, not at pipeline construction, so the flush is suspended; a trailing\n * incomplete UTF-8 sequence surfaces as replacement text. Its raw bytes were already counted when\n * the chunk arrived, so the flush event carries zero bytes.\n */\nconst flushDecoder = (stream: OutputStream, decoder: TextDecoder): Stream.Stream<SandboxOutput> =>\n Stream.suspend(() => {\n const text = decoder.decode();\n\n return text.length === 0\n ? Stream.empty\n : Stream.succeed(\n SandboxOutput.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n stream,\n text,\n bytes: 0,\n }),\n );\n });\n\nconst makeExecute =\n (spawner: ChildProcessSpawner[\"Service\"]): SandboxExecute =>\n (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* validateRequest(request);\n const startedAt = yield* Clock.currentTimeMillis;\n const counts = yield* Ref.make(zeroOutput);\n const stdoutDecoder = new TextDecoder();\n const stderrDecoder = new TextDecoder();\n const environment = yield* environmentFromAllowlist(request);\n\n const command = ChildProcess.make(request.command, request.args, {\n cwd: request.cwd,\n env: environment,\n extendEnv: false,\n stdout: \"pipe\",\n stderr: \"pipe\",\n });\n\n const child = yield* spawner\n .spawn(command)\n .pipe(Effect.mapError((error) => spawnError(request, error.message, error)));\n\n const streamOutput = (stream: OutputStream, decoder: TextDecoder) => {\n const source = stream === \"stdout\" ? child.stdout : child.stderr;\n\n return source.pipe(\n Stream.mapError((error) => exitError(error.message, error)),\n Stream.mapEffect((bytes) =>\n outputEvent(counts, stream, bytes, decoder, request.limits.maxOutputBytes),\n ),\n Stream.concat(flushDecoder(stream, decoder)),\n );\n };\n\n const terminal = Stream.unwrap(\n Effect.gen(function* () {\n const exitCode = yield* child.exitCode.pipe(\n Effect.mapError((error) => exitError(error.message, error)),\n );\n\n const endedAt = yield* Clock.currentTimeMillis;\n const output = yield* Ref.get(counts);\n\n const resourceUse = SandboxResourceUse.make({\n wallTime: Duration.millis(endedAt - startedAt),\n stdoutBytes: output.stdout,\n stderrBytes: output.stderr,\n });\n\n const exited = SandboxExited.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n exitCode,\n resourceUse,\n artifacts: [],\n });\n\n return exitCode === 0\n ? Stream.succeed<SandboxEvent>(exited)\n : Stream.concat(\n Stream.succeed<SandboxEvent>(exited),\n Stream.fail(\n exitError(\n `Unisolated local process exited with code ${exitCode}.`,\n undefined,\n exitCode,\n ),\n ),\n );\n }),\n );\n\n return Stream.concat(\n Stream.succeed<SandboxEvent>(\n SandboxStarted.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n runtime: request.runtime,\n }),\n ),\n Stream.concat(\n Stream.merge(\n streamOutput(\"stdout\", stdoutDecoder),\n streamOutput(\"stderr\", stderrDecoder),\n ),\n terminal,\n ),\n );\n }),\n ).pipe(\n Stream.interruptWhen(\n Effect.gen(function* () {\n yield* Effect.sleep(request.limits.maxWallTime);\n\n return yield* SandboxTimeoutError.make({\n implementation: unisolatedImplementation,\n maxWallTime: request.limits.maxWallTime,\n });\n }),\n ),\n Stream.withSpan(\"LocalSandbox.execute\"),\n );\n\n/**\n * Development-only local process adapter with its `ChildProcessSpawner` requirement kept visible\n * so composition roots and tests can inject a spawner double. It is unisolated and must never be\n * used as a security boundary for untrusted code or commands.\n */\nexport const sandboxLayer: Layer.Layer<Sandbox, never, ChildProcessSpawner> = Layer.effect(Sandbox)(\n Effect.gen(function* () {\n const spawner = yield* ChildProcessSpawner;\n\n return Sandbox.of({ execute: makeExecute(spawner) });\n }),\n);\n\n/** A scoped Node process implementation whose events are always labeled `unisolated`. */\nexport const layer: Layer.Layer<Sandbox> = sandboxLayer.pipe(Layer.provide(NodeServices.layer));\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAa,2BAA2B,sBAAsB,KAAK;CACjE,WAAW;CACX,UAAU;AACZ,CAAC;AAKD,MAAM,aAA2B;CAAE,QAAQ;CAAG,QAAQ;AAAE;AAExD,MAAM,qBAAqB,YACzB,QAAQ,MAAM,GAAG,6BAA6B;AAEhD,MAAM,eACJ,SACA,YAEA,+BAA+B,KAAK;CAClC,gBAAgB;CAChB;CACA,SAAS,kBAAkB,OAAO;AACpC,CAAC;AAEH,MAAM,kBAAkB,OAAO,GAAG,8BAA8B,CAAC,CAAC,WAChE,SACA;CACA,IACE,QAAQ,QAAQ,SAAS,wBACzB,QAAQ,QAAQ,aAAa,yBAAyB,UAEtD,OAAO,OAAO,YACZ,WACA,wGACF;CAEF,IAAI,QAAQ,OAAO,SAAS,GAC1B,OAAO,OAAO,YACZ,UACA,wEACF;CAEF,IAAI,QAAQ,QAAQ,SAAS,mBAC3B,OAAO,OAAO,YACZ,WACA,6EACF;CAEF,IAAI,QAAQ,OAAO,aAAa,K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D,CAAC,CACH;;AAGA,MAAa,QAA8B,aAAa,KAAK,MAAM,QAAQ,aAAa,KAAK,CAAC"}
1
+ {"version":3,"file":"LocalSandbox.mjs","names":[],"sources":["../src/LocalSandbox.ts"],"sourcesContent":["import { NodeServices } from \"@effect/platform-node\";\nimport { Clock, Config, Duration, Effect, Layer, Option, Ref, Stream } from \"effect\";\nimport {\n SANDBOX_DIAGNOSTIC_MAX_LENGTH,\n Sandbox,\n SandboxExited,\n SandboxExitError,\n SandboxImplementation,\n SandboxOutput,\n SandboxOutputLimitError,\n SandboxResourceUse,\n SandboxSpawnError,\n SandboxStarted,\n SandboxTimeoutError,\n SandboxUnsupportedRequestError,\n type SandboxEvent,\n type SandboxExecute,\n type SandboxRequest,\n} from \"effect-agent/sandbox\";\nimport { ChildProcess } from \"effect/unstable/process\";\nimport { ChildProcessSpawner } from \"effect/unstable/process/ChildProcessSpawner\";\n\n/**\n * The only implementation identity produced by this package. It deliberately states that local\n * process execution is unisolated development tooling, not a security sandbox.\n */\nexport const unisolatedImplementation = SandboxImplementation.make({\n isolation: \"unisolated\",\n identity: \"local-process\",\n});\n\ntype OutputStream = \"stdout\" | \"stderr\";\ntype OutputCounts = Readonly<Record<OutputStream, number>>;\n\nconst zeroOutput: OutputCounts = { stdout: 0, stderr: 0 };\n\nconst boundedDiagnostic = (message: string): string =>\n message.slice(0, SANDBOX_DIAGNOSTIC_MAX_LENGTH);\n\nconst unsupported = (\n feature: Parameters<typeof SandboxUnsupportedRequestError.make>[0][\"feature\"],\n message: string,\n) =>\n SandboxUnsupportedRequestError.make({\n implementation: unisolatedImplementation,\n feature,\n message: boundedDiagnostic(message),\n });\n\nconst validateRequest = Effect.fn(\"LocalSandbox.validateRequest\")(function* (\n request: SandboxRequest,\n) {\n if (\n request.runtime.kind !== \"unisolated-process\" ||\n request.runtime.identity !== unisolatedImplementation.identity\n ) {\n return yield* unsupported(\n \"runtime\",\n \"The local process runner only accepts runtime kind 'unisolated-process' with identity 'local-process'.\",\n );\n }\n if (request.mounts.length > 0) {\n return yield* unsupported(\n \"mounts\",\n \"The unisolated local process runner cannot enforce mount access modes.\",\n );\n }\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* unsupported(\n \"network\",\n \"The unisolated local process runner cannot enforce workload network policy.\",\n );\n }\n if (request.limits.cpuCores !== undefined) {\n return yield* unsupported(\n \"cpu-limit\",\n \"The unisolated local process runner cannot enforce CPU limits.\",\n );\n }\n if (request.limits.memoryBytes !== undefined) {\n return yield* unsupported(\n \"memory-limit\",\n \"The unisolated local process runner cannot enforce memory limits.\",\n );\n }\n if (request.secretHandles.length > 0) {\n return yield* unsupported(\n \"secret-handles\",\n \"The unisolated local process runner does not resolve secret handles into an environment.\",\n );\n }\n if (request.artifactRules.length > 0) {\n return yield* unsupported(\n \"artifacts\",\n \"The unisolated local process runner does not collect artifacts.\",\n );\n }\n});\n\nconst spawnError = (request: SandboxRequest, message: string, cause?: unknown) =>\n SandboxSpawnError.make({\n implementation: unisolatedImplementation,\n command: request.command,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst exitError = (message: string, cause?: unknown, exitCode = -1) =>\n SandboxExitError.make({\n implementation: unisolatedImplementation,\n exitCode,\n message: boundedDiagnostic(message),\n ...(cause === undefined ? {} : { cause }),\n });\n\nconst environmentFromAllowlist = Effect.fn(\"LocalSandbox.environmentFromAllowlist\")(function* (\n request: SandboxRequest,\n) {\n const environment: Record<string, string> = {};\n\n for (const name of request.environment.allow) {\n const value = yield* Config.option(Config.String(name)).pipe(\n Effect.mapError((error) =>\n spawnError(\n request,\n `Could not read allowed environment variable '${name}': ${error.message}`,\n error,\n ),\n ),\n );\n\n if (Option.isSome(value)) {\n environment[name] = value.value;\n }\n }\n\n return environment;\n});\n\nconst outputEvent = (\n counts: Ref.Ref<OutputCounts>,\n stream: OutputStream,\n bytes: Uint8Array,\n decoder: TextDecoder,\n limit: number,\n): Effect.Effect<SandboxOutput, SandboxOutputLimitError> =>\n Ref.modify(counts, (current) => {\n const streamBytes = current[stream] + bytes.byteLength;\n const next = { ...current, [stream]: streamBytes };\n\n return [next.stdout + next.stderr, next] as const;\n }).pipe(\n Effect.flatMap((observed) =>\n observed > limit\n ? Effect.fail(\n SandboxOutputLimitError.make({\n implementation: unisolatedImplementation,\n stream,\n limit,\n observed,\n }),\n )\n : Effect.succeed(\n SandboxOutput.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n stream,\n text: decoder.decode(bytes, { stream: true }),\n bytes: bytes.byteLength,\n }),\n ),\n ),\n );\n\n/**\n * Emits any text the streaming decoder still holds once its source stream ends. The final decode\n * must run at end-of-stream, not at pipeline construction, so the flush is suspended; a trailing\n * incomplete UTF-8 sequence surfaces as replacement text. Its raw bytes were already counted when\n * the chunk arrived, so the flush event carries zero bytes.\n */\nconst flushDecoder = (stream: OutputStream, decoder: TextDecoder): Stream.Stream<SandboxOutput> =>\n Stream.suspend(() => {\n const text = decoder.decode();\n\n return text.length === 0\n ? Stream.empty\n : Stream.succeed(\n SandboxOutput.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n stream,\n text,\n bytes: 0,\n }),\n );\n });\n\nconst makeExecute =\n (spawner: ChildProcessSpawner[\"Service\"]): SandboxExecute =>\n (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* validateRequest(request);\n const startedAt = yield* Clock.currentTimeMillis;\n const counts = yield* Ref.make(zeroOutput);\n const stdoutDecoder = new TextDecoder();\n const stderrDecoder = new TextDecoder();\n const environment = yield* environmentFromAllowlist(request);\n\n const command = ChildProcess.make(request.command, request.args, {\n cwd: request.cwd,\n env: environment,\n extendEnv: false,\n stdout: \"pipe\",\n stderr: \"pipe\",\n });\n\n const child = yield* spawner\n .spawn(command)\n .pipe(Effect.mapError((error) => spawnError(request, error.message, error)));\n\n const streamOutput = (stream: OutputStream, decoder: TextDecoder) => {\n const source = stream === \"stdout\" ? child.stdout : child.stderr;\n\n return source.pipe(\n Stream.mapError((error) => exitError(error.message, error)),\n Stream.mapEffect((bytes) =>\n outputEvent(counts, stream, bytes, decoder, request.limits.maxOutputBytes),\n ),\n Stream.concat(flushDecoder(stream, decoder)),\n );\n };\n\n const terminal = Stream.unwrap(\n Effect.gen(function* () {\n const exitCode = yield* child.exitCode.pipe(\n Effect.mapError((error) => exitError(error.message, error)),\n );\n\n const endedAt = yield* Clock.currentTimeMillis;\n const output = yield* Ref.get(counts);\n\n const resourceUse = SandboxResourceUse.make({\n wallTime: Duration.millis(endedAt - startedAt),\n stdoutBytes: output.stdout,\n stderrBytes: output.stderr,\n });\n\n const exited = SandboxExited.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n exitCode,\n resourceUse,\n artifacts: [],\n });\n\n return exitCode === 0\n ? Stream.succeed<SandboxEvent>(exited)\n : Stream.concat(\n Stream.succeed<SandboxEvent>(exited),\n Stream.fail(\n exitError(\n `Unisolated local process exited with code ${exitCode}.`,\n undefined,\n exitCode,\n ),\n ),\n );\n }),\n );\n\n return Stream.concat(\n Stream.succeed<SandboxEvent>(\n SandboxStarted.make({\n eventVersion: 1,\n implementation: unisolatedImplementation,\n runtime: request.runtime,\n }),\n ),\n Stream.concat(\n Stream.merge(\n streamOutput(\"stdout\", stdoutDecoder),\n streamOutput(\"stderr\", stderrDecoder),\n ),\n terminal,\n ),\n );\n }),\n ).pipe(\n Stream.interruptWhen(\n Effect.gen(function* () {\n yield* Effect.sleep(request.limits.maxWallTime);\n\n return yield* SandboxTimeoutError.make({\n implementation: unisolatedImplementation,\n maxWallTime: request.limits.maxWallTime,\n });\n }),\n ),\n Stream.withSpan(\"LocalSandbox.execute\"),\n );\n\n/**\n * Development-only local process adapter with its `ChildProcessSpawner` requirement kept visible\n * so composition roots and tests can inject a spawner double. It is unisolated and must never be\n * used as a security boundary for untrusted code or commands.\n */\nexport const sandboxLayer: Layer.Layer<Sandbox, never, ChildProcessSpawner> = Layer.effect(Sandbox)(\n Effect.gen(function* () {\n const spawner = yield* ChildProcessSpawner;\n\n return Sandbox.of({ execute: makeExecute(spawner) });\n }),\n);\n\n/** A scoped Node process implementation whose events are always labeled `unisolated`. */\nexport const layer: Layer.Layer<Sandbox> = sandboxLayer.pipe(Layer.provide(NodeServices.layer));\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAa,2BAA2B,sBAAsB,KAAK;CACjE,WAAW;CACX,UAAU;AACZ,CAAC;AAKD,MAAM,aAA2B;CAAE,QAAQ;CAAG,QAAQ;AAAE;AAExD,MAAM,qBAAqB,YACzB,QAAQ,MAAM,GAAG,6BAA6B;AAEhD,MAAM,eACJ,SACA,YAEA,+BAA+B,KAAK;CAClC,gBAAgB;CAChB;CACA,SAAS,kBAAkB,OAAO;AACpC,CAAC;AAEH,MAAM,kBAAkB,OAAO,GAAG,8BAA8B,CAAC,CAAC,WAChE,SACA;CACA,IACE,QAAQ,QAAQ,SAAS,wBACzB,QAAQ,QAAQ,aAAa,yBAAyB,UAEtD,OAAO,OAAO,YACZ,WACA,wGACF;CAEF,IAAI,QAAQ,OAAO,SAAS,GAC1B,OAAO,OAAO,YACZ,UACA,wEACF;CAEF,IAAI,QAAQ,QAAQ,SAAS,mBAC3B,OAAO,OAAO,YACZ,WACA,6EACF;CAEF,IAAI,QAAQ,OAAO,aAAa,KAAA,GAC9B,OAAO,OAAO,YACZ,aACA,gEACF;CAEF,IAAI,QAAQ,OAAO,gBAAgB,KAAA,GACjC,OAAO,OAAO,YACZ,gBACA,mEACF;CAEF,IAAI,QAAQ,cAAc,SAAS,GACjC,OAAO,OAAO,YACZ,kBACA,0FACF;CAEF,IAAI,QAAQ,cAAc,SAAS,GACjC,OAAO,OAAO,YACZ,aACA,iEACF;AAEJ,CAAC;AAED,MAAM,cAAc,SAAyB,SAAiB,UAC5D,kBAAkB,KAAK;CACrB,gBAAgB;CAChB,SAAS,QAAQ;CACjB,SAAS,kBAAkB,OAAO;CAClC,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM;AACzC,CAAC;AAEH,M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AW,CAAC;EACd,CAAC;EAED,OAAO,aAAa,IAChB,OAAO,QAAsB,MAAM,IACnC,OAAO,OACL,OAAO,QAAsB,MAAM,GACnC,OAAO,KACL,UACE,6CAA6C,SAAS,IACtD,KAAA,GACA,QACF,CACF,CACF;CACN,CAAC,CACH;CAEA,OAAO,OAAO,OACZ,OAAO,QACL,eAAe,KAAK;EAClB,cAAc;EACd,gBAAgB;EAChB,SAAS,QAAQ;CACnB,CAAC,CACH,GACA,OAAO,OACL,OAAO,MACL,aAAa,UAAU,aAAa,GACpC,aAAa,UAAU,aAAa,CACtC,GACA,QACF,CACF;AACF,CAAC,CACH,CAAC,CAAC,KACA,OAAO,cACL,OAAO,IAAI,aAAa;CACtB,OAAO,OAAO,MAAM,QAAQ,OAAO,WAAW;CAE9C,OAAO,OAAO,oBAAoB,KAAK;EACrC,gBAAgB;EAChB,aAAa,QAAQ,OAAO;CAC9B,CAAC;AACH,CAAC,CACH,GACA,OAAO,SAAS,sBAAsB,CACxC;;;;;;AAOJ,MAAa,eAAiE,MAAM,OAAO,OAAO,CAAC,CACjG,OAAO,IAAI,aAAa;CACtB,MAAM,UAAU,OAAO;CAEvB,OAAO,QAAQ,GAAG,EAAE,SAAS,YAAY,OAAO,EAAE,CAAC;AACrD,CAAC,CACH;;AAGA,MAAa,QAA8B,aAAa,KAAK,MAAM,QAAQ,aAAa,KAAK,CAAC"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@effect-agent/sandbox-local","version":"0.1.0-beta.91","dependencies":{"@effect/platform-node":"4.0.0-rc.112","effect-agent":"0.1.0-beta.91"},"devDependencies":{"@effect/vitest":"4.0.0-rc.112","@types/node":"26.1.2","effect":"4.0.0-rc.112","typescript":"7.0.2","vite-plus":"0.3.0"},"peerDependencies":{"effect":"^4.0.0-rc.112"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./local-sandbox":{"types":"./dist/LocalSandbox.d.mts","default":"./dist/LocalSandbox.mjs"}},"description":"Node-local child-process Sandbox adapter for Effect Agent; honestly labeled unisolated development tooling, not a security boundary.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/sandbox-local"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
1
+ {"name":"@effect-agent/sandbox-local","version":"0.1.0-beta.92","dependencies":{"@effect/platform-node":"4.0.0-rc.115","effect-agent":"0.1.0-beta.92"},"devDependencies":{"@effect/vitest":"4.0.0-rc.115","@types/node":"26.1.2","effect":"4.0.0-rc.115","typescript":"7.0.2","vite-plus":"0.3.0"},"peerDependencies":{"effect":"^4.0.0-rc.115"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./local-sandbox":{"types":"./dist/LocalSandbox.d.mts","default":"./dist/LocalSandbox.mjs"}},"description":"Node-local child-process Sandbox adapter for Effect Agent; honestly labeled unisolated development tooling, not a security boundary.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/sandbox-local"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
@@ -119,7 +119,7 @@ const environmentFromAllowlist = Effect.fn("LocalSandbox.environmentFromAllowlis
119
119
  const environment: Record<string, string> = {};
120
120
 
121
121
  for (const name of request.environment.allow) {
122
- const value = yield* Config.option(Config.string(name)).pipe(
122
+ const value = yield* Config.option(Config.String(name)).pipe(
123
123
  Effect.mapError((error) =>
124
124
  spawnError(
125
125
  request,