@nylorun/core 0.34.0-beta → 0.36.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/compatibility.d.ts +9 -1
  3. package/dist/compatibility.js +8 -0
  4. package/dist/contracts.d.ts +352 -6
  5. package/dist/contracts.js +180 -6
  6. package/dist/definition/variant.js +8 -1
  7. package/dist/engine/blocks.d.ts +2 -0
  8. package/dist/engine/blocks.js +7 -0
  9. package/dist/engine/explain.d.ts +1 -1
  10. package/dist/engine/explain.js +27 -5
  11. package/dist/engine/index.d.ts +1 -0
  12. package/dist/engine/index.js +1 -0
  13. package/dist/engine/names.d.ts +1 -1
  14. package/dist/engine/names.js +1 -0
  15. package/dist/engine/preview.d.ts +6 -0
  16. package/dist/engine/preview.js +3 -1
  17. package/dist/engine/projection.d.ts +10 -6
  18. package/dist/engine/projection.js +110 -6
  19. package/dist/engine/tools.d.ts +32 -0
  20. package/dist/engine/tools.js +85 -1
  21. package/dist/folder/compile.d.ts +3 -3
  22. package/dist/folder/compile.js +82 -12
  23. package/dist/folder/engine.d.ts +14 -2
  24. package/dist/folder/engine.js +17 -3
  25. package/dist/folder/index.d.ts +2 -0
  26. package/dist/folder/index.js +2 -0
  27. package/dist/folder/migrate-v3.d.ts +20 -0
  28. package/dist/folder/migrate-v3.js +124 -0
  29. package/dist/folder/nested.js +5 -0
  30. package/dist/folder/schemas.js +19 -6
  31. package/dist/folder/v3.d.ts +66 -0
  32. package/dist/folder/v3.js +139 -0
  33. package/dist/harness-api/harness-api.schema.json +19 -4
  34. package/dist/harness-api/json-schema.js +3 -2
  35. package/dist/harness-api/schema.d.ts +6 -0
  36. package/dist/harness-api/schema.js +9 -2
  37. package/dist/manifest-schemas.js +6 -4
  38. package/dist/plugins/bundle.generated.d.ts +120 -0
  39. package/dist/plugins/bundle.generated.js +143 -0
  40. package/dist/plugins/index.d.ts +65 -0
  41. package/dist/plugins/index.js +62 -0
  42. package/dist/schemas/agent-folder/agent-md.schema.json +26 -4
  43. package/dist/schemas/agent-folder/runtime.schema.json +22 -1
  44. package/dist/schemas/agent-manifest.schema.json +72 -1
  45. package/dist/schemas/harness-manifest.schema.json +51 -1
  46. package/dist/schemas/runtime-manifest.schema.json +22 -1
  47. package/dist/types/manifest.d.ts +14 -0
  48. package/package.json +1 -1
@@ -11,6 +11,7 @@
11
11
  * artifacts: { read: true, save: false } # save needs a computer
12
12
  * outputs: true # save /workspace/outputs when a turn ends; needs a computer
13
13
  * toolSearch: false # no automatic deferral; a server's own `deferred` still applies
14
+ * triggers: true # the triggers tool and its text (D83); the root agent's only
14
15
  * instructions: # a block's wording, replaced by a file under engine/
15
16
  * memory: engine/memory.md
16
17
  * ```
@@ -27,7 +28,7 @@ import { DEFAULT_ENGINE_TOOL_LIMITS, engineProjection } from "../engine/projecti
27
28
  import { TOOL_SEARCH_TOOL } from "../engine/tools.js";
28
29
  import { suggestion } from "./suggest.js";
29
30
  /** The keys of `AGENT.md`'s `engine:` block. */
30
- export const ENGINE_KEYS = ["sandbox", "artifacts", "outputs", "toolSearch", "instructions"];
31
+ export const ENGINE_KEYS = ["sandbox", "artifacts", "outputs", "toolSearch", "triggers", "instructions"];
31
32
  const ARTIFACT_KEYS = ["read", "save"];
32
33
  /** Where a folder keeps the files that replace a block's wording. */
33
34
  export const ENGINE_TEXT_DIR = "engine";
@@ -145,6 +146,18 @@ export function engineDeclarations(value, options) {
145
146
  engine.toolSearch = value.toolSearch;
146
147
  }
147
148
  }
149
+ // triggers: the root agent's (D83). A subagent whose parent declares them is refused in
150
+ // `nested.ts`; one whose parent does not, here.
151
+ if (value.triggers !== undefined) {
152
+ const at = ["engine", "triggers"];
153
+ if (typeof value.triggers !== "boolean")
154
+ fail("value_invalid", "engine.triggers is true or false: true offers the agent the triggers tool, to set up its own schedules and follow-ups", at);
155
+ else {
156
+ if (role === "subagent" && value.triggers && parent?.triggers !== true)
157
+ subset("engine.triggers is true", at);
158
+ engine.triggers = value.triggers;
159
+ }
160
+ }
148
161
  if (value.instructions !== undefined) {
149
162
  const at = ["engine", "instructions"];
150
163
  if (!isObject(value.instructions))
@@ -186,11 +199,12 @@ export function engineDeclarations(value, options) {
186
199
  /**
187
200
  * The text blocks an agent gets, from what it declares and what the folder says of its session:
188
201
  * whether its runtime has a computer and sets `selfWake`, its skills, memory and loop settings,
189
- * and whether its MCP tools may be deferred. The harness's own projection decides them
202
+ * whether it is the root agent declaring `engine.triggers`, and whether its MCP tools may be
203
+ * deferred. The harness's own projection decides them
190
204
  * (`engineProjection`), so the list is what a session's system text holds.
191
205
  */
192
206
  export function engineBlocksOf(agent, facts) {
193
- const projection = engineProjection(agent, { ...(facts.computer ? { sandbox: { workspace: SANDBOX_WORKSPACE } } : {}), ...(facts.selfWake ? { selfWake: true } : {}) }, DEFAULT_ENGINE_TOOL_LIMITS, facts.memory && { access: facts.memory.access ?? "read_write", root: facts.memory.root, index: facts.memory.index !== false }, facts.plan, facts.connections);
207
+ const projection = engineProjection(agent, { ...(facts.computer ? { sandbox: { workspace: SANDBOX_WORKSPACE } } : {}), ...(facts.selfWake ? { selfWake: true } : {}) }, DEFAULT_ENGINE_TOOL_LIMITS, facts.memory && { access: facts.memory.access ?? "read_write", root: facts.memory.root, index: facts.memory.index !== false }, facts.plan, facts.connections, facts.triggers === true, facts.ask === true);
194
208
  const names = projection.blocks.map((block) => block.name);
195
209
  const servers = Object.values(agent.mcpServers ?? {});
196
210
  const deferrable = servers.length > 0 &&
@@ -10,3 +10,5 @@ export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderT
10
10
  export { folderOfManifest, type FolderOfManifest, type FolderOfManifestOptions } from "./decompile.js";
11
11
  export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas, type AgentFolderSchemaKind } from "./schemas.js";
12
12
  export { applyFolderFixes, type AppliedFolderFixes } from "./fix.js";
13
+ export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
14
+ export { folderV3Edit, type FolderV3Edit } from "./migrate-v3.js";
@@ -10,3 +10,5 @@ export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderT
10
10
  export { folderOfManifest } from "./decompile.js";
11
11
  export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas } from "./schemas.js";
12
12
  export { applyFolderFixes } from "./fix.js";
13
+ export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
14
+ export { folderV3Edit } from "./migrate-v3.js";
@@ -0,0 +1,20 @@
1
+ import { type PluginName } from "../plugins/index.js";
2
+ /** A folder file, migrated, or why it can't be. */
3
+ export type FolderV3Edit = {
4
+ readonly ok: true;
5
+ readonly agentMd: string;
6
+ readonly runtimeJson?: string;
7
+ readonly plugins: readonly PluginName[];
8
+ } | {
9
+ readonly ok: false;
10
+ readonly reason: string;
11
+ };
12
+ /**
13
+ * Migrates one `AGENT.md` (and, for the root, its folder's `runtime.json`). `role` is `subagent`
14
+ * for `agents/<id>/AGENT.md`, which declares no memory, loop or triggers of its own.
15
+ */
16
+ export declare function folderV3Edit(input: {
17
+ readonly agentMd: string;
18
+ readonly runtimeJson?: string;
19
+ readonly role: "root" | "subagent";
20
+ }): FolderV3Edit;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `agent-folder/2` → `agent-folder/3` (ADR-106): the plugins that keep what an agent gets, written
3
+ * in place of the declarations they stand for. `nylorun migrate folder <dir> --to 3` runs it on a
4
+ * folder's `AGENT.md` and each subagent's, and on `runtime.json`, then checks that every agent
5
+ * keeps the same tools and features.
6
+ *
7
+ * - `memory` → `nylorun-memory`; its `instructions` move to the end of the body.
8
+ * - `engine.triggers`, or `runtime.selfWake` → `nylorun-triggers`.
9
+ * - `loop.plan` → `nylorun-plan`; `loop.connections` → `nylorun-interactions`, with `ask` off.
10
+ * - `engine.artifacts` → `nylorun-artifacts`, with the tools it left out off.
11
+ * - `engine.sandbox` → `nylorun-sandbox`, with the tools it left out off.
12
+ *
13
+ * A declaration v3 can't express stops it: a read-only root memory, `memory.index: false`, or a
14
+ * replaced wording (`engine.instructions`).
15
+ */
16
+ import { Document, isMap, parseDocument, YAMLMap, YAMLSeq } from "yaml";
17
+ import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
18
+ import { RUNTIME_SERVER, pluginTools } from "../plugins/index.js";
19
+ import { AGENT_FOLDER_V3 } from "./v3.js";
20
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
21
+ function split(text) {
22
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
23
+ const lines = text.replace(/^/, "").split(/\r?\n/);
24
+ if (lines[0]?.trimEnd() !== "---")
25
+ return undefined;
26
+ const end = lines.findIndex((line, index) => index > 0 && line.trimEnd() === "---");
27
+ if (end < 0)
28
+ return undefined;
29
+ return { front: lines.slice(1, end).join("\n"), body: lines.slice(end + 1).join("\n"), eol };
30
+ }
31
+ /**
32
+ * Migrates one `AGENT.md` (and, for the root, its folder's `runtime.json`). `role` is `subagent`
33
+ * for `agents/<id>/AGENT.md`, which declares no memory, loop or triggers of its own.
34
+ */
35
+ export function folderV3Edit(input) {
36
+ const parts = split(input.agentMd);
37
+ if (!parts)
38
+ return { ok: false, reason: "AGENT.md has no frontmatter" };
39
+ const doc = parseDocument(parts.front);
40
+ const data = (doc.toJS() ?? {});
41
+ const runtime = input.runtimeJson === undefined ? undefined : JSON.parse(input.runtimeJson);
42
+ const memory = isObject(data.memory) ? data.memory : undefined;
43
+ const loop = isObject(data.loop) ? data.loop : {};
44
+ const engine = isObject(data.engine) ? data.engine : {};
45
+ if (engine.instructions !== undefined)
46
+ return { ok: false, reason: "engine.instructions replaces the engine's wording, which agent-folder/3 doesn't do: the plugins' words are the Runtime's. Remove it first" };
47
+ if (memory && memory.access === "read_only" && input.role === "root")
48
+ return { ok: false, reason: "memory.access: read_only for the root agent has no plugin form: in agent-folder/3 the root agent may write its memory" };
49
+ if (memory && memory.index === false)
50
+ return { ok: false, reason: "memory.index: false has no plugin form: nylorun-memory always pins its index" };
51
+ const plugins = [];
52
+ const off = [];
53
+ if (memory && input.role === "root")
54
+ plugins.push("nylorun-memory");
55
+ if (input.role === "root" && (engine.triggers === true || runtime?.selfWake === true))
56
+ plugins.push("nylorun-triggers");
57
+ if (input.role === "root" && loop.plan === true)
58
+ plugins.push("nylorun-plan");
59
+ if (input.role === "root" && loop.connections === true) {
60
+ plugins.push("nylorun-interactions");
61
+ off.push("ask");
62
+ }
63
+ const artifacts = isObject(engine.artifacts) ? engine.artifacts : {};
64
+ if (artifacts.read === true || artifacts.save === true) {
65
+ plugins.push("nylorun-artifacts");
66
+ if (artifacts.read !== true)
67
+ off.push("read_artifact");
68
+ if (artifacts.save !== true)
69
+ off.push("save_artifact");
70
+ }
71
+ const sandbox = Array.isArray(engine.sandbox) ? engine.sandbox : [];
72
+ if (sandbox.length > 0) {
73
+ plugins.push("nylorun-sandbox");
74
+ off.push(...SANDBOX_TOOL_NAMES.filter((tool) => !sandbox.includes(tool)));
75
+ }
76
+ // The frontmatter, edited in place: comments and the other keys stay as they are.
77
+ doc.delete("memory");
78
+ doc.delete("loop");
79
+ const engineNode = doc.get("engine", true);
80
+ if (isMap(engineNode)) {
81
+ for (const key of ["sandbox", "artifacts", "triggers", "instructions"])
82
+ engineNode.delete(key);
83
+ if (engineNode.items.length === 0)
84
+ doc.delete("engine");
85
+ }
86
+ if (input.role === "root") {
87
+ if (doc.has("format"))
88
+ doc.set("format", AGENT_FOLDER_V3);
89
+ else
90
+ doc.contents.items.unshift(doc.createPair("format", AGENT_FOLDER_V3));
91
+ }
92
+ if (plugins.length > 0) {
93
+ const seq = new YAMLSeq();
94
+ for (const name of plugins)
95
+ seq.add(doc.createNode(name));
96
+ seq.flow = true;
97
+ doc.set("plugins", seq);
98
+ }
99
+ if (off.length > 0) {
100
+ const known = new Set(plugins.flatMap(pluginTools));
101
+ const tools = Object.fromEntries(off.filter((tool) => known.has(tool)).map((tool) => [tool, { enabled: false }]));
102
+ if (Object.keys(tools).length > 0) {
103
+ const node = doc.createNode({ tools });
104
+ for (const pair of node.items)
105
+ if (isMap(pair.value))
106
+ pair.value.flow = false;
107
+ const servers = doc.get("mcpServers", true);
108
+ if (isMap(servers))
109
+ servers.set(RUNTIME_SERVER, node);
110
+ else
111
+ doc.set("mcpServers", doc.createNode({ [RUNTIME_SERVER]: { tools } }));
112
+ }
113
+ }
114
+ const front = new Document(doc.contents).toString({ lineWidth: 0 }).replace(/\n$/, "");
115
+ const instructions = memory && typeof memory.instructions === "string" && memory.instructions.trim() !== "" ? memory.instructions.trim() : undefined;
116
+ const body = instructions === undefined ? parts.body : `${parts.body.replace(/\s+$/, "")}\n\n${instructions}\n`;
117
+ const agentMd = ["---", front, "---", body].join("\n").replaceAll("\n", parts.eol);
118
+ let runtimeJson = input.runtimeJson;
119
+ if (runtime && runtime.selfWake !== undefined) {
120
+ const { selfWake: _wake, ...rest } = runtime;
121
+ runtimeJson = `${JSON.stringify(rest, null, 2)}\n`;
122
+ }
123
+ return { ok: true, agentMd, ...(runtimeJson === undefined ? {} : { runtimeJson }), plugins };
124
+ }
@@ -197,6 +197,11 @@ function nestedChecks(ctx) {
197
197
  for (const [key, message] of Object.entries(keys))
198
198
  if (ctx.front[key] !== undefined)
199
199
  refuse(message, AGENT_FILE, [key]);
200
+ // Triggers are the root agent's (D83): a subagent of a parent without them fails engine_subset.
201
+ if (isObject(ctx.front.engine) &&
202
+ ctx.front.engine.triggers === true &&
203
+ (ctx.scope.role === "stage" || ctx.scope.engineFacts?.engine?.triggers === true))
204
+ refuse(`triggers are the root agent's: ${what} never sets up triggers, so leave engine.triggers out here`, AGENT_FILE, ["engine", "triggers"]);
200
205
  // Agent manifest v7, which embeds an agent, has no place for a credential or a skill's secrets.
201
206
  const settings = isObject(ctx.front.mcpServers) ? ctx.front.mcpServers : {};
202
207
  for (const [key, server] of Object.entries(isObject(ctx.harness.mcpServers) ? ctx.harness.mcpServers : {})) {
@@ -17,6 +17,7 @@
17
17
  * document says less than the compiler only where JSON Schema cannot: that a path names a file of
18
18
  * the folder, a cron, a time zone, which server or skill a name means.
19
19
  */
20
+ import { PLUGIN_NAMES } from "../plugins/index.js";
20
21
  import { z } from "zod";
21
22
  import { AGENT_MANIFEST_NAME_PATTERN, ENVIRONMENT_NAME_PATTERN, HarnessIdSchema, AgentModelSchema, HarnessMemorySchema, HttpToolTargetSchema, McpToolSettingsSchema, RuntimeSectionSchema, TOOL_SECRET_NAME_PATTERN, TriggerSchema, } from "../contracts.js";
22
23
  import { DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
@@ -52,11 +53,13 @@ function fromZod(schema, defs, description) {
52
53
  /**
53
54
  * A kind's revision within format 1, when its document gained an optional key (a published `$id`
54
55
  * names one document for good): `AGENT.md` took `model` (Host feature `agent-model`), published
55
- * as `agent-md.1.json`, then `format: agent-folder/2` and `engine` (ADR-100), as `agent-md.2.json`;
56
+ * as `agent-md.1.json`, then `format: agent-folder/2` and `engine` (ADR-100), as `agent-md.2.json`,
57
+ * then `engine.triggers` (D83), as `agent-md.3.json`, then `format: agent-folder/3` and
58
+ * `plugins` (ADR-106), as `agent-md.4.json`;
56
59
  * `runtime.json` took a secret slot's `toolPrefix` (Host feature `secret-routing`), published as
57
- * `runtime.1.json`.
60
+ * `runtime.1.json`, then `limits.triggers` (D83), as `runtime.2.json`.
58
61
  */
59
- const REVISIONS = { "agent-md": 2, runtime: 1 };
62
+ const REVISIONS = { "agent-md": 4, runtime: 2 };
60
63
  /** One document: its `$id` from its kind, then the body, then the `$defs` its parts named. */
61
64
  function document(kind, title, description, body, defs) {
62
65
  const revision = REVISIONS[kind];
@@ -96,8 +99,8 @@ function agentMd() {
96
99
  name: { type: "string", pattern: AGENT_MANIFEST_NAME_PATTERN.source, description: "The agent manifest's name, the folder's when it is saved under one" },
97
100
  description: { type: "string", minLength: 1, description: "What the agent does, in a sentence" },
98
101
  format: {
99
- enum: [1, 2, "agent-folder/1", "agent-folder/2"],
100
- description: "The folder's format: agent-folder/1 (or 1, the default), which gets every engine feature by default, or agent-folder/2 (or 2), which declares each in engine",
102
+ enum: [1, 2, 3, "agent-folder/1", "agent-folder/2", "agent-folder/3"],
103
+ description: "The folder's format: agent-folder/1 (or 1, the default), which gets every engine feature by default; agent-folder/2 (or 2), which declares each in engine; or agent-folder/3 (or 3), which declares the Runtime's features as plugins",
101
104
  },
102
105
  harness: fromZod(HarnessIdSchema, defs, "The harness that runs the loop: nylorun (ours, the default) or a custom harness's id"),
103
106
  inputSchema: ref("JsonSchemaOrPath", "A flow's input (a folder with flow.json); an agent's input is the message"),
@@ -119,10 +122,16 @@ function agentMd() {
119
122
  type: "object",
120
123
  description: "The harness's own settings, passed to it each turn; the nylorun harness reads plan (true offers the agent update_plan) and connections (true offers it request_connection)",
121
124
  },
125
+ plugins: {
126
+ type: "array",
127
+ items: { enum: [...PLUGIN_NAMES] },
128
+ uniqueItems: true,
129
+ description: "agent-folder/3: the Runtime's plugins the agent uses, which share the server nylorun (mcpServers.nylorun.tools turns one of their tools off): nylorun-memory, nylorun-triggers, nylorun-plan, nylorun-interactions, nylorun-artifacts, nylorun-sandbox (needs a computer)",
130
+ },
122
131
  model: fromZod(AgentModelSchema, defs, "The model the agent runs on: <provider>/<model>, such as anthropic/claude-sonnet-4-5"),
123
132
  engine: {
124
133
  type: "object",
125
- description: "agent-folder/2: the engine features the agent uses, and nothing else is added: sandbox (the sandbox tools), artifacts (read_artifact, save_artifact), outputs (the outputs folder), toolSearch (MCP tools deferred past the threshold), instructions (a block's wording, from a file under engine/)",
134
+ description: "agent-folder/2: the engine features the agent uses, and nothing else is added: sandbox (the sandbox tools), artifacts (read_artifact, save_artifact), outputs (the outputs folder), toolSearch (MCP tools deferred past the threshold), triggers (the triggers tool, the root agent's), instructions (a block's wording, from a file under engine/)",
126
135
  properties: {
127
136
  sandbox: {
128
137
  type: "array",
@@ -143,6 +152,10 @@ function agentMd() {
143
152
  type: "boolean",
144
153
  description: "Defer the MCP tools behind tool_search when their schemas pass the threshold; a server's own deferred applies either way",
145
154
  },
155
+ triggers: {
156
+ type: "boolean",
157
+ description: "The triggers tool and its text: the agent sets up its own schedules and follow-ups, kept by the Agent; the root agent's only",
158
+ },
146
159
  instructions: {
147
160
  type: "object",
148
161
  propertyNames: { enum: [...ENGINE_BLOCK_NAMES] },
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `agent-folder/3` (ADR-106): a folder declares the Runtime's features as plugins, by name, and
3
+ * narrows their tools with the settings any MCP server takes:
4
+ *
5
+ * ```yaml
6
+ * format: agent-folder/3
7
+ * plugins: [nylorun-memory, nylorun-triggers, nylorun-plan, nylorun-interactions, nylorun-artifacts, nylorun-sandbox]
8
+ * mcpServers:
9
+ * nylorun:
10
+ * tools: { save_artifact: { enabled: false } }
11
+ * engine: { outputs: true, toolSearch: false } # the harness's own, as in agent-folder/2
12
+ * ```
13
+ *
14
+ * The compiler reads it as the `agent-folder/2` declarations it stands for (`memory`, `loop`,
15
+ * `engine.sandbox`, `engine.artifacts`, `engine.triggers`), so the Runtime checks a v3 agent as it
16
+ * checks a v2 one, and records the plugins in `harness.engine.plugins`, each with the tools left on
17
+ * and the hash of its files. The engine's projection then presents those tools as server
18
+ * `nylorun` (`engineProjection`).
19
+ */
20
+ import { type PluginName } from "../plugins/index.js";
21
+ import type { HarnessEnginePlugin } from "../types/manifest.js";
22
+ import type { ReportOptions } from "./context.js";
23
+ /** The format name a v3 folder writes. */
24
+ export declare const AGENT_FOLDER_V3 = "agent-folder/3";
25
+ /** The keys of `AGENT.md` a v3 folder declares as plugins instead. */
26
+ export declare const V3_REFUSED_KEYS: readonly ["memory", "loop"];
27
+ /** The keys of `engine:` a v3 folder declares as plugins instead. */
28
+ export declare const V3_REFUSED_ENGINE_KEYS: readonly ["sandbox", "artifacts", "triggers", "instructions"];
29
+ /** Whether `value` names the v3 format: `agent-folder/3` or `3`. */
30
+ export declare function isFolderV3(value: unknown): boolean;
31
+ type Fail = (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
32
+ /** The plugins a v3 folder declares, each with the tools left on. */
33
+ export interface V3Plugins {
34
+ readonly plugins: {
35
+ readonly name: PluginName;
36
+ readonly tools: readonly string[];
37
+ }[];
38
+ /** The frontmatter keys they stand for, in `agent-folder/2`'s terms. */
39
+ readonly memory?: Record<string, unknown>;
40
+ readonly loop?: Record<string, unknown>;
41
+ readonly engine: Record<string, unknown>;
42
+ }
43
+ /**
44
+ * Reads a v3 frontmatter's `plugins:` and `mcpServers.nylorun`, refusing the keys it replaces.
45
+ * `parent` is a subagent's parent's plugins: a subagent's are a subset of them. Undefined, with
46
+ * the errors reported, when they are not valid.
47
+ */
48
+ export declare function v3Declarations(front: Record<string, unknown>, options: {
49
+ readonly error: Fail;
50
+ readonly computer: boolean;
51
+ readonly role: "root" | "subagent";
52
+ readonly parent?: readonly {
53
+ readonly name: string;
54
+ readonly tools: readonly string[];
55
+ }[];
56
+ }): V3Plugins | undefined;
57
+ /** `harness.engine.plugins`: each declared plugin with its tools, its hash, and the sandbox's hosts. */
58
+ export declare function enginePlugins(plugins: readonly {
59
+ readonly name: PluginName;
60
+ readonly tools: readonly string[];
61
+ }[], hosts: readonly string[] | undefined): HarnessEnginePlugin[];
62
+ /** The names of the declared plugins' skills, which a folder's own skill may not take. */
63
+ export declare function pluginSkillNames(plugins: readonly {
64
+ readonly name: PluginName;
65
+ }[]): string[];
66
+ export {};
@@ -0,0 +1,139 @@
1
+ /**
2
+ * `agent-folder/3` (ADR-106): a folder declares the Runtime's features as plugins, by name, and
3
+ * narrows their tools with the settings any MCP server takes:
4
+ *
5
+ * ```yaml
6
+ * format: agent-folder/3
7
+ * plugins: [nylorun-memory, nylorun-triggers, nylorun-plan, nylorun-interactions, nylorun-artifacts, nylorun-sandbox]
8
+ * mcpServers:
9
+ * nylorun:
10
+ * tools: { save_artifact: { enabled: false } }
11
+ * engine: { outputs: true, toolSearch: false } # the harness's own, as in agent-folder/2
12
+ * ```
13
+ *
14
+ * The compiler reads it as the `agent-folder/2` declarations it stands for (`memory`, `loop`,
15
+ * `engine.sandbox`, `engine.artifacts`, `engine.triggers`), so the Runtime checks a v3 agent as it
16
+ * checks a v2 one, and records the plugins in `harness.engine.plugins`, each with the tools left on
17
+ * and the hash of its files. The engine's projection then presents those tools as server
18
+ * `nylorun` (`engineProjection`).
19
+ */
20
+ import { PLUGIN_NAMES, RUNTIME_SERVER, isPluginName, pluginOf, pluginSkills, pluginTools, } from "../plugins/index.js";
21
+ import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
22
+ import { suggestion } from "./suggest.js";
23
+ /** The format name a v3 folder writes. */
24
+ export const AGENT_FOLDER_V3 = "agent-folder/3";
25
+ /** The keys of `AGENT.md` a v3 folder declares as plugins instead. */
26
+ export const V3_REFUSED_KEYS = ["memory", "loop"];
27
+ /** The keys of `engine:` a v3 folder declares as plugins instead. */
28
+ export const V3_REFUSED_ENGINE_KEYS = ["sandbox", "artifacts", "triggers", "instructions"];
29
+ const MIGRATE = "run nylorun migrate folder <dir> --to 3, which writes the plugins that keep what the agent gets today";
30
+ /** Whether `value` names the v3 format: `agent-folder/3` or `3`. */
31
+ export function isFolderV3(value) {
32
+ return value === 3 || value === AGENT_FOLDER_V3;
33
+ }
34
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
35
+ /**
36
+ * Reads a v3 frontmatter's `plugins:` and `mcpServers.nylorun`, refusing the keys it replaces.
37
+ * `parent` is a subagent's parent's plugins: a subagent's are a subset of them. Undefined, with
38
+ * the errors reported, when they are not valid.
39
+ */
40
+ export function v3Declarations(front, options) {
41
+ const { error, computer, role, parent } = options;
42
+ let valid = true;
43
+ const fail = (...args) => {
44
+ valid = false;
45
+ error(...args);
46
+ };
47
+ for (const key of V3_REFUSED_KEYS)
48
+ if (front[key] !== undefined)
49
+ fail("v3_refused", `${key} is a key of agent-folder/2: an agent-folder/3 folder declares the Runtime's features as plugins. Fix: ${MIGRATE}`, [key], { key: true });
50
+ if (isObject(front.engine))
51
+ for (const key of V3_REFUSED_ENGINE_KEYS)
52
+ if (front.engine[key] !== undefined)
53
+ fail("v3_refused", `engine.${key} is a key of agent-folder/2: in agent-folder/3 the plugins declare it, and engine keeps outputs and toolSearch. Fix: ${MIGRATE}`, ["engine", key], { key: true });
54
+ const names = [];
55
+ if (front.plugins !== undefined) {
56
+ if (!Array.isArray(front.plugins))
57
+ fail("value_invalid", `plugins is a list of the Runtime's plugins: ${PLUGIN_NAMES.join(", ")}`, ["plugins"]);
58
+ else
59
+ for (const [index, name] of front.plugins.entries()) {
60
+ if (!isPluginName(name)) {
61
+ const close = typeof name === "string" ? suggestion(name, PLUGIN_NAMES) : undefined;
62
+ fail("plugin_unknown", `${JSON.stringify(name)} is not one of the Runtime's plugins: ${PLUGIN_NAMES.join(", ")}.${close ? ` Did you mean '${close}'?` : ""}`, ["plugins", index]);
63
+ }
64
+ else if (names.includes(name))
65
+ fail("value_invalid", `plugins names ${name} twice`, ["plugins", index]);
66
+ else if (pluginOf(name).requires.includes("computer") && !computer)
67
+ fail("plugin_needs_computer", `${name} needs a computer, and the runtime has none. Fix: set "kind": "virtual" (or "pod") in runtime.json, or leave it out`, ["plugins", index]);
68
+ else if (role === "subagent" && parent !== undefined && !parent.some((item) => item.name === name))
69
+ fail("plugin_subset", `${name}, and the agent that holds this subagent does not declare it: a subagent's plugins are a subset of its parent's`, ["plugins", index]);
70
+ else
71
+ names.push(name);
72
+ }
73
+ }
74
+ // mcpServers.nylorun: the declared plugins' tools, turned off one by one, or all with "*".
75
+ const off = new Set();
76
+ const servers = isObject(front.mcpServers) ? front.mcpServers : undefined;
77
+ const settings = servers?.[RUNTIME_SERVER];
78
+ if (settings !== undefined) {
79
+ const at = ["mcpServers", RUNTIME_SERVER];
80
+ const known = names.flatMap(pluginTools);
81
+ if (!isObject(settings) || Object.keys(settings).some((key) => key !== "tools"))
82
+ fail("value_invalid", "mcpServers.nylorun takes tools: each declared plugin's tool, { enabled: false } to turn it off", at);
83
+ else if (settings.tools !== undefined) {
84
+ if (!isObject(settings.tools))
85
+ fail("value_invalid", "mcpServers.nylorun.tools is a map of tool names to { enabled: false }", [...at, "tools"]);
86
+ else
87
+ for (const [tool, value] of Object.entries(settings.tools)) {
88
+ if (tool !== "*" && !known.includes(tool)) {
89
+ const close = suggestion(tool, known);
90
+ fail("tool_unknown", `${tool} is not a tool of the plugins this folder declares (${known.join(", ") || "none"}).${close ? ` Did you mean '${close}'?` : ""}`, [...at, "tools", tool], { key: true });
91
+ continue;
92
+ }
93
+ if (!isObject(value) || Object.keys(value).some((key) => key !== "enabled") || typeof value.enabled !== "boolean") {
94
+ fail("value_invalid", `mcpServers.nylorun.tools.${tool} is { enabled: true } or { enabled: false }`, [...at, "tools", tool]);
95
+ continue;
96
+ }
97
+ if (value.enabled === false)
98
+ for (const name of tool === "*" ? known : [tool])
99
+ off.add(name);
100
+ else if (tool !== "*")
101
+ off.delete(tool);
102
+ }
103
+ }
104
+ }
105
+ if (!valid)
106
+ return undefined;
107
+ const plugins = names.map((name) => {
108
+ const tools = pluginTools(name).filter((tool) => !off.has(tool));
109
+ const within = parent?.find((item) => item.name === name);
110
+ return { name, tools: within ? tools.filter((tool) => within.tools.includes(tool)) : tools };
111
+ });
112
+ const on = (tool) => plugins.some((plugin) => plugin.tools.includes(tool));
113
+ const loop = Object.fromEntries([["plan", "update_plan"], ["connections", "request_connection"], ["ask", "ask"]].flatMap(([key, tool]) => (role === "root" && on(tool) ? [[key, true]] : [])));
114
+ const engine = {
115
+ ...(isObject(front.engine) ? front.engine : {}),
116
+ sandbox: SANDBOX_TOOL_NAMES.filter((tool) => on(tool)),
117
+ artifacts: { read: on("read_artifact"), save: computer && on("save_artifact") },
118
+ ...(role === "root" && on("triggers") ? { triggers: true } : {}),
119
+ };
120
+ return {
121
+ plugins,
122
+ ...(role === "root" && on("memory") ? { memory: { access: "read_write" } } : {}),
123
+ ...(Object.keys(loop).length > 0 ? { loop } : {}),
124
+ engine,
125
+ };
126
+ }
127
+ /** `harness.engine.plugins`: each declared plugin with its tools, its hash, and the sandbox's hosts. */
128
+ export function enginePlugins(plugins, hosts) {
129
+ return plugins.map((plugin) => ({
130
+ name: plugin.name,
131
+ tools: [...plugin.tools],
132
+ sha256: pluginOf(plugin.name).sha256,
133
+ ...(plugin.name === "nylorun-sandbox" && hosts !== undefined && hosts.length > 0 ? { hosts: [...hosts] } : {}),
134
+ }));
135
+ }
136
+ /** The names of the declared plugins' skills, which a folder's own skill may not take. */
137
+ export function pluginSkillNames(plugins) {
138
+ return pluginSkills(plugins.map((plugin) => plugin.name)).map((skill) => skill.name);
139
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://docs.nylorun.com/schemas/harness-api/v5.2.json",
3
+ "$id": "https://docs.nylorun.com/schemas/harness-api/v5.3.json",
4
4
  "title": "Nylorun Harness API 5",
5
5
  "$defs": {
6
6
  "ArtifactMeta": {
@@ -191,7 +191,8 @@
191
191
  "type": "string",
192
192
  "enum": [
193
193
  "schedule_wake",
194
- "memory"
194
+ "memory",
195
+ "triggers"
195
196
  ]
196
197
  }
197
198
  },
@@ -633,7 +634,8 @@
633
634
  "type": "string",
634
635
  "enum": [
635
636
  "schedule_wake",
636
- "memory"
637
+ "memory",
638
+ "triggers"
637
639
  ]
638
640
  }
639
641
  },
@@ -676,6 +678,10 @@
676
678
  },
677
679
  "selfWake": {
678
680
  "type": "boolean"
681
+ },
682
+ "triggers": {
683
+ "type": "boolean",
684
+ "const": true
679
685
  }
680
686
  },
681
687
  "required": [
@@ -1562,6 +1568,10 @@
1562
1568
  },
1563
1569
  "selfWake": {
1564
1570
  "type": "boolean"
1571
+ },
1572
+ "triggers": {
1573
+ "type": "boolean",
1574
+ "const": true
1565
1575
  }
1566
1576
  },
1567
1577
  "required": [
@@ -3760,6 +3770,10 @@
3760
3770
  },
3761
3771
  "selfWake": {
3762
3772
  "type": "boolean"
3773
+ },
3774
+ "triggers": {
3775
+ "type": "boolean",
3776
+ "const": true
3763
3777
  }
3764
3778
  },
3765
3779
  "required": [
@@ -4012,7 +4026,8 @@
4012
4026
  "type": "string",
4013
4027
  "enum": [
4014
4028
  "schedule_wake",
4015
- "memory"
4029
+ "memory",
4030
+ "triggers"
4016
4031
  ]
4017
4032
  }
4018
4033
  },
@@ -54,9 +54,10 @@ export function harnessApiSchemas() {
54
54
  * published `$id` names one document for good. Revision 2: `engine.diagnostic` among the claims,
55
55
  * `turn.start.memory.index` absent for a version that pins none (ADR-100), and
56
56
  * `turn.start.memory.refresh` (an optional field a v5 harness may ignore, keeping the index it
57
- * pinned).
57
+ * pinned). Revision 3: `turn.start.agent.triggers` and the `runtime` operation `triggers` (D83),
58
+ * which a v5 harness that offers no `triggers` tool never sees.
58
59
  */
59
- const SCHEMA_REVISION = 2;
60
+ const SCHEMA_REVISION = 3;
60
61
  /** The JSON Schema document of the Harness API (draft 2020-12). */
61
62
  export function harnessApiJsonSchema() {
62
63
  const $defs = {};
@@ -118,6 +118,7 @@ export declare const EffectTargetSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
118
118
  operation: z.ZodEnum<{
119
119
  memory: "memory";
120
120
  schedule_wake: "schedule_wake";
121
+ triggers: "triggers";
121
122
  }>;
122
123
  }, z.core.$strict>], "kind">;
123
124
  /**
@@ -178,6 +179,7 @@ export declare const EffectIntentSchema: z.ZodObject<{
178
179
  operation: z.ZodEnum<{
179
180
  memory: "memory";
180
181
  schedule_wake: "schedule_wake";
182
+ triggers: "triggers";
181
183
  }>;
182
184
  }, z.core.$strict>], "kind">>;
183
185
  skill: z.ZodOptional<z.ZodString>;
@@ -407,6 +409,7 @@ export declare const TurnAgentSchema: z.ZodObject<{
407
409
  workspace: z.ZodString;
408
410
  }, z.core.$strict>>;
409
411
  selfWake: z.ZodOptional<z.ZodBoolean>;
412
+ triggers: z.ZodOptional<z.ZodLiteral<true>>;
410
413
  }, z.core.$strict>;
411
414
  /**
412
415
  * The Agent's memory as a turn starts, present when the version its session runs
@@ -537,6 +540,7 @@ export declare const TurnStartSchema: z.ZodObject<{
537
540
  workspace: z.ZodString;
538
541
  }, z.core.$strict>>;
539
542
  selfWake: z.ZodOptional<z.ZodBoolean>;
543
+ triggers: z.ZodOptional<z.ZodLiteral<true>>;
540
544
  }, z.core.$strict>>;
541
545
  }, z.core.$strict>;
542
546
  /**
@@ -779,6 +783,7 @@ export declare const harnessRequests: {
779
783
  workspace: z.ZodString;
780
784
  }, z.core.$strict>>;
781
785
  selfWake: z.ZodOptional<z.ZodBoolean>;
786
+ triggers: z.ZodOptional<z.ZodLiteral<true>>;
782
787
  }, z.core.$strict>>;
783
788
  }, z.core.$strict>;
784
789
  }, z.core.$strict>;
@@ -843,6 +848,7 @@ export declare const harnessRequests: {
843
848
  operation: z.ZodEnum<{
844
849
  memory: "memory";
845
850
  schedule_wake: "schedule_wake";
851
+ triggers: "triggers";
846
852
  }>;
847
853
  }, z.core.$strict>], "kind">>;
848
854
  skill: z.ZodOptional<z.ZodString>;