@fungi.computer/mycelium 0.0.1 → 0.1.0
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.
|
@@ -10,20 +10,15 @@ import * as Fiber from "effect/Fiber";
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { InvalidOperationInput, MyceliumDefinitionError, } from "../errors.js";
|
|
12
12
|
const jsonValueSchema = z.json();
|
|
13
|
-
const jsonScalarSchema = z.union([
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
z.boolean(),
|
|
17
|
-
z.number(),
|
|
18
|
-
]);
|
|
19
|
-
const jsonRecordSchema = z.record(z.string(), z.unknown());
|
|
20
|
-
const executionOptionsSchema = z
|
|
13
|
+
const jsonScalarSchema = z.lazy(() => z.union([z.null(), z.string(), z.boolean(), z.number()]));
|
|
14
|
+
const jsonRecordSchema = z.lazy(() => z.record(z.string(), z.unknown()));
|
|
15
|
+
const executionOptionsSchema = z.lazy(() => z
|
|
21
16
|
.object({
|
|
22
17
|
timeoutMs: z.number().int().min(1).max(900_000).optional(),
|
|
23
18
|
abortGraceMs: z.number().int().min(1).max(30_000).optional(),
|
|
24
19
|
})
|
|
25
20
|
.strict()
|
|
26
|
-
.optional();
|
|
21
|
+
.optional());
|
|
27
22
|
const maximumJsonDepth = 64;
|
|
28
23
|
const maximumSerializedJsonBytes = 256 * 1024;
|
|
29
24
|
const maximumBackingExecutions = 8;
|
package/dist/sandbox-boundary.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as Schema from "effect/Schema";
|
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { InvalidOperationInput } from "./errors.js";
|
|
7
7
|
import { SourceInvalid, GuestThrew, DeadlineExceeded, Cancelled, DispatchLost, SandboxCrashed, BadResponse, ResultTooLarge, ResultNotJson, CapabilityFailed, Unknown, referenceSandboxFailure, sandboxFailureMessage, } from "./sandbox-failure.js";
|
|
8
|
-
const ownedFailureSchema = z.union([
|
|
8
|
+
const ownedFailureSchema = z.lazy(() => z.union([
|
|
9
9
|
z.instanceof(SourceInvalid),
|
|
10
10
|
z.instanceof(GuestThrew),
|
|
11
11
|
z.instanceof(DeadlineExceeded),
|
|
@@ -17,9 +17,9 @@ const ownedFailureSchema = z.union([
|
|
|
17
17
|
z.instanceof(ResultNotJson),
|
|
18
18
|
z.instanceof(CapabilityFailed),
|
|
19
19
|
z.instanceof(Unknown),
|
|
20
|
-
]);
|
|
20
|
+
]));
|
|
21
21
|
/** The one interpretation boundary for foreign in-process values and rejections. */
|
|
22
|
-
const foreignValueSchema = z
|
|
22
|
+
const foreignValueSchema = z.lazy(() => z
|
|
23
23
|
.unknown()
|
|
24
24
|
.pipe(z.union([
|
|
25
25
|
z
|
|
@@ -32,7 +32,12 @@ const foreignValueSchema = z
|
|
|
32
32
|
z.string().transform((value) => ({ kind: "string", value })),
|
|
33
33
|
z.boolean().transform((value) => ({ kind: "boolean", value })),
|
|
34
34
|
z
|
|
35
|
-
.union([
|
|
35
|
+
.union([
|
|
36
|
+
z.number(),
|
|
37
|
+
z.nan(),
|
|
38
|
+
z.literal(Infinity),
|
|
39
|
+
z.literal(-Infinity),
|
|
40
|
+
])
|
|
36
41
|
.transform((value) => ({ kind: "number", value })),
|
|
37
42
|
z.bigint().transform((value) => ({ kind: "bigint", value })),
|
|
38
43
|
z.symbol().transform((value) => ({ kind: "symbol", value })),
|
|
@@ -46,7 +51,7 @@ const foreignValueSchema = z
|
|
|
46
51
|
.union([z.instanceof(Object), z.record(z.string(), z.unknown())])
|
|
47
52
|
.transform((value) => ({ kind: "object", value })),
|
|
48
53
|
z.unknown().transform(() => ({ kind: "opaque" })),
|
|
49
|
-
]));
|
|
54
|
+
])));
|
|
50
55
|
/** Admit only errors constructed by the sandbox owner, using the maintained decoder. */
|
|
51
56
|
export function isSandboxFailure(cause) {
|
|
52
57
|
return ownedFailureSchema.safeParse(cause).success;
|
|
@@ -68,7 +73,7 @@ export function sandboxValueKind(value) {
|
|
|
68
73
|
return decoded.kind;
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
|
-
const bindingInputSchema = z.json().optional();
|
|
76
|
+
const bindingInputSchema = z.lazy(() => z.json().optional());
|
|
72
77
|
/** Decode the RPC argument before any capability callback observes it. */
|
|
73
78
|
export function sandboxBindingInput(value) {
|
|
74
79
|
return bindingInputSchema.parse(value);
|
|
@@ -132,7 +137,7 @@ function operatorValue(cause, seen) {
|
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
|
-
const missingVariable = z
|
|
140
|
+
const missingVariable = z.lazy(() => z
|
|
136
141
|
.object({
|
|
137
142
|
name: z.literal("ReferenceError"),
|
|
138
143
|
message: z
|
|
@@ -142,10 +147,13 @@ const missingVariable = z
|
|
|
142
147
|
.transform((value) => ({
|
|
143
148
|
...value,
|
|
144
149
|
missingVariable: value.message.slice(0, -" is not defined".length),
|
|
145
|
-
}));
|
|
146
|
-
const guestDiagnosticSchema = z
|
|
147
|
-
.union([
|
|
148
|
-
|
|
150
|
+
})));
|
|
151
|
+
const guestDiagnosticSchema = z.lazy(() => z
|
|
152
|
+
.union([
|
|
153
|
+
missingVariable,
|
|
154
|
+
z.object({ name: z.string(), message: z.string() }),
|
|
155
|
+
])
|
|
156
|
+
.and(z.object({ transportMessage: z.string().max(512).optional() })));
|
|
149
157
|
/** Decode the engine's guest-owned diagnostic once; renderers receive typed fields. */
|
|
150
158
|
export function sandboxGuestFailure(cause, bindings = {}) {
|
|
151
159
|
const diagnostic = guestDiagnosticSchema.parse(cause);
|
|
@@ -160,7 +168,7 @@ export function sandboxGuestFailure(cause, bindings = {}) {
|
|
|
160
168
|
}
|
|
161
169
|
return new GuestThrew(diagnostic);
|
|
162
170
|
}
|
|
163
|
-
const transportEnvelopeSchema = z.strictObject({
|
|
171
|
+
const transportEnvelopeSchema = z.lazy(() => z.strictObject({
|
|
164
172
|
v: z.literal(1),
|
|
165
173
|
kind: z.literal("sandbox_failure"),
|
|
166
174
|
tag: z.enum([
|
|
@@ -178,9 +186,9 @@ const transportEnvelopeSchema = z.strictObject({
|
|
|
178
186
|
]),
|
|
179
187
|
ref: z.string().min(1).max(32),
|
|
180
188
|
message: z.string().max(160),
|
|
181
|
-
});
|
|
189
|
+
}));
|
|
182
190
|
const decodeJsonText = Schema.decodeUnknownResult(Schema.fromJsonString(Schema.Unknown));
|
|
183
|
-
const jsonTextSchema = z.string().transform((text, context) => {
|
|
191
|
+
const jsonTextSchema = z.lazy(() => z.string().transform((text, context) => {
|
|
184
192
|
const decoded = decodeJsonText(text);
|
|
185
193
|
if (Result.isFailure(decoded)) {
|
|
186
194
|
context.addIssue({
|
|
@@ -190,7 +198,7 @@ const jsonTextSchema = z.string().transform((text, context) => {
|
|
|
190
198
|
return z.NEVER;
|
|
191
199
|
}
|
|
192
200
|
return decoded.success;
|
|
193
|
-
});
|
|
201
|
+
}));
|
|
194
202
|
const transportMessageSchema = jsonTextSchema.pipe(transportEnvelopeSchema);
|
|
195
203
|
const returnedOperationFailure = z.strictObject({
|
|
196
204
|
error: transportMessageSchema,
|
|
@@ -218,16 +226,15 @@ export function recoverSandboxFailure(failure, failures) {
|
|
|
218
226
|
const original = failures.get(decoded.data.ref);
|
|
219
227
|
return original?._tag === decoded.data.tag ? original : failure;
|
|
220
228
|
}
|
|
221
|
-
const executorFailureSchema = z
|
|
222
|
-
.unknown()
|
|
223
|
-
.pipe(z.union([
|
|
229
|
+
const executorFailureSchema = z.lazy(() => z.unknown().pipe(z.union([
|
|
224
230
|
z
|
|
225
231
|
.literal("Execution timed out")
|
|
226
232
|
.transform(() => ({ kind: "deadline" })),
|
|
227
|
-
z
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
z.unknown().transform((rawCause) => ({
|
|
234
|
+
kind: "bad_response",
|
|
235
|
+
rawCause,
|
|
236
|
+
})),
|
|
237
|
+
])));
|
|
231
238
|
/** Decode Codemode's documented error carrier before adapters choose a failure. */
|
|
232
239
|
export function sandboxExecutorFailure(cause, limitMs, elapsedMs) {
|
|
233
240
|
const decoded = executorFailureSchema.parse(cause);
|
package/dist/sandbox-guest.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/** Closed guest envelope: guest exceptions cannot masquerade as host failures. */
|
|
3
|
-
export declare const sandboxGuestResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
export declare const sandboxGuestResultSchema: z.ZodLazy<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
4
|
ok: z.ZodLiteral<true>;
|
|
5
5
|
value: z.ZodUnknown;
|
|
6
6
|
}, z.core.$strict>, z.ZodObject<{
|
|
@@ -11,7 +11,7 @@ export declare const sandboxGuestResultSchema: z.ZodDiscriminatedUnion<[z.ZodObj
|
|
|
11
11
|
message: z.ZodString;
|
|
12
12
|
transportMessage: z.ZodOptional<z.ZodString>;
|
|
13
13
|
}, z.core.$strict>;
|
|
14
|
-
}, z.core.$strict>], "ok"
|
|
14
|
+
}, z.core.$strict>], "ok">>;
|
|
15
15
|
/** Locate syntax in the submitted code, accounting for Codemode's normalization. */
|
|
16
16
|
export declare function submittedSourceLocation(normalized: string, submitted: string): Readonly<{
|
|
17
17
|
line: number;
|
|
@@ -19,13 +19,13 @@ export declare function submittedSourceLocation(normalized: string, submitted: s
|
|
|
19
19
|
excerpt: string;
|
|
20
20
|
}> | null;
|
|
21
21
|
/** Parsed guest namespace segments; callbacks never cross this wire. */
|
|
22
|
-
export declare const sandboxNamespaceSegmentSchema: z.ZodString
|
|
22
|
+
export declare const sandboxNamespaceSegmentSchema: z.ZodLazy<z.ZodString>;
|
|
23
23
|
/** A transport alias is interpolated as a strict JavaScript binding identifier. */
|
|
24
|
-
export declare const sandboxTransportAliasSchema: z.ZodString
|
|
24
|
+
export declare const sandboxTransportAliasSchema: z.ZodLazy<z.ZodString>;
|
|
25
25
|
/** Transport aliases mapped to their logical namespace paths. */
|
|
26
|
-
export declare const sandboxNamespacePathsSchema: z.ZodRecord<z.ZodString
|
|
26
|
+
export declare const sandboxNamespacePathsSchema: z.ZodLazy<z.ZodRecord<z.ZodLazy<z.ZodString>, z.ZodArray<z.ZodLazy<z.ZodString>>>>;
|
|
27
27
|
/** Serializable flat transport table; operation keys may have any namespace depth. */
|
|
28
|
-
export declare const sandboxBindingNamesSchema: z.ZodRecord<z.ZodString
|
|
28
|
+
export declare const sandboxBindingNamesSchema: z.ZodLazy<z.ZodRecord<z.ZodLazy<z.ZodString>, z.ZodArray<z.ZodString>>>;
|
|
29
29
|
/** Serializable operation names; callbacks stay in the host's existing binding table. */
|
|
30
30
|
export declare function sandboxBindingNames<A>(bindings: Readonly<Record<string, Readonly<Record<string, A>>>>): Readonly<Record<string, readonly string[]>>;
|
|
31
31
|
/** Injective provider identifier: Codemode sanitizes dotted function names. */
|
package/dist/sandbox-guest.js
CHANGED
|
@@ -2,7 +2,7 @@ import { parse } from "acorn";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { sandboxSourceError } from "./sandbox-boundary.js";
|
|
4
4
|
/** Closed guest envelope: guest exceptions cannot masquerade as host failures. */
|
|
5
|
-
export const sandboxGuestResultSchema = z.discriminatedUnion("ok", [
|
|
5
|
+
export const sandboxGuestResultSchema = z.lazy(() => z.discriminatedUnion("ok", [
|
|
6
6
|
z.strictObject({ ok: z.literal(true), value: z.unknown() }),
|
|
7
7
|
z.strictObject({
|
|
8
8
|
ok: z.literal(false),
|
|
@@ -13,7 +13,7 @@ export const sandboxGuestResultSchema = z.discriminatedUnion("ok", [
|
|
|
13
13
|
transportMessage: z.string().max(512).optional(),
|
|
14
14
|
}),
|
|
15
15
|
}),
|
|
16
|
-
]);
|
|
16
|
+
]));
|
|
17
17
|
/** Locate syntax in the submitted code, accounting for Codemode's normalization. */
|
|
18
18
|
export function submittedSourceLocation(normalized, submitted) {
|
|
19
19
|
try {
|
|
@@ -45,9 +45,7 @@ export function submittedSourceLocation(normalized, submitted) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
/** Parsed guest namespace segments; callbacks never cross this wire. */
|
|
48
|
-
export const sandboxNamespaceSegmentSchema = z
|
|
49
|
-
.string()
|
|
50
|
-
.regex(/^[A-Za-z][A-Za-z0-9_]*$/u);
|
|
48
|
+
export const sandboxNamespaceSegmentSchema = z.lazy(() => z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/u));
|
|
51
49
|
/** A transport alias is interpolated as a strict JavaScript binding identifier. */
|
|
52
50
|
export const sandboxTransportAliasSchema = sandboxNamespaceSegmentSchema.refine((alias) => {
|
|
53
51
|
if (alias === "env")
|
|
@@ -63,9 +61,9 @@ export const sandboxTransportAliasSchema = sandboxNamespaceSegmentSchema.refine(
|
|
|
63
61
|
}
|
|
64
62
|
}, "Invalid sandbox transport alias");
|
|
65
63
|
/** Transport aliases mapped to their logical namespace paths. */
|
|
66
|
-
export const sandboxNamespacePathsSchema = z.record(sandboxTransportAliasSchema, z.array(sandboxNamespaceSegmentSchema).min(1));
|
|
64
|
+
export const sandboxNamespacePathsSchema = z.lazy(() => z.record(sandboxTransportAliasSchema, z.array(sandboxNamespaceSegmentSchema).min(1)));
|
|
67
65
|
/** Serializable flat transport table; operation keys may have any namespace depth. */
|
|
68
|
-
export const sandboxBindingNamesSchema = z.record(sandboxTransportAliasSchema, z.array(z.string().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u)));
|
|
66
|
+
export const sandboxBindingNamesSchema = z.lazy(() => z.record(sandboxTransportAliasSchema, z.array(z.string().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*$/u))));
|
|
69
67
|
/** Serializable operation names; callbacks stay in the host's existing binding table. */
|
|
70
68
|
export function sandboxBindingNames(bindings) {
|
|
71
69
|
return Object.fromEntries(Object.entries(bindings).map(([namespace, operations]) => [
|
package/dist/source-runtime.js
CHANGED
|
@@ -9,11 +9,11 @@ function compareCodeUnits(left, right) {
|
|
|
9
9
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
10
10
|
}
|
|
11
11
|
const maximumCapabilitySources = 128;
|
|
12
|
-
const sourceIdSchema = z.string().min(1).max(160);
|
|
13
|
-
const sourceSnapshotSchema = z.object({
|
|
12
|
+
const sourceIdSchema = z.lazy(() => z.string().min(1).max(160));
|
|
13
|
+
const sourceSnapshotSchema = z.lazy(() => z.object({
|
|
14
14
|
version: z.string().min(1).max(160),
|
|
15
15
|
modules: z.array(z.unknown()),
|
|
16
|
-
});
|
|
16
|
+
}));
|
|
17
17
|
const maximumCandidateModules = 1_000;
|
|
18
18
|
function validateSources(input) {
|
|
19
19
|
if (input.length > maximumCapabilitySources) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/mycelium",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Effect-native scoped capability lifecycle with a Zod-authored execute door",
|
|
6
6
|
"type": "module",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@fungi.computer/cairn": "0.0.1",
|
|
78
|
-
"@fungi.computer/forage": "0.0
|
|
79
|
-
"@fungi.computer/mule": "0.0.
|
|
80
|
-
"@fungi.computer/puffball": "0.0
|
|
78
|
+
"@fungi.computer/forage": "0.1.0",
|
|
79
|
+
"@fungi.computer/mule": "0.0.2",
|
|
80
|
+
"@fungi.computer/puffball": "0.1.0",
|
|
81
81
|
"effect": "4.0.2",
|
|
82
82
|
"zod": "4.4.3",
|
|
83
83
|
"acorn": "8.18.0",
|