@nylorun/core 0.52.0-beta → 0.54.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 (83) hide show
  1. package/CHANGELOG.md +119 -98
  2. package/dist/compatibility.d.ts +39 -12
  3. package/dist/compatibility.js +37 -10
  4. package/dist/contracts.d.ts +126 -44
  5. package/dist/contracts.js +127 -69
  6. package/dist/define.d.ts +2 -2
  7. package/dist/define.js +1 -1
  8. package/dist/definition/bound.d.ts +3 -1
  9. package/dist/definition/declaration.js +1 -0
  10. package/dist/definition/delegate.d.ts +7 -4
  11. package/dist/definition/delegate.js +4 -3
  12. package/dist/definition/from.js +3 -1
  13. package/dist/definition/manifest.js +7 -1
  14. package/dist/definition/sections.d.ts +9 -8
  15. package/dist/definition/sections.js +13 -5
  16. package/dist/definition/variant.d.ts +2 -2
  17. package/dist/definition/variant.js +4 -4
  18. package/dist/definition/workflow/runnable.d.ts +1 -1
  19. package/dist/definition/workflow/runnable.js +1 -1
  20. package/dist/definition/workflow/verdict.d.ts +1 -1
  21. package/dist/definition/workflow/verdict.js +1 -1
  22. package/dist/engine/blocks.d.ts +2 -2
  23. package/dist/engine/blocks.js +3 -3
  24. package/dist/engine/explain.d.ts +1 -1
  25. package/dist/engine/explain.js +3 -3
  26. package/dist/engine/features.d.ts +1 -1
  27. package/dist/engine/features.js +1 -1
  28. package/dist/engine/index.d.ts +1 -1
  29. package/dist/engine/index.js +1 -1
  30. package/dist/engine/mcp.d.ts +4 -4
  31. package/dist/engine/mcp.js +4 -4
  32. package/dist/engine/names.d.ts +1 -1
  33. package/dist/engine/names.js +1 -1
  34. package/dist/engine/preview.d.ts +2 -2
  35. package/dist/engine/preview.js +1 -1
  36. package/dist/engine/projection.d.ts +3 -3
  37. package/dist/engine/projection.js +8 -8
  38. package/dist/engine/tools.d.ts +8 -8
  39. package/dist/engine/tools.js +7 -7
  40. package/dist/errors.d.ts +1 -1
  41. package/dist/folder/compile.d.ts +2 -2
  42. package/dist/folder/compile.js +111 -15
  43. package/dist/folder/decompile.js +7 -7
  44. package/dist/folder/engine.d.ts +8 -2
  45. package/dist/folder/engine.js +3 -3
  46. package/dist/folder/fix.js +1 -1
  47. package/dist/folder/flow.d.ts +1 -1
  48. package/dist/folder/flow.js +1 -1
  49. package/dist/folder/index.d.ts +4 -2
  50. package/dist/folder/index.js +4 -2
  51. package/dist/folder/migrate-v3.js +2 -2
  52. package/dist/folder/migrate-v4.d.ts +33 -0
  53. package/dist/folder/migrate-v4.js +207 -0
  54. package/dist/folder/nested.js +14 -6
  55. package/dist/folder/plugins.d.ts +13 -1
  56. package/dist/folder/plugins.js +49 -12
  57. package/dist/folder/schemas.js +29 -9
  58. package/dist/folder/subagent-files.d.ts +110 -0
  59. package/dist/folder/subagent-files.js +514 -0
  60. package/dist/folder/v3.d.ts +2 -2
  61. package/dist/folder/v3.js +2 -2
  62. package/dist/harness-api/artifacts.d.ts +1 -1
  63. package/dist/harness-api/json-schema.js +6 -6
  64. package/dist/harness-api/messages.d.ts +1 -1
  65. package/dist/harness-api/messages.js +1 -1
  66. package/dist/harness-api/schema.d.ts +2 -2
  67. package/dist/harness-api/schema.js +8 -8
  68. package/dist/manifest-schemas.js +9 -6
  69. package/dist/plugins/index.js +1 -1
  70. package/dist/schemas/agent-folder/agent-md.schema.json +67 -18
  71. package/dist/schemas/agent-manifest.schema.json +65 -2
  72. package/dist/schemas/harness-manifest.schema.json +55 -2
  73. package/dist/types/manifest.d.ts +32 -7
  74. package/dist/types/model.d.ts +3 -3
  75. package/dist/types/observe.d.ts +1 -1
  76. package/dist/types/part.d.ts +5 -3
  77. package/dist/types/transcript.d.ts +1 -1
  78. package/dist/utils/definition-files.d.ts +23 -0
  79. package/dist/utils/definition-files.js +50 -4
  80. package/dist/utils/memory.js +1 -1
  81. package/dist/utils/runtime-limits.d.ts +2 -2
  82. package/dist/utils/runtime-limits.js +3 -3
  83. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  /**
2
- * `@nylorun/core/folder`: agent folders (track T6, D79). An agent written as a folder of
2
+ * `@nylorun/core/folder`: agent folders. An agent written as a folder of
3
3
  * Markdown and JSON, compiled by `compileAgentFolder` into the agent manifest v8 the Runtime
4
4
  * runs. The Runtime compiles every folder it is sent with this code, and the CLI checks one
5
5
  * offline with the same code. `folderOfManifest` writes the folder of a saved manifest,
6
6
  * `agentFolderJsonSchemas` gives the JSON Schema of each kind of file in a folder, for editors, and
7
- * `applyFolderFixes` makes the fix-its its diagnostics carry (track T7).
7
+ * `applyFolderFixes` makes the fix-its its diagnostics carry.
8
8
  */
9
9
  export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderTextPaths, type AgentFolderDiagnostic, type AgentFolderEntry, type AgentFolderFix, type AgentFolderLimits, type CompileAgentFolderInput, type CompiledAgentFolder, } from "./compile.js";
10
10
  export { folderOfManifest, type FolderOfManifest, type FolderOfManifestOptions } from "./decompile.js";
@@ -12,3 +12,5 @@ export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas, type AgentFolderSche
12
12
  export { applyFolderFixes, type AppliedFolderFixes } from "./fix.js";
13
13
  export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
14
14
  export { folderV3Edit, type FolderV3Edit } from "./migrate-v3.js";
15
+ export { AGENT_FOLDER_V4, isFolderV4 } from "./subagent-files.js";
16
+ export { folderV4Plan, type FolderV4Input, type FolderV4Plan } from "./migrate-v4.js";
@@ -1,10 +1,10 @@
1
1
  /**
2
- * `@nylorun/core/folder`: agent folders (track T6, D79). An agent written as a folder of
2
+ * `@nylorun/core/folder`: agent folders. An agent written as a folder of
3
3
  * Markdown and JSON, compiled by `compileAgentFolder` into the agent manifest v8 the Runtime
4
4
  * runs. The Runtime compiles every folder it is sent with this code, and the CLI checks one
5
5
  * offline with the same code. `folderOfManifest` writes the folder of a saved manifest,
6
6
  * `agentFolderJsonSchemas` gives the JSON Schema of each kind of file in a folder, for editors, and
7
- * `applyFolderFixes` makes the fix-its its diagnostics carry (track T7).
7
+ * `applyFolderFixes` makes the fix-its its diagnostics carry.
8
8
  */
9
9
  export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderTextPaths, } from "./compile.js";
10
10
  export { folderOfManifest } from "./decompile.js";
@@ -12,3 +12,5 @@ export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas } from "./schemas.js"
12
12
  export { applyFolderFixes } from "./fix.js";
13
13
  export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
14
14
  export { folderV3Edit } from "./migrate-v3.js";
15
+ export { AGENT_FOLDER_V4, isFolderV4 } from "./subagent-files.js";
16
+ export { folderV4Plan } from "./migrate-v4.js";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `agent-folder/2` → `agent-folder/3` (ADR-106): the plugins that keep what an agent gets, written
2
+ * `agent-folder/2` → `agent-folder/3`: the plugins that keep what an agent gets, written
3
3
  * in place of the declarations they stand for. `nylorun migrate folder <dir> --to 3` runs it on a
4
4
  * folder's `AGENT.md` and each subagent's, and on `runtime.json`, then checks that every agent
5
5
  * keeps the same tools and features.
@@ -75,7 +75,7 @@ export function folderV3Edit(input) {
75
75
  }
76
76
  // The frontmatter, edited in place: comments and the other keys stay as they are.
77
77
  doc.delete("memory");
78
- // loop keeps the harness's own settings (compaction, ADR-157); its plan, connections and ask are plugins now.
78
+ // loop keeps the harness's own settings (compaction); its plan, connections and ask are plugins now.
79
79
  const loopNode = doc.get("loop", true);
80
80
  if (isMap(loopNode)) {
81
81
  for (const key of ["plan", "connections", "ask"])
@@ -0,0 +1,33 @@
1
+ /** A folder's file as the migration reads it: its path and hash, and its text when it is one the migration edits. */
2
+ export interface FolderV4Input {
3
+ readonly entries: readonly {
4
+ readonly path: string;
5
+ readonly sha256: string;
6
+ }[];
7
+ /** The text of a file, for `AGENT.md` files and `mcp.json` files. */
8
+ readonly text: (path: string) => string | undefined;
9
+ /**
10
+ * What each subagent has, by id, from the folder compiled as it is: its HTTP tool names, its
11
+ * Runtime plugin tools, its skills and its servers.
12
+ */
13
+ readonly subagents: ReadonlyMap<string, {
14
+ readonly tools: readonly string[];
15
+ readonly pluginTools: readonly string[];
16
+ readonly skills: readonly string[];
17
+ readonly servers: readonly string[];
18
+ }>;
19
+ }
20
+ export type FolderV4Plan = {
21
+ readonly ok: true;
22
+ /** Files to write, by path, with their text. */
23
+ readonly writes: ReadonlyMap<string, string>;
24
+ /** Files to copy, from → to. */
25
+ readonly moves: readonly (readonly [string, string])[];
26
+ /** Files to delete once the rest is written: every file of every subagent folder. */
27
+ readonly deletes: readonly string[];
28
+ } | {
29
+ readonly ok: false;
30
+ readonly reason: string;
31
+ };
32
+ /** Plans the migration of a format 3 folder to format 4. */
33
+ export declare function folderV4Plan(input: FolderV4Input): FolderV4Plan;
@@ -0,0 +1,207 @@
1
+ /**
2
+ * `agent-folder/3` → `agent-folder/4`: 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
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The folders inside an agent folder (track T7, D80; design §3.3, §3.8), compiled by the same
2
+ * The folders inside an agent folder, compiled by the same
3
3
  * compiler, one level in:
4
4
  *
5
5
  * - **Subagents.** `agents/<id>/` of an agent (no `flow.json` beside it) is an agent folder
@@ -56,7 +56,7 @@ export function scopedSchema(scope, value, fail) {
56
56
  export function folderParts(ctx) {
57
57
  const isFlow = [...ctx.kinds.values()].includes("flow");
58
58
  let plugins;
59
- const folded = () => (plugins ??= isFlow ? { servers: new Map(), skills: new Map() } : foldPlugins(ctx));
59
+ const folded = () => (plugins ??= isFlow ? { servers: new Map(), skills: new Map(), mounted: new Map() } : foldPlugins(ctx));
60
60
  return {
61
61
  /** Adds the plugins' MCP servers, before `AGENT.md` says how the agent uses them. */
62
62
  mergeServers(servers) {
@@ -116,7 +116,7 @@ export function folderParts(ctx) {
116
116
  nestedChecks(ctx);
117
117
  if (isFlow)
118
118
  return composeFlow(ctx);
119
- composeAgent(ctx);
119
+ composeAgent(ctx, folded().mounted);
120
120
  return true;
121
121
  },
122
122
  };
@@ -198,7 +198,7 @@ function nestedChecks(ctx) {
198
198
  for (const [key, message] of Object.entries(keys))
199
199
  if (ctx.front[key] !== undefined)
200
200
  refuse(message, AGENT_FILE, [key]);
201
- // Triggers are the root agent's (D83): a subagent of a parent without them fails engine_subset.
201
+ // Triggers are the root agent's: a subagent of a parent without them fails engine_subset.
202
202
  if (isObject(ctx.front.engine) &&
203
203
  ctx.front.engine.triggers === true &&
204
204
  (ctx.scope.role === "stage" || ctx.scope.engineFacts?.engine?.triggers === true))
@@ -223,7 +223,7 @@ function nestedChecks(ctx) {
223
223
  ctx.report("error", "credential_unsupported", `Only the root agent's skills get secrets: ${what}'s skill ${key} gets none`, AGENT_FILE, ["skills", key, "secrets"]);
224
224
  }
225
225
  /** An agent: its `agents/` are tools, and its plugins are listed. */
226
- function composeAgent(ctx) {
226
+ function composeAgent(ctx, mounted) {
227
227
  if (ctx.front.inputSchema !== undefined)
228
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;
@@ -268,6 +268,9 @@ function composeAgent(ctx) {
268
268
  if (label && !labels.has(label.name))
269
269
  labels.set(label.name, { ...label });
270
270
  }
271
+ // A plugin mounted whole carries its files, whether or not its parts carry its label.
272
+ for (const plugin of mounted.values())
273
+ labels.set(plugin.name, plugin);
271
274
  if (labels.size > 0)
272
275
  harness.plugins = [...labels.values()].sort((a, b) => a.name.localeCompare(b.name));
273
276
  }
@@ -313,7 +316,12 @@ function composeFlow(ctx) {
313
316
  });
314
317
  }
315
318
  const noted = new Set();
319
+ // agent-folder/4: a flow root's mcp.json, skills/, plugins/ and tools are the library
320
+ // its stages draw on, not its own.
321
+ const library = !ctx.scope && ctx.engineFacts().v4 !== undefined;
316
322
  for (const [path, kind] of ctx.kinds) {
323
+ if (library)
324
+ break;
317
325
  const top = path.split("/").slice(0, 2).join("/");
318
326
  if (kind === "instructions")
319
327
  refuse("A manifest driven by a flow has no instructions: move this to the subagent under agents/ that needs it", path);
@@ -357,7 +365,7 @@ function composeFlow(ctx) {
357
365
  tools.set(String(tool.name), tool);
358
366
  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);
359
367
  for (const name of tools.keys())
360
- if (!translated.toolsUsed.has(name))
368
+ if (!library && !translated.toolsUsed.has(name))
361
369
  ctx.report("error", "tool_unused", `No node of flow.json names ${name}: a flow holds only the tools its nodes name`, `tools/${name}.json`);
362
370
  if (isRoot) {
363
371
  const unused = namespace.ids.filter((id) => !namespace.used.has(id));
@@ -6,7 +6,7 @@ export interface PluginLabel {
6
6
  readonly name: string;
7
7
  readonly version?: string;
8
8
  }
9
- /** A plugin's skills and servers, labelled, with the file each came from. */
9
+ /** A plugin's skills and servers, labelled, with the file each came from, and the plugins mounted whole. */
10
10
  export interface FoldedPlugins {
11
11
  readonly servers: Map<string, {
12
12
  readonly server: Record<string, unknown>;
@@ -16,8 +16,20 @@ export interface FoldedPlugins {
16
16
  readonly skill: Record<string, unknown>;
17
17
  readonly file: string;
18
18
  }>;
19
+ /** By name: each plugin holding files beyond the parts the manifest carries, with all its files. */
20
+ readonly mounted: Map<string, {
21
+ readonly name: string;
22
+ readonly version?: string;
23
+ readonly files: Record<string, string>;
24
+ }>;
19
25
  }
20
26
  /** The files of `plugins/<name>/` the compiler reads, relative to the plugin's folder. */
21
27
  export declare function pluginTextPaths(paths: readonly string[]): string[];
28
+ /** A plugin's subagent file, relative to the plugin's folder (`agents/<file>.md`): its file name, or undefined. */
29
+ export declare function pluginSubagentFile(path: string): string | undefined;
30
+ /** A JSON file beside a plugin's subagent files, such as the flow file a subagent's `flow:` names. */
31
+ export declare function pluginSubagentFlow(path: string): boolean;
32
+ /** A plugin's label as its `plugin.json` gives it, read quietly: undefined when it names none. */
33
+ export declare function pluginLabelOf(manifest: unknown): PluginLabel | undefined;
22
34
  /** Folds every plugin under `plugins/`. */
23
35
  export declare function foldPlugins(ctx: FolderContext): FoldedPlugins;
@@ -8,7 +8,7 @@ const AUTHOR_KEYS = ["name", "email", "url"];
8
8
  const READ = new Set([PLUGIN_FILE, "mcp.json", ".mcp.json", "skills"]);
9
9
  /** Parts of plugins for other tools, which Nylorun does not run. */
10
10
  const NOT_RUN = {
11
- agents: "Claude Code's subagents (agents/*.md) are not run by Nylorun: write an agent as agents/<id>/ in the agent folder",
11
+ agents: "A plugin's subagents (agents/*.md) run in agent-folder/4: nylorun migrate folder <dir> --to 4",
12
12
  hooks: "Hooks are not run by Nylorun",
13
13
  commands: "Slash commands are not run by Nylorun",
14
14
  "output-styles": "Output styles are not run by Nylorun",
@@ -19,13 +19,34 @@ const NOT_RUN = {
19
19
  /** The agent the compiler wraps a plugin's skills and servers in, to read them as an agent's. */
20
20
  const WRAPPER = new TextEncoder().encode("---\nname: plugin\ndescription: An Agent Plugin's skills and MCP servers.\n---\n");
21
21
  const isSecretShaped = (base) => base === ".env" || base.startsWith(".env.") || base.endsWith(".pem") || base.endsWith(".key");
22
+ /** A plugin file the manifest already carries: its plugin.json, servers, skills and subagent files. */
23
+ const carried = (path) => path === PLUGIN_FILE || path === "mcp.json" || path === ".mcp.json" || path.startsWith("skills/") || pluginSubagentFile(path) !== undefined;
22
24
  /** The files of `plugins/<name>/` the compiler reads, relative to the plugin's folder. */
23
25
  export function pluginTextPaths(paths) {
24
- return paths.filter((path) => path === PLUGIN_FILE || path === "mcp.json" || path === ".mcp.json" || /^skills\/[^/]+\/SKILL\.md$/.test(path));
26
+ return paths.filter((path) => path === PLUGIN_FILE ||
27
+ path === "mcp.json" ||
28
+ path === ".mcp.json" ||
29
+ /^skills\/[^/]+\/SKILL\.md$/.test(path) ||
30
+ pluginSubagentFile(path) !== undefined ||
31
+ pluginSubagentFlow(path));
32
+ }
33
+ /** A plugin's subagent file, relative to the plugin's folder (`agents/<file>.md`): its file name, or undefined. */
34
+ export function pluginSubagentFile(path) {
35
+ return /^agents\/([^/]+)\.md$/.exec(path)?.[1];
36
+ }
37
+ /** A JSON file beside a plugin's subagent files, such as the flow file a subagent's `flow:` names. */
38
+ export function pluginSubagentFlow(path) {
39
+ return /^agents\/[^/]+\.json$/.test(path);
40
+ }
41
+ /** A plugin's label as its `plugin.json` gives it, read quietly: undefined when it names none. */
42
+ export function pluginLabelOf(manifest) {
43
+ if (!isObject(manifest) || !isPluginName(manifest.name))
44
+ return undefined;
45
+ return { name: manifest.name, ...(typeof manifest.version === "string" ? { version: manifest.version } : {}) };
25
46
  }
26
47
  /** Folds every plugin under `plugins/`. */
27
48
  export function foldPlugins(ctx) {
28
- const folded = { servers: new Map(), skills: new Map() };
49
+ const folded = { servers: new Map(), skills: new Map(), mounted: new Map() };
29
50
  for (const [folder, paths] of foldersUnder("plugins", ctx.entries.keys()))
30
51
  foldPlugin(ctx, folder, paths, folded);
31
52
  return folded;
@@ -36,16 +57,18 @@ function foldPlugin(ctx, folder, paths, folded) {
36
57
  const error = (code, message, at, path, key = false) => ctx.report("error", code, message, at, path, { key });
37
58
  // What it holds that Nylorun does not read: one note per top-level part.
38
59
  const noted = new Set();
60
+ // In agent-folder/4 a plugin's agents/*.md are subagents, read by the format 4 expansion.
61
+ const v4 = ctx.engineFacts().v4 !== undefined;
39
62
  for (const path of paths) {
40
63
  const top = path.split("/")[0];
41
- if (READ.has(top) || isSecretShaped(path.split("/").at(-1)) || noted.has(top))
64
+ if (READ.has(top) || isSecretShaped(path.split("/").at(-1)) || noted.has(top) || (v4 && top === "agents"))
42
65
  continue;
43
66
  noted.add(top);
44
67
  const isFolder = path.includes("/");
45
68
  ctx.report("note", "plugin_part_ignored", `${NOT_RUN[top] ?? "Kept with the source: Nylorun reads a plugin's plugin.json, mcp.json and skills/"}`, `${prefix}${top}${isFolder ? "/" : ""}`);
46
69
  }
47
70
  if (!paths.includes(PLUGIN_FILE)) {
48
- error("plugin_invalid", `${prefix} has no plugin.json: an Agent Plugin names itself there, with the Agent Plugins $schema and its name`, file);
71
+ error("plugin_invalid", `${prefix} has no plugin.json: an Agent Plugin names itself there, with its name`, file);
49
72
  return;
50
73
  }
51
74
  const manifest = ctx.readJson(file);
@@ -61,8 +84,9 @@ function foldPlugin(ctx, folder, paths, folded) {
61
84
  const close = ctx.suggest(key, PLUGIN_KEYS);
62
85
  ctx.report("warning", "plugin_unknown_key", `plugin.json has no field '${key}' in Agent Plugins 1.0.0: it is not read.${close ? ` Did you mean '${close}'?` : ""}`, file, [key], { key: true });
63
86
  }
64
- if (manifest.$schema !== AGENT_PLUGINS_PLUGIN_SCHEMA)
65
- invalid(`plugin.json names the Agent Plugins 1.0.0 plugin schema in $schema (${AGENT_PLUGINS_PLUGIN_SCHEMA})`, manifest.$schema === undefined ? [] : ["$schema"]);
87
+ // No $schema reads as Agent Plugins 1.0.0, as other hosts read it; another format is refused.
88
+ if (manifest.$schema !== undefined && manifest.$schema !== AGENT_PLUGINS_PLUGIN_SCHEMA)
89
+ invalid(`plugin.json's $schema names another format: Nylorun reads Agent Plugins 1.0.0 (${AGENT_PLUGINS_PLUGIN_SCHEMA}), or no $schema`, ["$schema"]);
66
90
  if (!isPluginName(manifest.name))
67
91
  invalid("name is required: 1-64 lowercase letters, digits, hyphens and periods, starting and ending with a letter or digit", manifest.name === undefined ? [] : ["name"]);
68
92
  for (const field of ["version", "description", "homepage", "repository", "license"])
@@ -87,16 +111,29 @@ function foldPlugin(ctx, folder, paths, folded) {
87
111
  }
88
112
  if (!valid)
89
113
  return;
90
- const label = { name: manifest.name, ...(typeof manifest.version === "string" ? { version: manifest.version } : {}) };
91
- // mcp.json, as Agent Plugins writes it: with its $schema. Claude Code's .mcp.json when there is none.
114
+ const label = pluginLabelOf(manifest);
115
+ // Its own files, mounted whole in the sandbox when it holds any the manifest doesn't carry, as
116
+ // other hosts give a plugin's root: every file but secret-shaped ones.
117
+ const kept = paths.filter((path) => !isSecretShaped(path.split("/").at(-1))).sort();
118
+ if (kept.some((path) => !carried(path))) {
119
+ const files = {};
120
+ for (const path of kept) {
121
+ const entry = ctx.entries.get(prefix + path);
122
+ if (entry)
123
+ files[path] = `sha256:${entry.sha256}`;
124
+ }
125
+ folded.mounted.set(label.name, { ...label, files });
126
+ }
127
+ // mcp.json, as Agent Plugins writes it: no $schema reads as 1.0.0, and one naming another format is
128
+ // refused. Claude Code's .mcp.json when there is none.
92
129
  const mcpFile = paths.includes("mcp.json") ? "mcp.json" : paths.includes(".mcp.json") ? ".mcp.json" : undefined;
93
130
  if (mcpFile === "mcp.json" && paths.includes(".mcp.json"))
94
131
  ctx.report("note", "plugin_part_ignored", "Claude Code's server file is not read: the plugin's mcp.json is", `${prefix}.mcp.json`);
95
132
  if (mcpFile === "mcp.json") {
96
133
  const value = quietJson(ctx, prefix + "mcp.json");
97
- if (value && value.$schema === undefined)
98
- ctx.report("error", "plugin_invalid", `A plugin's mcp.json names the Agent Plugins MCP schema in $schema (${AGENT_PLUGINS_MCP_SCHEMA}), as Agent Plugins requires`, prefix + "mcp.json", [], {
99
- at: jsonPosition(ctx, prefix + "mcp.json", []),
134
+ if (value && value.$schema !== undefined && value.$schema !== AGENT_PLUGINS_MCP_SCHEMA)
135
+ ctx.report("error", "plugin_invalid", `A plugin's mcp.json $schema names another format: Nylorun reads Agent Plugins 1.0.0 (${AGENT_PLUGINS_MCP_SCHEMA}), or no $schema`, prefix + "mcp.json", ["$schema"], {
136
+ at: jsonPosition(ctx, prefix + "mcp.json", ["$schema"]),
100
137
  });
101
138
  }
102
139
  // Its skills and servers, read as an agent's own by the compiler itself, inside a wrapper.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The JSON Schema document of each kind of file in an agent folder (track T7, design §3.10), so
2
+ * The JSON Schema document of each kind of file in an agent folder, so
3
3
  * an editor checks and completes a folder's files as it is written, from the `json.schemas`
4
4
  * mapping `nylorun init` writes. Each `$id` is `https://docs.nylorun.com/schemas/agent-folder/v1/
5
5
  * <kind>.json`; the build writes them to `dist/schemas/agent-folder/`, exported as
@@ -53,13 +53,14 @@ function fromZod(schema, defs, description) {
53
53
  /**
54
54
  * A kind's revision within format 1, when its document gained an optional key (a published `$id`
55
55
  * names one document for good): `AGENT.md` took `model` (Host feature `agent-model`), published
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`, then `roles` (ADR-154), as `agent-md.5.json`;
56
+ * as `agent-md.1.json`, then `format: agent-folder/2` and `engine`, as `agent-md.2.json`,
57
+ * then `engine.triggers`, as `agent-md.3.json`, then `format: agent-folder/3` and
58
+ * `plugins`, as `agent-md.4.json`, then `roles`, as `agent-md.5.json`, then
59
+ * `format: agent-folder/4` and a subagent file's keys, as `agent-md.6.json`;
59
60
  * `runtime.json` took a secret slot's `toolPrefix` (Host feature `secret-routing`), published as
60
- * `runtime.1.json`, then `limits.triggers` (D83), as `runtime.2.json`.
61
+ * `runtime.1.json`, then `limits.triggers`, 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: 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 = [