@nylorun/core 0.1.1-beta → 0.3.0-beta

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,109 @@
1
+ import { z } from "zod";
2
+ import { tool } from "./helpers.js";
3
+ import { ToolError } from "./tool-error.js";
4
+ import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
5
+ const PATH_NOTE = `Relative paths resolve under ${SANDBOX_WORKSPACE}.`;
6
+ /** Instructions attached to every sandbox capability. */
7
+ export const SANDBOX_INSTRUCTIONS = `You have an isolated Linux sandbox with a persistent working directory at ${SANDBOX_WORKSPACE}. ` +
8
+ "Use bash to run commands, read/write/edit to work with files, and grep/glob to search. " +
9
+ "Network egress is limited by policy; a failed download usually means the host is not allowed.";
10
+ /**
11
+ * Stub implementation for the developer process. The Runtime executes sandbox tools;
12
+ * reaching this means the agent ran without a Nylorun Runtime.
13
+ */
14
+ async function runtimeOnly() {
15
+ throw new ToolError("sandbox.runtime-only", "Sandbox tools run in the Nylorun Runtime. Run the agent with `nylorun dev` or `nylorun serve` to use them.");
16
+ }
17
+ /** The six built-in sandbox tools. Schemas are part of the hashed manifest; change them deliberately. */
18
+ export function createSandboxTools() {
19
+ return Object.freeze([
20
+ tool({
21
+ name: "bash",
22
+ description: `Run a bash command in the sandbox. The working directory is ${SANDBOX_WORKSPACE}. ` +
23
+ "Returns exitCode, stdout and stderr; a non-zero exit code is a normal result, not an error. " +
24
+ "Long output is truncated in the middle.",
25
+ inputSchema: z.object({
26
+ command: z.string().min(1).describe("The command line to run with bash."),
27
+ timeout: z
28
+ .number()
29
+ .int()
30
+ .min(1)
31
+ .max(600)
32
+ .optional()
33
+ .describe("Seconds before the command is killed. Default 120, maximum 600."),
34
+ }),
35
+ effects: "write",
36
+ execute: runtimeOnly,
37
+ }),
38
+ tool({
39
+ name: "read",
40
+ description: `Read a text file from the sandbox. ${PATH_NOTE} Returns numbered lines. ` +
41
+ "Use offset and limit to page through large files.",
42
+ inputSchema: z.object({
43
+ path: z.string().min(1),
44
+ offset: z
45
+ .number()
46
+ .int()
47
+ .min(1)
48
+ .optional()
49
+ .describe("First line to return, 1-based."),
50
+ limit: z
51
+ .number()
52
+ .int()
53
+ .min(1)
54
+ .max(5000)
55
+ .optional()
56
+ .describe("Maximum number of lines. Default 2000."),
57
+ }),
58
+ effects: "read",
59
+ execute: runtimeOnly,
60
+ }),
61
+ tool({
62
+ name: "write",
63
+ description: `Create or overwrite a text file in the sandbox. ${PATH_NOTE} Parent directories are created.`,
64
+ inputSchema: z.object({
65
+ path: z.string().min(1),
66
+ content: z.string(),
67
+ }),
68
+ effects: "write",
69
+ execute: runtimeOnly,
70
+ }),
71
+ tool({
72
+ name: "edit",
73
+ description: `Replace text in a sandbox file. ${PATH_NOTE} old_string must match exactly and be unique ` +
74
+ "unless replace_all is true.",
75
+ inputSchema: z.object({
76
+ path: z.string().min(1),
77
+ old_string: z.string().min(1),
78
+ new_string: z.string(),
79
+ replace_all: z.boolean().optional(),
80
+ }),
81
+ effects: "write",
82
+ execute: runtimeOnly,
83
+ }),
84
+ tool({
85
+ name: "grep",
86
+ description: `Search file contents in the sandbox with an extended regular expression. ${PATH_NOTE} ` +
87
+ "Returns matching lines as path:line:text.",
88
+ inputSchema: z.object({
89
+ pattern: z.string().min(1),
90
+ path: z.string().min(1).optional().describe(`Directory or file to search. Default ${SANDBOX_WORKSPACE}.`),
91
+ glob: z.string().min(1).optional().describe("Only search files whose name matches, e.g. \"*.py\"."),
92
+ ignore_case: z.boolean().optional(),
93
+ max_results: z.number().int().min(1).max(1000).optional().describe("Default 200."),
94
+ }),
95
+ effects: "read",
96
+ execute: runtimeOnly,
97
+ }),
98
+ tool({
99
+ name: "glob",
100
+ description: `Find files in the sandbox by glob pattern, e.g. "**/*.csv". ${PATH_NOTE} Returns matching paths.`,
101
+ inputSchema: z.object({
102
+ pattern: z.string().min(1),
103
+ path: z.string().min(1).optional().describe(`Directory to search. Default ${SANDBOX_WORKSPACE}.`),
104
+ }),
105
+ effects: "read",
106
+ execute: runtimeOnly,
107
+ }),
108
+ ]);
109
+ }
@@ -91,11 +91,14 @@ export function normalizeSchema(source, role) {
91
91
  return normalized;
92
92
  }
93
93
  function normalizeZodSchema(source, role) {
94
- if (hasDeclaredAsyncWork(source))
94
+ // Classic parse/JSON Schema helpers are typed on ZodType; concrete schemas
95
+ // are $ZodType-compatible but may not assign to ZodType under zod 4.6+.
96
+ const classic = source;
97
+ if (hasDeclaredAsyncWork(classic))
95
98
  throw new HarnessError("tool.invalid-schema", "Tool schema must validate synchronously");
96
99
  let jsonSchema;
97
100
  try {
98
- jsonSchema = copyJsonObject(z.toJSONSchema(source, { target: "draft-07" }), `tool.${role}Schema.jsonSchema`);
101
+ jsonSchema = copyJsonObject(z.toJSONSchema(classic, { target: "draft-07" }), `tool.${role}Schema.jsonSchema`);
99
102
  }
100
103
  catch (error) {
101
104
  throw new HarnessError("tool.invalid-schema", `Tool ${role}Schema must convert to JSON Schema: ${message(error)}`, { cause: error });
@@ -104,7 +107,7 @@ function normalizeZodSchema(source, role) {
104
107
  jsonSchema,
105
108
  validate(value) {
106
109
  try {
107
- const result = source.safeParse(value);
110
+ const result = classic.safeParse(value);
108
111
  if (result.success)
109
112
  return { ok: true, value: result.data };
110
113
  return {
@@ -0,0 +1,3 @@
1
+ import type { SkillRecord } from "../types/middleware.js";
2
+ import type { ToolDefinition } from "../types/tool.js";
3
+ export declare function createSkillTools(skills: ReadonlyMap<string, SkillRecord>): readonly ToolDefinition[];
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { tool } from "./helpers.js";
3
+ const USAGE = "Load the full instructions for a named skill. Call this before following a skill.";
4
+ export function createSkillTools(skills) {
5
+ const names = [...skills.keys()].sort();
6
+ const nameSchema = names.length === 1
7
+ ? z.literal(names[0])
8
+ : z.enum(names);
9
+ const definitions = [
10
+ tool({
11
+ name: "load_skill",
12
+ description: USAGE,
13
+ inputSchema: z.object({ name: nameSchema }),
14
+ effects: "read",
15
+ async execute(args) {
16
+ const name = args.name;
17
+ const skill = skills.get(name);
18
+ if (!skill)
19
+ return { unknown: name, available: names };
20
+ const loaded = {
21
+ name: skill.name,
22
+ content: skill.instructions,
23
+ };
24
+ const resources = Object.keys(skill.resources ?? {}).sort();
25
+ if (resources.length === 0)
26
+ return loaded;
27
+ return { ...loaded, resources };
28
+ },
29
+ }),
30
+ ];
31
+ const hasResources = [...skills.values()].some((skill) => skill.resources !== undefined && Object.keys(skill.resources).length > 0);
32
+ if (hasResources) {
33
+ definitions.push(tool({
34
+ name: "read_skill_resource",
35
+ description: "Read one text resource from a skill after load_skill.",
36
+ inputSchema: z.object({
37
+ name: nameSchema,
38
+ path: z.string().min(1),
39
+ }),
40
+ effects: "read",
41
+ async execute(args) {
42
+ const { name, path } = args;
43
+ const skill = skills.get(name);
44
+ const content = skill?.resources?.[path];
45
+ if (!skill || content === undefined)
46
+ return {
47
+ kind: "failed",
48
+ code: "skill.unknown_resource",
49
+ message: `Skill '${name}' has no resource '${path}'.`,
50
+ };
51
+ return { kind: "completed", output: { name, path, content } };
52
+ },
53
+ }));
54
+ }
55
+ return definitions;
56
+ }
@@ -3,10 +3,8 @@ import type { AgentManifest } from "./manifest.js";
3
3
  /** An agent definition composed with Agent(...).use(...). Optional `.build()` is a no-op facade. */
4
4
  export interface BuiltAgent<Info = unknown, Output = string> {
5
5
  readonly id: string;
6
- readonly name: string;
6
+ readonly name?: string;
7
7
  readonly manifest: AgentManifest;
8
- /** Canonical SHA-256 of `manifest` — durable definition identity. */
9
- readonly hash: string;
10
8
  toJSON(): AgentManifest;
11
9
  getBinding(): AgentBinding;
12
10
  }
@@ -7,11 +7,11 @@ export type Patch = {
7
7
  readonly capabilities?: Readonly<Record<string, boolean>>;
8
8
  /** Switch tools by name. */
9
9
  readonly tools?: Readonly<Record<string, boolean>>;
10
- /** Extra instructions for this model call only. */
10
+ /** Extra instructions for the model calls this patch covers. */
11
11
  readonly instructions?: readonly string[];
12
12
  /** Write session state keys (merged into durable session state). */
13
13
  readonly state?: Readonly<Record<string, JsonValue>>;
14
- /** Refuse this model call; message returned to the host. */
14
+ /** Refuse the model call; message returned to the host. */
15
15
  readonly block?: string;
16
16
  /**
17
17
  * Capability-level shorthand: toggle only this capability.
@@ -33,21 +33,69 @@ export type Decision = {
33
33
  readonly retry?: string;
34
34
  readonly block?: string;
35
35
  };
36
- export type BeforeModelCallFn<Info = unknown> = (args: {
36
+ /** Decision applied to a turn's final answer before it is returned. */
37
+ export type TurnDecision = {
38
+ /** Replace the final text. Plain-text agents only. */
39
+ readonly text?: string;
40
+ /** Replace the final structured output. Agents with an output schema only. */
41
+ readonly output?: JsonValue;
42
+ /** Ask the model to answer again; the feedback is added as a message. */
43
+ readonly retry?: string;
44
+ readonly block?: string;
45
+ };
46
+ /** When a hook runs: once per turn, or on every model call (step). */
47
+ export type HookScope = "turn" | "step";
48
+ export type HookAt = "before" | "after";
49
+ /** A registered hook point as published in the manifest. */
50
+ export type HookManifest = {
51
+ readonly at: HookAt;
52
+ readonly scope: HookScope;
53
+ };
54
+ export type HookState = Readonly<Record<string, JsonValue>>;
55
+ export type HookToolCall = {
56
+ readonly id: string;
57
+ readonly name: string;
58
+ readonly args: JsonValue;
59
+ };
60
+ export type BeforeTurnArgs<Info = unknown> = {
61
+ /** The user input that started this turn. */
37
62
  readonly input?: MessageInput | string;
38
63
  readonly info?: Info;
39
- readonly state: Readonly<Record<string, JsonValue>>;
64
+ readonly state: HookState;
40
65
  readonly messages: readonly PromptItem[];
66
+ };
67
+ export type BeforeStepArgs<Info = unknown> = BeforeTurnArgs<Info> & {
68
+ /** Zero-based model call index within the turn. */
41
69
  readonly step: number;
42
- }) => Patch | Promise<Patch>;
43
- export type AfterModelCallFn<Info = unknown> = (args: {
70
+ };
71
+ export type AfterStepArgs<Info = unknown> = {
44
72
  readonly text?: string;
45
- readonly toolCalls: readonly {
46
- readonly id: string;
47
- readonly name: string;
48
- readonly args: JsonValue;
49
- }[];
50
- }, ctx: {
73
+ readonly toolCalls: readonly HookToolCall[];
74
+ readonly info?: Info;
75
+ readonly state: HookState;
76
+ readonly step: number;
77
+ /** Retries already requested by `after("step")` hooks in this turn. */
78
+ readonly attempt: number;
79
+ };
80
+ export type AfterTurnArgs<Info = unknown> = {
81
+ /** Final text, for plain-text agents. */
82
+ readonly text?: string;
83
+ /** Final output: the text, or the structured value when an output schema is set. */
84
+ readonly output: JsonValue;
51
85
  readonly info?: Info;
52
- readonly state: Readonly<Record<string, JsonValue>>;
53
- }) => Decision | Promise<Decision>;
86
+ readonly state: HookState;
87
+ /** Retries already requested by `after("turn")` hooks in this turn. */
88
+ readonly attempt: number;
89
+ };
90
+ type Awaitable<T> = T | Promise<T>;
91
+ export type BeforeHook<S extends HookScope, Info = unknown> = (args: S extends "turn" ? BeforeTurnArgs<Info> : BeforeStepArgs<Info>) => Awaitable<Patch>;
92
+ export type AfterHook<S extends HookScope, Info = unknown> = S extends "step" ? (args: AfterStepArgs<Info>) => Awaitable<Decision> : (args: AfterTurnArgs<Info>) => Awaitable<TurnDecision>;
93
+ export type BeforeHooks<Info = unknown> = {
94
+ readonly turn?: BeforeHook<"turn", Info>;
95
+ readonly step?: BeforeHook<"step", Info>;
96
+ };
97
+ export type AfterHooks<Info = unknown> = {
98
+ readonly step?: AfterHook<"step", Info>;
99
+ readonly turn?: AfterHook<"turn", Info>;
100
+ };
101
+ export {};
@@ -1,34 +1,83 @@
1
- import type { ModelDirective } from "./model.js";
2
1
  import type { JsonObject } from "./shared.js";
2
+ import type { HookManifest } from "./dynamics.js";
3
3
  /** Published manifest schema version (no top-level model — Runtime-owned). */
4
- export type ManifestSchemaVersion = 2;
5
- export interface ManifestTool {
4
+ export type ManifestSchemaVersion = 4;
5
+ export interface ToolManifest {
6
6
  readonly name: string;
7
7
  readonly description?: string;
8
8
  readonly inputSchema: JsonObject;
9
9
  readonly outputSchema?: JsonObject;
10
10
  }
11
+ export interface SkillManifest {
12
+ readonly name: string;
13
+ readonly description: string;
14
+ }
15
+ export type McpServerManifest = {
16
+ readonly name: string;
17
+ readonly type: "stdio";
18
+ readonly command: string;
19
+ readonly args?: readonly string[];
20
+ readonly env?: Readonly<Record<string, string>>;
21
+ readonly cwd?: string;
22
+ } | {
23
+ readonly name: string;
24
+ readonly type: "streamable-http";
25
+ readonly url: string;
26
+ readonly headers?: Readonly<Record<string, string>>;
27
+ } | {
28
+ readonly name: string;
29
+ readonly type: "sse";
30
+ readonly url: string;
31
+ readonly headers?: Readonly<Record<string, string>>;
32
+ };
33
+ /** Network egress preset for a sandbox. Private ranges and metadata endpoints are always blocked. */
34
+ export type SandboxNetworkPreset = "none" | "dev" | "open";
35
+ /**
36
+ * What computer an agent needs. The Runtime decides where it runs; nothing here names a backend.
37
+ * Every field is optional; omitted fields take Runtime defaults.
38
+ */
39
+ export interface SandboxManifest {
40
+ /** OCI image reference. Default: the Runtime's default sandbox image. */
41
+ readonly image?: string;
42
+ readonly network?: {
43
+ /** Default: "dev" (package registries and code hosts over HTTPS). */
44
+ readonly preset?: SandboxNetworkPreset;
45
+ /** Extra hosts to allow, e.g. "api.github.com" or "*.example.com". */
46
+ readonly allow?: readonly string[];
47
+ };
48
+ readonly resources?: {
49
+ readonly cpus?: number;
50
+ /** Size such as "512MiB" or "2GiB". */
51
+ readonly memory?: string;
52
+ };
53
+ /** Stop compute after this long without use, e.g. "15m". Files persist. */
54
+ readonly idle?: string;
55
+ }
11
56
  export interface CapabilityManifest {
12
57
  readonly id: string;
13
- readonly kind: "agent" | "capability" | "middleware";
14
- /** @deprecated Prefer beforeModelCall / afterModelCall flags. */
15
- readonly hasMiddleware: boolean;
58
+ readonly type: "agent" | "agent-plugin";
59
+ readonly name?: string;
60
+ readonly description?: string;
61
+ readonly metadata?: JsonObject;
16
62
  readonly instructions?: readonly string[];
17
- readonly tools?: readonly ManifestTool[];
18
- /** True when an implementations entry provides beforeModelCall for this capability. */
19
- readonly beforeModelCall?: boolean;
20
- /** True when an implementations entry provides afterModelCall for this capability. */
21
- readonly afterModelCall?: boolean;
22
- /**
23
- * @deprecated Model resolution is Runtime-owned. Legacy local snapshots may still carry this;
24
- * new manifests omit it.
25
- */
26
- readonly model?: Pick<ModelDirective, "id" | "controls">;
63
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
64
+ readonly tools?: readonly ToolManifest[];
65
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
66
+ /** Present when this capability gives the agent a Runtime-owned sandbox. */
67
+ readonly sandbox?: SandboxManifest;
68
+ /** Hook points this capability registered, in canonical order. */
69
+ readonly hooks?: readonly HookManifest[];
70
+ }
71
+ /** Reserved. Empty until later fields are defined. Omit `runtime` while it has no fields. */
72
+ export interface RuntimeManifest {
27
73
  }
28
74
  export interface AgentManifest {
29
- readonly schemaVersion: ManifestSchemaVersion;
75
+ readonly manifestSchemaVersion: ManifestSchemaVersion;
30
76
  readonly id: string;
31
- readonly name: string;
77
+ readonly name?: string;
78
+ readonly description?: string;
79
+ readonly metadata?: JsonObject;
32
80
  readonly outputSchema?: JsonObject;
33
81
  readonly capabilities: readonly CapabilityManifest[];
82
+ readonly runtime?: RuntimeManifest;
34
83
  }
@@ -1,7 +1,15 @@
1
1
  import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
2
  import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
- import type { ContextItem, Tripwire } from "./shared.js";
4
- import type { AfterModelCallFn, BeforeModelCallFn } from "./dynamics.js";
3
+ import type { McpServerManifest, SandboxManifest, SkillManifest } from "./manifest.js";
4
+ /** Skill files held on the developer binding. Not a manifest field. */
5
+ export interface SkillRecord {
6
+ readonly name: string;
7
+ readonly description: string;
8
+ readonly instructions: string;
9
+ readonly resources?: Readonly<Record<string, string>>;
10
+ }
11
+ import type { ContextItem, JsonObject, Tripwire } from "./shared.js";
12
+ import type { AfterHooks, BeforeHooks } from "./dynamics.js";
5
13
  import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
6
14
  interface StepRequestBase {
7
15
  /** Opaque identity of the execution that owns this Step. */
@@ -51,17 +59,31 @@ export type CapabilityItems<Item> = readonly Item[] | Readonly<{
51
59
  }>;
52
60
  export interface CapabilityDeclaration<Info = unknown> {
53
61
  readonly id: string;
62
+ readonly type?: "agent" | "agent-plugin";
63
+ readonly name?: string;
64
+ readonly description?: string;
65
+ readonly metadata?: JsonObject;
54
66
  readonly tools?: CapabilityItems<ToolDefinition<any, Info, any>>;
55
67
  readonly instructions?: CapabilityItems<string>;
68
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
69
+ /** File contents for load_skill. Omitted from the manifest. */
70
+ readonly skillRecords?: Readonly<Record<string, SkillRecord>>;
71
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
72
+ /** Runtime-owned sandbox requirements. Declare the built-in sandbox tools alongside it. */
73
+ readonly sandbox?: SandboxManifest;
74
+ /** Resolved package directory. Not projected into the manifest. */
75
+ readonly pluginRoot?: string;
56
76
  /**
57
77
  * @deprecated Model resolution is Runtime-owned. Not projected into the harness manifest.
58
78
  * Kept for local middleware composition through 1.0.
59
79
  */
60
80
  readonly model?: ModelDirective;
61
- /** @deprecated Prefer beforeModelCall / afterModelCall. Kept through 1.0. */
81
+ /** @deprecated Prefer before / after hooks. Kept through 1.0. */
62
82
  readonly middleware?: StepMiddleware<Info>;
63
- readonly beforeModelCall?: BeforeModelCallFn<Info>;
64
- readonly afterModelCall?: AfterModelCallFn<Info>;
83
+ /** Run before each turn or each model call (step). */
84
+ readonly before?: BeforeHooks<Info>;
85
+ /** Run after each model call (step) or after the turn's final answer. */
86
+ readonly after?: AfterHooks<Info>;
65
87
  }
66
88
  export interface MiddlewareContributions {
67
89
  readonly instructions?: readonly string[];
@@ -1,6 +1,13 @@
1
- import type { ZodType } from "zod";
1
+ import type { z } from "zod";
2
2
  import type { DeferredOutcome, JsonObject, JsonValue } from "./shared.js";
3
3
  import type { ModelAdapter } from "./model.js";
4
+ /**
5
+ * Zod classic schemas accepted as tool contracts.
6
+ * Use core `$ZodType` so concrete schemas (e.g. ZodObject) stay assignable on
7
+ * zod 4.6+, where ZodType gained validate/validateAsync methods that break
8
+ * ZodObject → ZodType assignability in some TypeScript configurations.
9
+ */
10
+ type ZodToolSchema<T = unknown> = z.core.$ZodType<T, unknown>;
4
11
  export interface SchemaIssue {
5
12
  readonly path: readonly (string | number)[];
6
13
  readonly code: string;
@@ -39,8 +46,8 @@ export interface StandardSchemaIssue {
39
46
  readonly path?: readonly (string | number | symbol)[];
40
47
  readonly code?: string;
41
48
  }
42
- export type ToolSchemaSource<T = unknown> = ZodType<T> | StandardToolSchema<any, T> | ToolSchema<T>;
43
- export type SchemaOutput<Schema> = Schema extends ZodType<infer Value> ? Value : Schema extends StandardToolSchema<any, infer Value> ? Value : Schema extends ToolSchema<infer Value> ? Value : never;
49
+ export type ToolSchemaSource<T = unknown> = ZodToolSchema<T> | StandardToolSchema<any, T> | ToolSchema<T>;
50
+ export type SchemaOutput<Schema> = Schema extends z.core.$ZodType<infer Value, any> ? Value : Schema extends StandardToolSchema<any, infer Value> ? Value : Schema extends ToolSchema<infer Value> ? Value : never;
44
51
  export type ToolInputSchema = ToolSchemaSource;
45
52
  export type ToolOutputSchema = ToolSchemaSource;
46
53
  type OutputFor<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : ToolContent;
@@ -109,7 +116,7 @@ interface ToolExecutionContextBase {
109
116
  readonly idempotencyKey: string;
110
117
  /** True when this invocation is being offered again after an interrupted active call. */
111
118
  readonly redelivery?: boolean;
112
- /** Durable session memory (tools write; beforeModelCall reads). */
119
+ /** Durable session memory (tools write; hooks read). */
113
120
  readonly state: SessionStateBag;
114
121
  /** Session identity stub — Runtime fills this later. */
115
122
  readonly session: {
@@ -0,0 +1,17 @@
1
+ /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
+ /** Built-in tools every sandbox capability declares. The Runtime executes them. */
3
+ export declare const SANDBOX_TOOL_NAMES: readonly ["bash", "read", "write", "edit", "grep", "glob"];
4
+ export type SandboxToolName = (typeof SANDBOX_TOOL_NAMES)[number];
5
+ export declare const SANDBOX_WORKSPACE = "/workspace";
6
+ export declare const SANDBOX_NETWORK_PRESETS: readonly ["none", "dev", "open"];
7
+ /** Manifest fields this version implements. Anything else is rejected with a teaching error. */
8
+ export declare const SANDBOX_FIELDS: readonly ["image", "network", "resources", "idle"];
9
+ /** Fields from the sandbox design that later versions will accept. */
10
+ export declare const SANDBOX_DEFERRED_FIELDS: readonly ["setup", "setupKey", "files", "secrets", "mount", "onStart", "scope", "isolation", "own", "tools", "snapshot"];
11
+ export declare function isSandboxToolName(name: string): name is SandboxToolName;
12
+ /** Parse "15m", "30s", "1h" into milliseconds. Returns undefined when invalid. */
13
+ export declare function parseSandboxDuration(value: string): number | undefined;
14
+ /** Parse "512MiB", "2GiB" into bytes. Returns undefined when invalid. */
15
+ export declare function parseSandboxSize(value: string): number | undefined;
16
+ /** A host name, optionally with a leading "*." wildcard. No scheme, port, path or IP literal. */
17
+ export declare function isSandboxHostPattern(value: string): boolean;
@@ -0,0 +1,64 @@
1
+ /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
+ /** Built-in tools every sandbox capability declares. The Runtime executes them. */
3
+ export const SANDBOX_TOOL_NAMES = Object.freeze([
4
+ "bash",
5
+ "read",
6
+ "write",
7
+ "edit",
8
+ "grep",
9
+ "glob",
10
+ ]);
11
+ export const SANDBOX_WORKSPACE = "/workspace";
12
+ export const SANDBOX_NETWORK_PRESETS = Object.freeze(["none", "dev", "open"]);
13
+ /** Manifest fields this version implements. Anything else is rejected with a teaching error. */
14
+ export const SANDBOX_FIELDS = Object.freeze(["image", "network", "resources", "idle"]);
15
+ /** Fields from the sandbox design that later versions will accept. */
16
+ export const SANDBOX_DEFERRED_FIELDS = Object.freeze([
17
+ "setup",
18
+ "setupKey",
19
+ "files",
20
+ "secrets",
21
+ "mount",
22
+ "onStart",
23
+ "scope",
24
+ "isolation",
25
+ "own",
26
+ "tools",
27
+ "snapshot",
28
+ ]);
29
+ export function isSandboxToolName(name) {
30
+ return SANDBOX_TOOL_NAMES.includes(name);
31
+ }
32
+ const DURATION = /^(\d+)(ms|s|m|h|d)$/;
33
+ const DURATION_MS = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
34
+ /** Parse "15m", "30s", "1h" into milliseconds. Returns undefined when invalid. */
35
+ export function parseSandboxDuration(value) {
36
+ const match = DURATION.exec(value.trim());
37
+ if (!match)
38
+ return undefined;
39
+ const amount = Number(match[1]);
40
+ return amount > 0 ? amount * DURATION_MS[match[2]] : undefined;
41
+ }
42
+ const SIZE = /^(\d+)(B|KiB|MiB|GiB|TiB)$/;
43
+ const SIZE_BYTES = { B: 1, KiB: 1024, MiB: 1024 ** 2, GiB: 1024 ** 3, TiB: 1024 ** 4 };
44
+ /** Parse "512MiB", "2GiB" into bytes. Returns undefined when invalid. */
45
+ export function parseSandboxSize(value) {
46
+ const match = SIZE.exec(value.trim());
47
+ if (!match)
48
+ return undefined;
49
+ const amount = Number(match[1]);
50
+ return amount > 0 ? amount * SIZE_BYTES[match[2]] : undefined;
51
+ }
52
+ const LABEL = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/;
53
+ /** A host name, optionally with a leading "*." wildcard. No scheme, port, path or IP literal. */
54
+ export function isSandboxHostPattern(value) {
55
+ const host = value.startsWith("*.") ? value.slice(2) : value;
56
+ if (host.length === 0 || host.length > 253)
57
+ return false;
58
+ const labels = host.toLowerCase().split(".");
59
+ if (labels.length < 2)
60
+ return false;
61
+ if (labels.every((label) => /^\d+$/.test(label)))
62
+ return false;
63
+ return labels.every((label) => LABEL.test(label));
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.1.1-beta",
3
+ "version": "0.3.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",
@@ -33,9 +33,9 @@
33
33
  "@noble/hashes": "^1.8.0"
34
34
  },
35
35
  "devDependencies": {
36
- "typescript": "npm:@typescript/typescript6@^6.0.2",
37
36
  "@types/node": "^26.5.0",
38
- "vitest": "^5.0.0"
37
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
38
+ "vitest": "^5.0.1"
39
39
  },
40
40
  "exports": {
41
41
  ".": {
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "peerDependencies": {
59
- "zod": "^4.5.4"
59
+ "zod": "^4.6.5"
60
60
  },
61
61
  "sideEffects": false
62
62
  }