@nylorun/core 0.51.0-beta → 0.53.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,207 @@
1
+ /**
2
+ * `agent-folder/3` → `agent-folder/4` (ADR-164): each subagent folder becomes one file,
3
+ * `agents/<id>.md`, and what it held moves into the manifest's library. `nylorun migrate folder
4
+ * <dir> --to 4` plans it here, applies it to a copy, and writes it only when the copy compiles to
5
+ * the same agent manifest.
6
+ *
7
+ * - `agents/<id>/AGENT.md` → `agents/<id>.md`, listing exactly what the subagent had: `tools`
8
+ * (its HTTP tools and Runtime plugin tools, or `[]`), and `skills` and `mcpServers` when the
9
+ * library holds more than it had. Its `plugins:` and `mcpServers.nylorun` go: a file inherits
10
+ * the root's.
11
+ * - Its `tools/`, `skills/` and `mcp.json` servers move to the root's; one the root already has, with
12
+ * the same bytes, is dropped. Under a root driven by a model loop, a tool that moves up joins the
13
+ * root's `disallowedTools`, so the root gains none.
14
+ * - `output.schema.json` → `agents/<id>.schema.json`; `flow.json` → `agents/<id>.flow.json`.
15
+ *
16
+ * It stops, naming why, on what it can't keep: a name the root holds with other bytes, a skill or
17
+ * server that would join a root driven by a model loop, instructions/, or any other file.
18
+ */
19
+ import { isMap, isSeq, parseDocument, YAMLSeq } from "yaml";
20
+ import { RUNTIME_SERVER } from "../plugins/index.js";
21
+ import { AGENT_FOLDER_V4 } from "./subagent-files.js";
22
+ /** Keeps long lines as written and lists as `[a, b]`. */
23
+ const YAML_OPTIONS = { lineWidth: 0, flowCollectionPadding: false };
24
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
25
+ function split(text) {
26
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
27
+ const bom = text.startsWith("") ? "" : "";
28
+ const lines = text.slice(bom.length).split(/\r?\n/);
29
+ if (lines[0]?.trimEnd() !== "---")
30
+ return undefined;
31
+ const end = lines.findIndex((line, index) => index > 0 && line.trimEnd() === "---");
32
+ if (end < 0)
33
+ return undefined;
34
+ return { front: lines.slice(1, end).join("\n"), body: lines.slice(end + 1).join(eol), eol, bom };
35
+ }
36
+ function join(parts, front) {
37
+ const lines = front.replace(/\n$/, "").split("\n");
38
+ return parts.bom + ["---", ...lines, "---"].join(parts.eol) + parts.eol + parts.body;
39
+ }
40
+ const flowList = (items) => {
41
+ const seq = new YAMLSeq();
42
+ seq.flow = true;
43
+ for (const item of items)
44
+ seq.add(item);
45
+ return seq;
46
+ };
47
+ /** Plans the migration of a format 3 folder to format 4. */
48
+ export function folderV4Plan(input) {
49
+ const sha = new Map(input.entries.map((entry) => [entry.path, entry.sha256]));
50
+ const flowRoot = sha.has("flow.json");
51
+ const rootText = input.text("AGENT.md");
52
+ const root = rootText === undefined ? undefined : split(rootText);
53
+ if (!root)
54
+ return { ok: false, reason: "AGENT.md has no frontmatter" };
55
+ const ids = [...new Set(input.entries.map((entry) => entry.path.split("/")).filter((segments) => segments[0] === "agents" && segments.length >= 3).map((segments) => segments[1]))].sort();
56
+ const writes = new Map();
57
+ const moves = [];
58
+ const deletes = [];
59
+ /** Library files after the migration, by path, with their hash. */
60
+ const library = new Map([...sha].filter(([path]) => path === "mcp.json" || /^(tools|skills|plugins)\//.test(path)));
61
+ const rootServers = (() => {
62
+ const text = input.text("mcp.json");
63
+ if (text === undefined)
64
+ return {};
65
+ const value = JSON.parse(text);
66
+ return isObject(value.mcpServers) ? { ...value.mcpServers } : {};
67
+ })();
68
+ const rootMcpBefore = JSON.stringify(rootServers);
69
+ const rootDenied = [];
70
+ for (const id of ids) {
71
+ const prefix = `agents/${id}/`;
72
+ const own = [...sha.keys()].filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length));
73
+ const where = (path) => `${prefix}${path}`;
74
+ if (sha.has(`agents/${id}.md`))
75
+ return { ok: false, reason: `agents/${id}.md already exists beside ${prefix}` };
76
+ const flow = own.includes("flow.json");
77
+ for (const path of own) {
78
+ if (path === "AGENT.md" || path === "output.schema.json" || (flow && path === "flow.json") || /^tools\/[^/]+\.json$/.test(path) || /^skills\//.test(path) || path === "mcp.json")
79
+ continue;
80
+ return {
81
+ ok: false,
82
+ reason: `${where(path)} has no place in agent-folder/4, which writes a subagent as one file: ${path.startsWith("instructions/") ? "join its instructions into the body of AGENT.md" : path.startsWith("agents/") ? "move a subagent driven by a flow's stages beside it by hand" : "move or remove it"} first`,
83
+ };
84
+ }
85
+ // HTTP tools: into the root's tools/.
86
+ for (const path of own.filter((item) => item.startsWith("tools/"))) {
87
+ const there = library.get(path);
88
+ if (there === sha.get(where(path)))
89
+ continue;
90
+ if (there !== undefined)
91
+ return { ok: false, reason: `${where(path)} and the root's ${path} differ: a library has one tool of a name. Rename one first` };
92
+ library.set(path, sha.get(where(path)));
93
+ moves.push([where(path), path]);
94
+ if (!flowRoot)
95
+ rootDenied.push(path.slice("tools/".length, -".json".length));
96
+ }
97
+ // Skills: into the root's skills/, which a root driven by a model loop would gain.
98
+ const skillNames = [...new Set(own.filter((item) => item.startsWith("skills/")).map((item) => item.split("/")[1]))];
99
+ for (const name of skillNames) {
100
+ const mine = own.filter((item) => item.startsWith(`skills/${name}/`));
101
+ const theirs = [...library.keys()].filter((path) => path.startsWith(`skills/${name}/`));
102
+ const same = theirs.length === mine.length && mine.every((path) => library.get(path) === sha.get(where(path)));
103
+ if (same)
104
+ continue;
105
+ if (theirs.length > 0)
106
+ return { ok: false, reason: `${prefix}skills/${name}/ and the root's skills/${name}/ differ: a library has one skill of a name. Rename one first` };
107
+ if (!flowRoot)
108
+ return { ok: false, reason: `${prefix}skills/${name}/ would join the root's skills, and the root agent would gain it: agent-folder/4 has no skill only a subagent sees. Keep this folder on agent-folder/3, or move the skill to the root first` };
109
+ for (const path of mine) {
110
+ library.set(path, sha.get(where(path)));
111
+ moves.push([where(path), path]);
112
+ }
113
+ }
114
+ // Servers: into the root's mcp.json, likewise.
115
+ if (own.includes("mcp.json")) {
116
+ const value = JSON.parse(input.text(where("mcp.json")) ?? "{}");
117
+ for (const [key, server] of Object.entries(isObject(value.mcpServers) ? value.mcpServers : {})) {
118
+ if (key in rootServers) {
119
+ if (JSON.stringify(rootServers[key]) !== JSON.stringify(server))
120
+ return { ok: false, reason: `${prefix}mcp.json and the root's mcp.json declare ${key} differently: a library has one server of a name. Rename one first` };
121
+ continue;
122
+ }
123
+ if (!flowRoot)
124
+ return { ok: false, reason: `${prefix}mcp.json's ${key} would join the root's servers, and the root agent would gain it: agent-folder/4 has no server only a subagent sees. Keep this folder on agent-folder/3, or move the server to the root first` };
125
+ rootServers[key] = server;
126
+ }
127
+ }
128
+ // The file.
129
+ const text = input.text(where("AGENT.md"));
130
+ const parts = text === undefined ? undefined : split(text);
131
+ if (!parts)
132
+ return { ok: false, reason: `${where("AGENT.md")} has no frontmatter` };
133
+ const doc = parseDocument(parts.front);
134
+ const data = (doc.toJS() ?? {});
135
+ doc.delete("plugins");
136
+ if (isMap(doc.get("mcpServers"))) {
137
+ doc.deleteIn(["mcpServers", RUNTIME_SERVER]);
138
+ if (doc.get("mcpServers").items.length === 0)
139
+ doc.delete("mcpServers");
140
+ }
141
+ if (flow) {
142
+ doc.set("flow", `./${id}.flow.json`);
143
+ moves.push([where("flow.json"), `agents/${id}.flow.json`]);
144
+ }
145
+ else {
146
+ const had = input.subagents.get(id);
147
+ if (!had)
148
+ return { ok: false, reason: `${prefix} did not compile as a subagent` };
149
+ doc.set("tools", flowList([...had.tools, ...had.pluginTools]));
150
+ if ([...library.keys()].some((path) => path.startsWith("skills/") || path.startsWith("plugins/"))) {
151
+ doc.delete("skills");
152
+ doc.set("skills", flowList(had.skills));
153
+ }
154
+ else if (isMap(doc.get("skills")) || isSeq(doc.get("skills")))
155
+ doc.delete("skills");
156
+ const anyServers = Object.keys(rootServers).length > 0 || [...library.keys()].some((path) => path.startsWith("plugins/"));
157
+ if (anyServers) {
158
+ const settings = isObject(data.mcpServers) ? data.mcpServers : {};
159
+ const kept = {};
160
+ for (const key of had.servers)
161
+ kept[key] = isObject(settings[key]) ? settings[key] : {};
162
+ doc.delete("mcpServers");
163
+ doc.set("mcpServers", doc.createNode(kept));
164
+ }
165
+ }
166
+ if (data.outputSchema !== undefined) {
167
+ const value = String(data.outputSchema);
168
+ if (value === "./output.schema.json" || value === "output.schema.json") {
169
+ doc.set("outputSchema", `./${id}.schema.json`);
170
+ moves.push([where("output.schema.json"), `agents/${id}.schema.json`]);
171
+ }
172
+ else if (!value.startsWith("/"))
173
+ return { ok: false, reason: `${where("AGENT.md")}'s outputSchema ${value} is a path inside the folder: write it from the root (/schemas/...) first` };
174
+ }
175
+ else if (own.includes("output.schema.json"))
176
+ return { ok: false, reason: `${where("output.schema.json")} is named by nothing: remove it first` };
177
+ writes.set(`agents/${id}.md`, join(parts, doc.toString(YAML_OPTIONS)));
178
+ for (const path of own)
179
+ deletes.push(where(path));
180
+ }
181
+ // The root: format 4, and the tools that moved up kept out of its own loop.
182
+ // Edited line by line, so the rest of the root's frontmatter stays as written.
183
+ const lines = root.front.split("\n");
184
+ const formatAt = lines.findIndex((line) => /^format\s*:/.test(line));
185
+ if (formatAt >= 0)
186
+ lines[formatAt] = `format: ${AGENT_FOLDER_V4}`;
187
+ else
188
+ lines.unshift(`format: ${AGENT_FOLDER_V4}`);
189
+ let front = lines.join("\n");
190
+ if (rootDenied.length > 0) {
191
+ const doc = parseDocument(front);
192
+ const existing = doc.get("disallowedTools");
193
+ if (existing === undefined)
194
+ front = `${front.replace(/\n$/, "")}\ndisallowedTools: [${[...new Set(rootDenied)].join(", ")}]`;
195
+ else {
196
+ doc.set("disallowedTools", flowList([...new Set([...(isSeq(existing) ? existing.toJSON() : []), ...rootDenied])]));
197
+ front = doc.toString(YAML_OPTIONS);
198
+ }
199
+ }
200
+ writes.set("AGENT.md", join(root, front));
201
+ if (JSON.stringify(rootServers) !== rootMcpBefore) {
202
+ const text = input.text("mcp.json");
203
+ const value = text === undefined ? {} : JSON.parse(text);
204
+ writes.set("mcp.json", `${JSON.stringify({ ...value, mcpServers: rootServers }, null, 2)}\n`);
205
+ }
206
+ return { ok: true, writes, moves, deletes };
207
+ }
@@ -20,7 +20,7 @@
20
20
  * and `./x` one from its own. A slot it needs is derived in the uploaded folder's runtime
21
21
  * section.
22
22
  */
23
- import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
23
+ import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN, delegateInputIssue } from "../definition/delegate.js";
24
24
  import { loopManifestOf } from "../definition/sections.js";
25
25
  import { TOOL_SECRET_NAME_PATTERN } from "../contracts.js";
26
26
  import { addInner, cloneJson, foldersUnder, isObject, jsonPosition, } from "./context.js";
@@ -225,12 +225,12 @@ function nestedChecks(ctx) {
225
225
  /** An agent: its `agents/` are tools, and its plugins are listed. */
226
226
  function composeAgent(ctx) {
227
227
  if (ctx.front.inputSchema !== undefined)
228
- ctx.report("error", "input_schema_refused", "inputSchema is a flow's: an agent's input is the message, and a subagent's is { task }. A folder is a flow when it has a flow.json", AGENT_FILE, ["inputSchema"], { key: true });
228
+ ctx.report("error", "input_schema_refused", "inputSchema is for a manifest driven by a flow: one driven by a model loop takes the message, and a subagent used as a tool takes { task }. flow.json makes a manifest driven by a flow", AGENT_FILE, ["inputSchema"], { key: true });
229
229
  const harness = ctx.harness;
230
230
  const folders = foldersUnder("agents", ctx.entries.keys());
231
231
  if (folders.size > 0 && ctx.scope?.role === "subagent")
232
232
  for (const [id, inner] of folders)
233
- ctx.report("error", "subagent_depth", `A subagent has no subagents: agents used as tools nest one level deep. Move agents/${id}/ to the agent that uses it`, folderFile(id, inner));
233
+ ctx.report("error", "subagent_depth", `A subagent has no subagents: subagents used as tools nest one level deep. Move agents/${id}/ to the manifest that uses it`, folderFile(id, inner));
234
234
  else if (folders.size > 0) {
235
235
  const tools = Array.isArray(harness.tools) ? harness.tools : [];
236
236
  const httpTools = new Set(tools.map((tool) => tool.name));
@@ -244,6 +244,11 @@ function composeAgent(ctx) {
244
244
  const manifest = compileInner(ctx, `agents/${id}/`, "subagent");
245
245
  if (!manifest)
246
246
  continue;
247
+ const input = delegateInputIssue(id, manifest.harness.inputSchema);
248
+ if (input) {
249
+ ctx.report("error", "delegation_input", input, `agents/${id}/${AGENT_FILE}`, ["inputSchema"], { key: true });
250
+ continue;
251
+ }
247
252
  ctx.origins.push([["harness", "tools", tools.length], { file: `agents/${id}/${AGENT_FILE}`, path: [] }]);
248
253
  // As the TypeScript builder emits an agent used as a tool (`delegateTool`).
249
254
  tools.push({
@@ -303,25 +308,30 @@ function composeFlow(ctx) {
303
308
  const lines = ctx.agent.body.split("\n");
304
309
  const first = lines.findIndex((line) => line.trim() !== "");
305
310
  if (first >= 0)
306
- ctx.report("error", "flow_body", "A flow's AGENT.md has no body: a flow has no instructions, and each of its agents has its own", AGENT_FILE, undefined, {
311
+ ctx.report("error", "flow_body", "A manifest driven by a flow has no instructions, so its AGENT.md has no body: each subagent under agents/ has its own", AGENT_FILE, undefined, {
307
312
  at: { line: ctx.agent.bodyLine + first, column: 1 },
308
313
  });
309
314
  }
310
315
  const noted = new Set();
316
+ // agent-folder/4 (ADR-164): a flow root's mcp.json, skills/, plugins/ and tools are the library
317
+ // its stages draw on, not its own.
318
+ const library = !ctx.scope && ctx.engineFacts().v4 !== undefined;
311
319
  for (const [path, kind] of ctx.kinds) {
320
+ if (library)
321
+ break;
312
322
  const top = path.split("/").slice(0, 2).join("/");
313
323
  if (kind === "instructions")
314
- refuse("A flow has no instructions: move this to the agent under agents/ that needs it", path);
324
+ refuse("A manifest driven by a flow has no instructions: move this to the subagent under agents/ that needs it", path);
315
325
  else if (kind === "mcp")
316
- refuse("A flow has no MCP servers of its own: give mcp.json to the agents under agents/ that call them", path);
326
+ refuse("A manifest driven by a flow has no MCP servers of its own: give mcp.json to the subagents under agents/ that call them", path);
317
327
  else if ((kind === "skill" || kind === "plugin") && !noted.has(top)) {
318
328
  noted.add(top);
319
- refuse(kind === "skill" ? `A flow has no skills of its own: move ${top}/ to the agent that uses it` : `A flow takes no plugins: vendor ${top}/ in the agent that uses it`, `${top}/`);
329
+ refuse(kind === "skill" ? `A manifest driven by a flow has no skills of its own: move ${top}/ to the subagent that uses it` : `A manifest driven by a flow takes no plugins: vendor ${top}/ in the subagent that uses it`, `${top}/`);
320
330
  }
321
331
  }
322
332
  for (const key of ["mcpServers", "skills", "memory", "model"])
323
333
  if (front[key] !== undefined)
324
- refuse(`${key} is an agent's: set it in the AGENT.md of the agent under agents/ that needs it`, AGENT_FILE, [key]);
334
+ refuse(`${key} belongs to a model loop: set it in the AGENT.md of the subagent under agents/ that needs it`, AGENT_FILE, [key]);
325
335
  const inputSchema = front.inputSchema === undefined ? undefined : ctx.schemaAt(AGENT_FILE, ["inputSchema"], front.inputSchema);
326
336
  // The agents it names: the flow root's.
327
337
  const own = foldersUnder("agents", ctx.entries.keys());
@@ -352,7 +362,7 @@ function composeFlow(ctx) {
352
362
  tools.set(String(tool.name), tool);
353
363
  const translated = translateFlow(tree, { agentIds: namespace.ids, agent: (id) => namespace.resolve(id), used: namespace.used, tools }, (code, message, file, path, options) => ctx.report("error", code, message, file, path, options), ctx.suggest);
354
364
  for (const name of tools.keys())
355
- if (!translated.toolsUsed.has(name))
365
+ if (!library && !translated.toolsUsed.has(name))
356
366
  ctx.report("error", "tool_unused", `No node of flow.json names ${name}: a flow holds only the tools its nodes name`, `tools/${name}.json`);
357
367
  if (isRoot) {
358
368
  const unused = namespace.ids.filter((id) => !namespace.used.has(id));
@@ -55,11 +55,12 @@ function fromZod(schema, defs, description) {
55
55
  * names one document for good): `AGENT.md` took `model` (Host feature `agent-model`), published
56
56
  * as `agent-md.1.json`, then `format: agent-folder/2` and `engine` (ADR-100), as `agent-md.2.json`,
57
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`, then `roles` (ADR-154), as `agent-md.5.json`;
58
+ * `plugins` (ADR-106), as `agent-md.4.json`, then `roles` (ADR-154), as `agent-md.5.json`, then
59
+ * `format: agent-folder/4` and a subagent file's keys (ADR-164), as `agent-md.6.json`;
59
60
  * `runtime.json` took a secret slot's `toolPrefix` (Host feature `secret-routing`), published as
60
61
  * `runtime.1.json`, then `limits.triggers` (D83), as `runtime.2.json`.
61
62
  */
62
- const REVISIONS = { "agent-md": 5, runtime: 2 };
63
+ const REVISIONS = { "agent-md": 6, runtime: 2 };
63
64
  /** One document: its `$id` from its kind, then the body, then the `$defs` its parts named. */
64
65
  function document(kind, title, description, body, defs) {
65
66
  const revision = REVISIONS[kind];
@@ -99,8 +100,8 @@ function agentMd() {
99
100
  name: { type: "string", pattern: AGENT_MANIFEST_NAME_PATTERN.source, description: "The agent manifest's name, the folder's when it is saved under one" },
100
101
  description: { type: "string", minLength: 1, description: "What the agent does, in a sentence" },
101
102
  format: {
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",
103
+ enum: [1, 2, 3, 4, "agent-folder/1", "agent-folder/2", "agent-folder/3", "agent-folder/4"],
104
+ 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; agent-folder/3 (or 3), which declares the Runtime's features as plugins; or agent-folder/4 (or 4), agent-folder/3 with each subagent one file, agents/<id>.md, drawing on the manifest's library",
104
105
  },
105
106
  harness: fromZod(HarnessIdSchema, defs, "The harness that runs the loop: nylorun (ours, the default) or a custom harness's id"),
106
107
  inputSchema: ref("JsonSchemaOrPath", "A flow's input (a folder with flow.json); an agent's input is the message"),
@@ -168,7 +169,26 @@ function agentMd() {
168
169
  },
169
170
  metadata: { type: "object", description: "The manifest's metadata, as it is" },
170
171
  };
171
- return document("agent-md", "Nylorun agent folder: AGENT.md frontmatter", "The frontmatter of an agent folder's AGENT.md; the body below it is the instructions", { type: "object", properties, required: ["name", "description"], additionalProperties: false }, defs);
172
+ // agent-folder/4 (ADR-164): the narrowing keys a subagent file (agents/<id>.md) and the root take.
173
+ const toolNames = {
174
+ anyOf: [{ type: "array", items: { type: "string" } }, { type: "string" }],
175
+ };
176
+ const fileProperties = {
177
+ tools: { ...toolNames, description: "agent-folder/4: the only HTTP tools and Runtime plugin tools of the manifest's library this agent gets, by name ([read, grep, glob]); left out, a subagent file gets every one a subagent can use" },
178
+ disallowedTools: { ...toolNames, description: "agent-folder/4: library tools this agent does not get, by name" },
179
+ flow: { type: "string", description: "agent-folder/4, a subagent file: the flow file that drives it (./research.flow.json); its body is then empty" },
180
+ readonly: { type: "boolean", description: "agent-folder/4, a subagent file (Cursor's key): true reads as tools: [read, grep, glob] when tools is left out" },
181
+ };
182
+ return document("agent-md", "Nylorun agent folder: AGENT.md frontmatter", "The frontmatter of an agent folder's AGENT.md, or of a subagent file (agents/<id>.md, agent-folder/4); the body below it is the instructions", {
183
+ type: "object",
184
+ properties: {
185
+ ...properties,
186
+ skills: { anyOf: [properties.skills, { type: "array", items: { type: "string" }, description: "agent-folder/4, a subagent file: the only skills of the manifest's library it gets, by name" }] },
187
+ ...fileProperties,
188
+ },
189
+ required: ["name", "description"],
190
+ additionalProperties: false,
191
+ }, defs);
172
192
  }
173
193
  /** A trigger has exactly one of schedule, at and webhook (`TriggerSchema` refines it), and timezone goes with schedule. */
174
194
  const ONE_TRIGGER_KIND = [
@@ -0,0 +1,106 @@
1
+ /**
2
+ * `agent-folder/4` (ADR-164, D97): a subagent is one file, `agents/<id>.md`, and the manifest's
3
+ * `tools/`, `skills/`, `mcp.json`, `plugins/` and Runtime plugins are its **library**, which every
4
+ * model loop in it draws on: the root's own, and each subagent's, which inherits it and narrows it
5
+ * with `tools`, `disallowedTools`, `skills` and `mcpServers`.
6
+ *
7
+ * ```markdown
8
+ * ---
9
+ * name: history
10
+ * description: Searches the person's past work.
11
+ * tools: [search_work, get_task]
12
+ * ---
13
+ * You find earlier work for a bot…
14
+ * ```
15
+ *
16
+ * The compiler keeps every check it has by **expanding** format 4 into the layout format 3 already
17
+ * compiles: each `agents/<id>.md` becomes a virtual `agents/<id>/` holding the file's bytes as its
18
+ * `AGENT.md` and a copy of the library (the same bytes and hashes), or, for a file with `flow:`,
19
+ * its flow file and the library tools the flow names. The subagent's compile then narrows what it
20
+ * inherited (`narrowFront`, `narrowParts`), and every diagnostic is moved back to the file people
21
+ * wrote (`compileFormat4`). Pure, like the compiler.
22
+ */
23
+ import type { CompileAgentFolderInput, CompiledAgentFolder } from "./compile.js";
24
+ import { PLUGIN_NAMES, pluginTools, type PluginName } from "../plugins/index.js";
25
+ import type { ReportOptions } from "./context.js";
26
+ /** The format name a v4 folder writes. */
27
+ export declare const AGENT_FOLDER_V4 = "agent-folder/4";
28
+ /** Whether `value` names the v4 format: `agent-folder/4` or `4`. */
29
+ export declare function isFolderV4(value: unknown): boolean;
30
+ /** The keys a subagent file adds to `AGENT.md`'s, and the root's in format 4. */
31
+ export declare const SUBAGENT_FILE_KEYS: readonly ["tools", "disallowedTools", "flow", "readonly"];
32
+ /** The root's own narrowing keys in format 4. */
33
+ export declare const ROOT_V4_KEYS: readonly ["tools", "disallowedTools"];
34
+ /**
35
+ * Keys Claude Code and Cursor write that mean nothing here: noted and ignored, so their files drop
36
+ * in. `memory` is one only as a string (Claude Code's `user`, `project` or `local`).
37
+ */
38
+ export declare const HOST_KEYS: readonly ["model", "color", "permissionMode", "hooks", "maxTurns", "background", "isolation", "effort", "initialPrompt", "omitClaudeMd", "autoCompactWindow", "experimental", "is_background"];
39
+ /** Claude Code's tool names that are ours under another spelling. */
40
+ export declare const CLAUDE_TOOL_ALIASES: Readonly<Record<string, string>>;
41
+ /** The Runtime plugins only the root agent uses: a subagent never inherits them, and names their tools only with an error. */
42
+ export declare const ROOT_ONLY_PLUGINS: readonly PluginName[];
43
+ /** Whether the uploaded folder's `AGENT.md` names format 4, read quietly. */
44
+ export declare function folderIsV4(input: CompileAgentFolderInput): boolean;
45
+ /** A subagent file's id from its path, or undefined: `agents/<id>.md`. */
46
+ export declare function subagentFileId(path: string): string | undefined;
47
+ /** The path `flow:` names, from the file at `agents/<id>.md`: `./x` and `x` from `agents/`, `/x` from the root. */
48
+ export declare function flowPathOf(value: unknown): string | undefined;
49
+ /**
50
+ * Compiles a format 4 folder: expands its subagent files, compiles the result as `compile` does a
51
+ * format 3 folder, and moves each diagnostic back to the file people wrote.
52
+ */
53
+ export declare function compileFormat4(input: CompileAgentFolderInput, compile: (input: CompileAgentFolderInput) => CompiledAgentFolder): CompiledAgentFolder;
54
+ /** What a subagent file, or a format 4 root, keeps of what it inherits. Undefined: everything. */
55
+ export interface Narrowing {
56
+ /** The HTTP tools it keeps, by name; undefined keeps every one. */
57
+ readonly http?: ReadonlySet<string>;
58
+ /** HTTP tools it drops. */
59
+ readonly httpDenied: ReadonlySet<string>;
60
+ /** The skills it keeps; undefined keeps every one it may have. */
61
+ readonly skills?: readonly {
62
+ readonly name: string;
63
+ readonly index: number;
64
+ }[];
65
+ /** The servers it keeps: `mcpServers`' keys; undefined keeps every one it may have. */
66
+ readonly servers?: readonly string[];
67
+ /** A subagent file driven by a flow (`flow:`). */
68
+ readonly flow: boolean;
69
+ }
70
+ /** What `narrowFront` needs to know. */
71
+ export interface NarrowOptions {
72
+ readonly role: "root" | "subagent";
73
+ /** The HTTP tools this folder (or the expansion's copy of the library) holds. */
74
+ readonly httpTools: readonly string[];
75
+ /** The Runtime plugins to inherit from: the parent's (a subagent's), or the root's own. */
76
+ readonly plugins: readonly {
77
+ readonly name: PluginName;
78
+ readonly tools: readonly string[];
79
+ }[];
80
+ readonly error: (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
81
+ readonly note: (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
82
+ }
83
+ /**
84
+ * Reads and strips the format 4 keys of `front` (a subagent file's, or a v4 root's), noting other
85
+ * hosts' keys, and writes the Runtime `plugins:` and `mcpServers.nylorun` its tools leave on, so the
86
+ * format 3 compiler that follows sees a folder it knows. Returns what it keeps of the rest.
87
+ */
88
+ export declare function narrowFront(front: Record<string, unknown>, options: NarrowOptions): Narrowing;
89
+ /** What a subagent file may not inherit unnamed: the root's skills with secrets and servers with a credential. */
90
+ export interface RootSecrets {
91
+ readonly skills: readonly string[];
92
+ readonly servers: readonly string[];
93
+ }
94
+ /** The root's skills with secrets and plugin servers it gives a credential, read from its frontmatter. */
95
+ export declare function rootSecretsOf(front: Record<string, unknown>): RootSecrets;
96
+ /**
97
+ * Keeps, of the HTTP tools, skills and servers a subagent file inherited (or a v4 root holds),
98
+ * what its narrowing allows. A subagent also drops the root's skills with secrets and servers with
99
+ * a credential unless it names them, which then fail the checks that follow.
100
+ */
101
+ export declare function narrowParts(harness: Record<string, unknown>, narrowing: Narrowing, options: {
102
+ readonly role: "root" | "subagent";
103
+ readonly secrets: RootSecrets;
104
+ readonly error: (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
105
+ }): void;
106
+ export { PLUGIN_NAMES, pluginTools };