@nylorun/core 0.2.0-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.
@@ -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,6 +1,7 @@
1
1
  import type { JsonObject } from "./shared.js";
2
+ import type { HookManifest } from "./dynamics.js";
2
3
  /** Published manifest schema version (no top-level model — Runtime-owned). */
3
- export type ManifestSchemaVersion = 3;
4
+ export type ManifestSchemaVersion = 4;
4
5
  export interface ToolManifest {
5
6
  readonly name: string;
6
7
  readonly description?: string;
@@ -29,6 +30,29 @@ export type McpServerManifest = {
29
30
  readonly url: string;
30
31
  readonly headers?: Readonly<Record<string, string>>;
31
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
+ }
32
56
  export interface CapabilityManifest {
33
57
  readonly id: string;
34
58
  readonly type: "agent" | "agent-plugin";
@@ -39,8 +63,10 @@ export interface CapabilityManifest {
39
63
  readonly skills?: Readonly<Record<string, SkillManifest>>;
40
64
  readonly tools?: readonly ToolManifest[];
41
65
  readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
42
- readonly beforeModelCall?: boolean;
43
- readonly afterModelCall?: boolean;
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[];
44
70
  }
45
71
  /** Reserved. Empty until later fields are defined. Omit `runtime` while it has no fields. */
46
72
  export interface RuntimeManifest {
@@ -1,6 +1,6 @@
1
1
  import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
2
  import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
- import type { McpServerManifest, SkillManifest } from "./manifest.js";
3
+ import type { McpServerManifest, SandboxManifest, SkillManifest } from "./manifest.js";
4
4
  /** Skill files held on the developer binding. Not a manifest field. */
5
5
  export interface SkillRecord {
6
6
  readonly name: string;
@@ -9,7 +9,7 @@ export interface SkillRecord {
9
9
  readonly resources?: Readonly<Record<string, string>>;
10
10
  }
11
11
  import type { ContextItem, JsonObject, Tripwire } from "./shared.js";
12
- import type { AfterModelCallFn, BeforeModelCallFn } from "./dynamics.js";
12
+ import type { AfterHooks, BeforeHooks } from "./dynamics.js";
13
13
  import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
14
14
  interface StepRequestBase {
15
15
  /** Opaque identity of the execution that owns this Step. */
@@ -69,6 +69,8 @@ export interface CapabilityDeclaration<Info = unknown> {
69
69
  /** File contents for load_skill. Omitted from the manifest. */
70
70
  readonly skillRecords?: Readonly<Record<string, SkillRecord>>;
71
71
  readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
72
+ /** Runtime-owned sandbox requirements. Declare the built-in sandbox tools alongside it. */
73
+ readonly sandbox?: SandboxManifest;
72
74
  /** Resolved package directory. Not projected into the manifest. */
73
75
  readonly pluginRoot?: string;
74
76
  /**
@@ -76,10 +78,12 @@ export interface CapabilityDeclaration<Info = unknown> {
76
78
  * Kept for local middleware composition through 1.0.
77
79
  */
78
80
  readonly model?: ModelDirective;
79
- /** @deprecated Prefer beforeModelCall / afterModelCall. Kept through 1.0. */
81
+ /** @deprecated Prefer before / after hooks. Kept through 1.0. */
80
82
  readonly middleware?: StepMiddleware<Info>;
81
- readonly beforeModelCall?: BeforeModelCallFn<Info>;
82
- 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>;
83
87
  }
84
88
  export interface MiddlewareContributions {
85
89
  readonly instructions?: readonly string[];
@@ -116,7 +116,7 @@ interface ToolExecutionContextBase {
116
116
  readonly idempotencyKey: string;
117
117
  /** True when this invocation is being offered again after an interrupted active call. */
118
118
  readonly redelivery?: boolean;
119
- /** Durable session memory (tools write; beforeModelCall reads). */
119
+ /** Durable session memory (tools write; hooks read). */
120
120
  readonly state: SessionStateBag;
121
121
  /** Session identity stub — Runtime fills this later. */
122
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.2.0-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",