@nylorun/core 0.26.0-beta → 0.28.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 (47) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +6 -0
  3. package/dist/compatibility.d.ts +11 -2
  4. package/dist/compatibility.js +10 -0
  5. package/dist/contracts.d.ts +362 -0
  6. package/dist/contracts.js +131 -5
  7. package/dist/define.d.ts +2 -1
  8. package/dist/define.js +2 -1
  9. package/dist/definition/cron.d.ts +15 -0
  10. package/dist/definition/cron.js +155 -0
  11. package/dist/definition/sections.d.ts +11 -0
  12. package/dist/definition/sections.js +29 -20
  13. package/dist/folder/compile.d.ts +87 -0
  14. package/dist/folder/compile.js +1280 -0
  15. package/dist/folder/context.d.ts +97 -0
  16. package/dist/folder/context.js +79 -0
  17. package/dist/folder/decompile.d.ts +18 -0
  18. package/dist/folder/decompile.js +660 -0
  19. package/dist/folder/fix.d.ts +22 -0
  20. package/dist/folder/fix.js +191 -0
  21. package/dist/folder/flow.d.ts +42 -0
  22. package/dist/folder/flow.js +215 -0
  23. package/dist/folder/frontmatter.d.ts +21 -0
  24. package/dist/folder/frontmatter.js +91 -0
  25. package/dist/folder/index.d.ts +12 -0
  26. package/dist/folder/index.js +12 -0
  27. package/dist/folder/json-schema.d.ts +15 -0
  28. package/dist/folder/json-schema.js +212 -0
  29. package/dist/folder/json.d.ts +28 -0
  30. package/dist/folder/json.js +183 -0
  31. package/dist/folder/nested.d.ts +24 -0
  32. package/dist/folder/nested.js +378 -0
  33. package/dist/folder/plugins.d.ts +23 -0
  34. package/dist/folder/plugins.js +155 -0
  35. package/dist/folder/schemas.d.ts +8 -0
  36. package/dist/folder/schemas.js +238 -0
  37. package/dist/folder/suggest.d.ts +13 -0
  38. package/dist/folder/suggest.js +63 -0
  39. package/dist/schemas/agent-folder/agent-md.schema.json +143 -0
  40. package/dist/schemas/agent-folder/flow.schema.json +466 -0
  41. package/dist/schemas/agent-folder/mcp.schema.json +59 -0
  42. package/dist/schemas/agent-folder/runtime.schema.json +447 -0
  43. package/dist/schemas/agent-folder/tool.schema.json +77 -0
  44. package/dist/schemas/agent-folder/trigger-md.schema.json +65 -0
  45. package/dist/utils/runtime-limits.d.ts +8 -0
  46. package/dist/utils/runtime-limits.js +19 -0
  47. package/package.json +14 -3
@@ -0,0 +1,378 @@
1
+ /**
2
+ * The folders inside an agent folder (track T7, D80; design §3.3, §3.8), compiled by the same
3
+ * compiler, one level in:
4
+ *
5
+ * - **Subagents.** `agents/<id>/` of an agent (no `flow.json` beside it) is an agent folder
6
+ * without `runtime.json`, `triggers/` or `files/`, offered to the agent as a tool, exactly as
7
+ * the TypeScript builder offers an agent used as a tool: named `<id>`, with the agent's
8
+ * description, input `{ task }`, and the agent's manifest embedded. One level deep: a subagent
9
+ * has no `agents/` of its own, unless it is a flow (a flow offered as a tool).
10
+ * - **Flows.** `flow.json` makes a folder a flow (`harness.kind: "workflow"`, v3's node tree).
11
+ * A flow root has one flat `agents/`, and every `flow.json` under it names stages from there by
12
+ * id. A stage with its own `flow.json` is a sub-flow over the same agents, so it has no
13
+ * `agents/`. The compiler embeds each agent where v3 wants it. A flow's `AGENT.md` has no body
14
+ * and may name `inputSchema`; a flow has no `mcp.json`, `skills/` or plugins, and only the
15
+ * tools its nodes name. An agent of `agents/` that no `flow.json` names is a warning.
16
+ * - **Plugins.** `plugins/<name>/` (`plugins.ts`).
17
+ *
18
+ * A folder inside another reports its diagnostics with paths from the uploaded folder
19
+ * (`agents/research/flow.json:3:12`). `/x` in it names a file from the uploaded folder's root,
20
+ * and `./x` one from its own. A slot it needs is derived in the uploaded folder's runtime
21
+ * section.
22
+ */
23
+ import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
24
+ import { loopManifestOf } from "../definition/sections.js";
25
+ import { TOOL_SECRET_NAME_PATTERN } from "../contracts.js";
26
+ import { addInner, cloneJson, foldersUnder, isObject, jsonPosition, } from "./context.js";
27
+ import { translateFlow } from "./flow.js";
28
+ import { foldPlugins, pluginTextPaths } from "./plugins.js";
29
+ const AGENT_FILE = "AGENT.md";
30
+ const FLOW_FILE = "flow.json";
31
+ /** The files of every folder under `agents/` and `plugins/` the compiler reads. */
32
+ export function nestedTextPaths(entries, folderTextPaths) {
33
+ const paths = [];
34
+ const all = entries.map((entry) => entry.path);
35
+ for (const id of foldersUnder("agents", all).keys()) {
36
+ const prefix = `agents/${id}/`;
37
+ const nested = entries.filter((entry) => entry.path.startsWith(prefix)).map((entry) => ({ ...entry, path: entry.path.slice(prefix.length) }));
38
+ paths.push(...folderTextPaths(nested).map((path) => prefix + path));
39
+ }
40
+ for (const [name, inner] of foldersUnder("plugins", all))
41
+ paths.push(...pluginTextPaths(inner).map((path) => `plugins/${name}/${path}`));
42
+ return paths;
43
+ }
44
+ /** `/x` from a folder inside another: the uploaded folder's file, or why not. */
45
+ export function scopedSchema(scope, value, fail) {
46
+ const found = scope.schema(value.slice(1));
47
+ if (found === undefined)
48
+ return undefined;
49
+ if ("message" in found) {
50
+ fail(found.code, found.message);
51
+ return undefined;
52
+ }
53
+ return found.schema;
54
+ }
55
+ /** The hooks `compileAgentFolder` calls for one folder: plugins, subagents and flows. */
56
+ export function folderParts(ctx) {
57
+ const isFlow = [...ctx.kinds.values()].includes("flow");
58
+ let plugins;
59
+ const folded = () => (plugins ??= isFlow ? { servers: new Map(), skills: new Map() } : foldPlugins(ctx));
60
+ return {
61
+ /** Adds the plugins' MCP servers, before `AGENT.md` says how the agent uses them. */
62
+ mergeServers(servers) {
63
+ for (const [key, { server, file }] of folded().servers) {
64
+ if (servers[key]) {
65
+ ctx.report("error", "plugin_duplicate", `MCP server ${key} is declared in mcp.json and by this plugin: an agent has one server of a name`, file, ["mcpServers", key], {
66
+ at: jsonPosition(ctx, file, ["mcpServers", key], true),
67
+ });
68
+ continue;
69
+ }
70
+ servers[key] = server;
71
+ ctx.origins.push([["harness", "mcpServers", key], { file, path: ["mcpServers", key] }]);
72
+ }
73
+ },
74
+ /**
75
+ * `credential` in `AGENT.md`'s block for a plugin's server, which cannot know the agent's slot
76
+ * names. True when the server is a plugin's, so the block may name it.
77
+ */
78
+ serverCredential(servers, key, settings, at) {
79
+ const server = servers[key];
80
+ if (!server || server.plugin === undefined)
81
+ return false;
82
+ const credential = settings.credential;
83
+ if (credential === undefined)
84
+ return true;
85
+ const path = [...at, "credential"];
86
+ if (typeof credential !== "string" || !TOOL_SECRET_NAME_PATTERN.test(credential)) {
87
+ ctx.report("error", "credential_name", "credential names a secret slot: 1-64 letters, digits, '.', '_' and '-'", AGENT_FILE, path);
88
+ return true;
89
+ }
90
+ if (server.credential !== undefined) {
91
+ ctx.report("error", "credential_twice", `The plugin's mcp.json already names ${String(server.credential)} for ${key}: a server authenticates with one credential`, AGENT_FILE, path);
92
+ return true;
93
+ }
94
+ server.credential = credential;
95
+ ctx.deriveSlot(credential, "bearer", String(server.url), AGENT_FILE, path);
96
+ ctx.origins.push([["harness", "mcpServers", key, "credential"], { file: AGENT_FILE, path }]);
97
+ return true;
98
+ },
99
+ /** Adds the plugins' skills, before `AGENT.md` says which secrets each gets. */
100
+ mergeSkills(skills) {
101
+ for (const [key, { skill, file }] of folded().skills) {
102
+ if (skills[key]) {
103
+ ctx.report("error", "plugin_duplicate", `Skill ${key} is in skills/ and in this plugin: an agent has one skill of a name`, file);
104
+ continue;
105
+ }
106
+ skills[key] = skill;
107
+ ctx.origins.push([["harness", "skills", key], { file, path: [] }]);
108
+ }
109
+ },
110
+ /**
111
+ * Subagents, or the flow: called once the folder's own parts are compiled. False when a part
112
+ * it needs did not compile and its errors are reported elsewhere (a stage of the flow root).
113
+ */
114
+ compose() {
115
+ if (ctx.scope && ctx.scope.role !== "plugin")
116
+ nestedChecks(ctx);
117
+ if (isFlow)
118
+ return composeFlow(ctx);
119
+ composeAgent(ctx);
120
+ return true;
121
+ },
122
+ };
123
+ }
124
+ /** The scope of a folder inside this one: its slots and `/x` schemas are the uploaded folder's. */
125
+ function innerScope(ctx, prefix, role, namespace) {
126
+ return {
127
+ role,
128
+ ...(namespace === undefined ? {} : { namespace }),
129
+ deriveSlot: (credential, type, url, file, at, header) => ctx.deriveSlot(credential, type, url, prefix + file, [], header, at),
130
+ schema: ctx.scope?.schema ?? rootSchema(ctx),
131
+ };
132
+ }
133
+ /** `/x` read from the uploaded folder: a JSON Schema file anywhere in it. */
134
+ function rootSchema(ctx) {
135
+ const read = new Map();
136
+ return (target) => {
137
+ if (target.split("/").some((segment) => segment === "" || segment === "." || segment === ".."))
138
+ return { code: "path_outside", message: `/${target} leaves the folder: a path names a file inside it` };
139
+ if (!ctx.entries.has(target))
140
+ return { code: "schema_missing", message: `/${target} is not a file in the folder` };
141
+ const kind = ctx.kinds.get(target);
142
+ const segments = target.split("/");
143
+ const base = segments.at(-1);
144
+ const schemaFile = kind === "schema" || (kind === "nested" && (base.endsWith(".schema.json") || (segments.includes("schemas") && base.endsWith(".json"))));
145
+ if (!schemaFile)
146
+ return { code: "schema_invalid", message: `/${target} is not a JSON Schema file: name it *.schema.json or keep it under schemas/` };
147
+ if (!read.has(target))
148
+ read.set(target, ctx.readJson(target));
149
+ const schema = read.get(target);
150
+ return schema === undefined ? undefined : { schema };
151
+ };
152
+ }
153
+ /** Compiles `prefix` (`agents/<id>/`) as a folder of its own, its diagnostics added to this one's. */
154
+ function compileInner(ctx, prefix, role, namespace) {
155
+ const entries = [];
156
+ for (const [path, entry] of ctx.entries)
157
+ if (path.startsWith(prefix))
158
+ entries.push({ ...entry, path: path.slice(prefix.length) });
159
+ const files = new Map();
160
+ for (const [path, bytes] of ctx.files)
161
+ if (path.startsWith(prefix))
162
+ files.set(path.slice(prefix.length), bytes);
163
+ const name = prefix.split("/").at(-2);
164
+ const result = ctx.compile({ entries, files, name }, innerScope(ctx, prefix, role, namespace));
165
+ addInner(ctx, prefix, result.diagnostics);
166
+ return result.manifest;
167
+ }
168
+ /** Why an id under `agents/` cannot name a tool or a stage, or undefined when it can. */
169
+ function badId(ctx, id) {
170
+ if (DELEGATE_NAME_PATTERN.test(id))
171
+ return false;
172
+ ctx.report("error", "agent_name", `agents/${id}/ names a tool or a stage, so its name takes only letters, digits, _ and -, up to 64 characters`, `agents/${id}/${AGENT_FILE}`);
173
+ return true;
174
+ }
175
+ /** The first file of `agents/<id>/`, for a diagnostic about the folder. */
176
+ const folderFile = (id, inner) => `agents/${id}/${inner.includes(AGENT_FILE) ? AGENT_FILE : inner[0]}`;
177
+ /** What only the uploaded folder has: a subagent or stage runs in its runtime and its harness. */
178
+ function nestedChecks(ctx) {
179
+ const what = ctx.scope.role === "subagent" ? "a subagent" : "a stage of a flow";
180
+ const refuse = (message, file, path) => ctx.report("error", "nested_refused", message, file, path, { key: path !== undefined && path.length > 0 });
181
+ for (const [path, kind] of ctx.kinds) {
182
+ if (kind === "runtime")
183
+ refuse(`runtime.json is the uploaded folder's: ${what} runs in its runtime, so move this to the root`, path);
184
+ else if (kind === "trigger")
185
+ refuse(`triggers/ is the uploaded folder's: a trigger starts the root agent, so move this to the root's triggers/`, path);
186
+ else if (kind === "file")
187
+ refuse(`files/ is the uploaded folder's: its runtime seeds the disk every agent shares, so move this to the root's files/`, path);
188
+ }
189
+ const keys = {
190
+ format: "format is read only in the uploaded folder's AGENT.md: one folder, one format",
191
+ harness: `${what} runs in the harness of the agent that holds it: set harness in the root's AGENT.md`,
192
+ memory: `memory is the root agent's: ${what} keeps none of its own`,
193
+ loop: `loop settings are the root agent's: ${what} has none of its own`,
194
+ };
195
+ for (const [key, message] of Object.entries(keys))
196
+ if (ctx.front[key] !== undefined)
197
+ refuse(message, AGENT_FILE, [key]);
198
+ // Agent manifest v7, which embeds an agent, has no place for a credential or a skill's secrets.
199
+ const settings = isObject(ctx.front.mcpServers) ? ctx.front.mcpServers : {};
200
+ for (const [key, server] of Object.entries(isObject(ctx.harness.mcpServers) ? ctx.harness.mcpServers : {})) {
201
+ if (!isObject(server) || server.credential === undefined)
202
+ continue;
203
+ const message = `${key} authenticates with ${String(server.credential)}, and ${what}'s MCP servers take no credential: only the root agent's servers do. Give the server to the root agent, or call it without one`;
204
+ if (isObject(settings[key]) && settings[key].credential !== undefined)
205
+ ctx.report("error", "credential_unsupported", message, AGENT_FILE, ["mcpServers", key, "credential"]);
206
+ else if (server.plugin !== undefined) {
207
+ const origin = ctx.origins.find(([path]) => path.length === 3 && path[1] === "mcpServers" && path[2] === key)?.[1];
208
+ ctx.report("error", "credential_unsupported", message, origin?.file, origin?.path, { at: origin && jsonPosition(ctx, origin.file, origin.path, true) });
209
+ }
210
+ else
211
+ ctx.report("error", "credential_unsupported", message, "mcp.json", ["mcpServers", key, "headers"]);
212
+ }
213
+ for (const [key, skill] of Object.entries(isObject(ctx.harness.skills) ? ctx.harness.skills : {}))
214
+ if (isObject(skill) && skill.secrets !== undefined)
215
+ ctx.report("error", "credential_unsupported", `Only the root agent's skills get secrets: ${what}'s skill ${key} gets none`, AGENT_FILE, ["skills", key, "secrets"]);
216
+ }
217
+ /** An agent: its `agents/` are tools, and its plugins are listed. */
218
+ function composeAgent(ctx) {
219
+ if (ctx.front.inputSchema !== undefined)
220
+ 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 });
221
+ const harness = ctx.harness;
222
+ const folders = foldersUnder("agents", ctx.entries.keys());
223
+ if (folders.size > 0 && ctx.scope?.role === "subagent")
224
+ for (const [id, inner] of folders)
225
+ 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));
226
+ else if (folders.size > 0) {
227
+ const tools = Array.isArray(harness.tools) ? harness.tools : [];
228
+ const httpTools = new Set(tools.map((tool) => tool.name));
229
+ for (const [id, inner] of folders) {
230
+ if (badId(ctx, id))
231
+ continue;
232
+ if (httpTools.has(id)) {
233
+ ctx.report("error", "tool_twice", `agents/${id}/ and tools/${id}.json both name the tool ${id}: rename one`, folderFile(id, inner));
234
+ continue;
235
+ }
236
+ const manifest = compileInner(ctx, `agents/${id}/`, "subagent");
237
+ if (!manifest)
238
+ continue;
239
+ ctx.origins.push([["harness", "tools", tools.length], { file: `agents/${id}/${AGENT_FILE}`, path: [] }]);
240
+ // As the TypeScript builder emits an agent used as a tool (`delegateTool`).
241
+ tools.push({
242
+ name: id,
243
+ ...(manifest.description === undefined ? {} : { description: manifest.description }),
244
+ inputSchema: cloneJson(DELEGATE_INPUT_SCHEMA),
245
+ agent: loopManifestOf(manifest),
246
+ });
247
+ }
248
+ if (tools.length > 0)
249
+ harness.tools = tools;
250
+ }
251
+ // The plugins its skills and servers came from, each once, by name (`pluginsOf`).
252
+ const labels = new Map();
253
+ for (const item of [...Object.values(isObject(harness.skills) ? harness.skills : {}), ...Object.values(isObject(harness.mcpServers) ? harness.mcpServers : {})]) {
254
+ const label = isObject(item) && isObject(item.plugin) ? item.plugin : undefined;
255
+ if (label && !labels.has(label.name))
256
+ labels.set(label.name, { ...label });
257
+ }
258
+ if (labels.size > 0)
259
+ harness.plugins = [...labels.values()].sort((a, b) => a.name.localeCompare(b.name));
260
+ }
261
+ /** A flow root's `agents/`: compiled once each, when a node first names it. */
262
+ class FlowNamespace {
263
+ ids;
264
+ used = new Set();
265
+ #members = new Map();
266
+ #ctx;
267
+ constructor(ctx, folders) {
268
+ this.#ctx = ctx;
269
+ this.ids = [...folders.keys()];
270
+ for (const id of this.ids)
271
+ if (badId(ctx, id))
272
+ this.#members.set(id, {});
273
+ }
274
+ resolve(id) {
275
+ if (!this.ids.includes(id))
276
+ return "unknown";
277
+ const member = this.#members.get(id);
278
+ if (member === "compiling")
279
+ return "cycle";
280
+ if (member)
281
+ return member.manifest ?? "failed";
282
+ this.#members.set(id, "compiling");
283
+ const manifest = compileInner(this.#ctx, `agents/${id}/`, "stage", this);
284
+ const embedded = manifest === undefined ? undefined : loopManifestOf(manifest);
285
+ this.#members.set(id, embedded === undefined ? {} : { manifest: embedded });
286
+ return embedded ?? "failed";
287
+ }
288
+ }
289
+ /** A flow: `flow.json`'s node tree over the flow root's agents and the tools beside it. */
290
+ function composeFlow(ctx) {
291
+ const { harness, front } = ctx;
292
+ const refuse = (message, file, path) => ctx.report("error", "flow_refused", message, file, path, { key: path !== undefined && path.length > 0 });
293
+ // What a flow has none of: each of its agents has its own.
294
+ if (ctx.agent) {
295
+ const lines = ctx.agent.body.split("\n");
296
+ const first = lines.findIndex((line) => line.trim() !== "");
297
+ if (first >= 0)
298
+ 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, {
299
+ at: { line: ctx.agent.bodyLine + first, column: 1 },
300
+ });
301
+ }
302
+ const noted = new Set();
303
+ for (const [path, kind] of ctx.kinds) {
304
+ const top = path.split("/").slice(0, 2).join("/");
305
+ if (kind === "instructions")
306
+ refuse("A flow has no instructions: move this to the agent under agents/ that needs it", path);
307
+ else if (kind === "mcp")
308
+ refuse("A flow has no MCP servers of its own: give mcp.json to the agents under agents/ that call them", path);
309
+ else if ((kind === "skill" || kind === "plugin") && !noted.has(top)) {
310
+ noted.add(top);
311
+ 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}/`);
312
+ }
313
+ }
314
+ for (const key of ["mcpServers", "skills", "memory"])
315
+ if (front[key] !== undefined)
316
+ refuse(`${key} is an agent's: set it in the AGENT.md of the agent under agents/ that needs it`, AGENT_FILE, [key]);
317
+ const inputSchema = front.inputSchema === undefined ? undefined : ctx.schemaAt(AGENT_FILE, ["inputSchema"], front.inputSchema);
318
+ // The agents it names: the flow root's.
319
+ const own = foldersUnder("agents", ctx.entries.keys());
320
+ let namespace;
321
+ let isRoot = false;
322
+ if (ctx.scope?.role === "stage" && ctx.scope.namespace) {
323
+ namespace = ctx.scope.namespace;
324
+ for (const [id, inner] of own)
325
+ ctx.report("error", "flow_namespace", `A sub-flow names its stages from the flow root's agents/, so it has none of its own: move agents/${id}/ to the flow root's agents/`, folderFile(id, inner));
326
+ }
327
+ else {
328
+ namespace = new FlowNamespace(ctx, own);
329
+ isRoot = true;
330
+ }
331
+ const flow = ctx.readJson(FLOW_FILE);
332
+ if (!flow) {
333
+ // Its agents are compiled all the same, so one pass finds their errors too.
334
+ if (isRoot)
335
+ for (const id of namespace.ids)
336
+ namespace.resolve(id);
337
+ return true;
338
+ }
339
+ if ("$schema" in flow)
340
+ ctx.checkSchemaUrl(FLOW_FILE, "flow", flow.$schema);
341
+ const { $schema: _, ...tree } = flow;
342
+ const tools = new Map();
343
+ for (const tool of Array.isArray(harness.tools) ? harness.tools : [])
344
+ tools.set(String(tool.name), tool);
345
+ 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);
346
+ for (const name of tools.keys())
347
+ if (!translated.toolsUsed.has(name))
348
+ ctx.report("error", "tool_unused", `No node of flow.json names ${name}: a flow holds only the tools its nodes name`, `tools/${name}.json`);
349
+ if (isRoot) {
350
+ const unused = namespace.ids.filter((id) => !namespace.used.has(id));
351
+ for (const id of unused) {
352
+ // Compiled all the same, so its errors are found now rather than when it is named.
353
+ namespace.resolve(id);
354
+ ctx.report("warning", "agent_unused", `No flow.json under the flow root names ${id}, so it never runs and is left out of the manifest: name it in a node, or remove it`, folderFile(id, own.get(id)));
355
+ }
356
+ }
357
+ if (!translated.complete)
358
+ return false;
359
+ if (!translated.root)
360
+ return true;
361
+ // The workflow harness, in place of the agent harness built so far.
362
+ const { id, outputSchema, loop } = harness;
363
+ for (const key of Object.keys(harness))
364
+ delete harness[key];
365
+ Object.assign(harness, {
366
+ kind: "workflow",
367
+ ...(id === undefined ? {} : { id }),
368
+ ...(inputSchema === undefined ? {} : { inputSchema }),
369
+ ...(outputSchema === undefined ? {} : { outputSchema }),
370
+ root: translated.root,
371
+ agents: translated.agents,
372
+ ...(loop === undefined ? {} : { loop }),
373
+ });
374
+ ctx.origins.push([["harness", "root"], { file: FLOW_FILE, path: [] }], [["harness", "inputSchema"], { file: AGENT_FILE, path: ["inputSchema"] }]);
375
+ for (const agent of Object.keys(translated.agents))
376
+ ctx.origins.push([["harness", "agents", agent], { file: isRoot ? `agents/${agent}/${AGENT_FILE}` : FLOW_FILE, path: [] }]);
377
+ return true;
378
+ }
@@ -0,0 +1,23 @@
1
+ import { type FolderContext } from "./context.js";
2
+ export declare const AGENT_PLUGINS_PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
3
+ export declare const AGENT_PLUGINS_MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";
4
+ /** One label: the plugin a skill or server came from. */
5
+ export interface PluginLabel {
6
+ readonly name: string;
7
+ readonly version?: string;
8
+ }
9
+ /** A plugin's skills and servers, labelled, with the file each came from. */
10
+ export interface FoldedPlugins {
11
+ readonly servers: Map<string, {
12
+ readonly server: Record<string, unknown>;
13
+ readonly file: string;
14
+ }>;
15
+ readonly skills: Map<string, {
16
+ readonly skill: Record<string, unknown>;
17
+ readonly file: string;
18
+ }>;
19
+ }
20
+ /** The files of `plugins/<name>/` the compiler reads, relative to the plugin's folder. */
21
+ export declare function pluginTextPaths(paths: readonly string[]): string[];
22
+ /** Folds every plugin under `plugins/`. */
23
+ export declare function foldPlugins(ctx: FolderContext): FoldedPlugins;
@@ -0,0 +1,155 @@
1
+ import { addInner, foldersUnder, isObject, jsonPosition, quietJson } from "./context.js";
2
+ export const AGENT_PLUGINS_PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
3
+ export const AGENT_PLUGINS_MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";
4
+ const PLUGIN_FILE = "plugin.json";
5
+ const PLUGIN_KEYS = ["$schema", "name", "version", "description", "author", "homepage", "repository", "license", "keywords", "extensions"];
6
+ const AUTHOR_KEYS = ["name", "email", "url"];
7
+ /** What the compiler reads of a plugin: the rest is kept with the source. */
8
+ const READ = new Set([PLUGIN_FILE, "mcp.json", ".mcp.json", "skills"]);
9
+ /** Parts of plugins for other tools, which Nylorun does not run. */
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",
12
+ hooks: "Hooks are not run by Nylorun",
13
+ commands: "Slash commands are not run by Nylorun",
14
+ "output-styles": "Output styles are not run by Nylorun",
15
+ ".claude-plugin": "Claude Code's plugin manifest is not read: Nylorun reads the plugin's plugin.json",
16
+ "settings.json": "Plugin settings are not read by Nylorun",
17
+ ".lsp.json": "LSP servers are not run by Nylorun",
18
+ };
19
+ /** The agent the compiler wraps a plugin's skills and servers in, to read them as an agent's. */
20
+ const WRAPPER = new TextEncoder().encode("---\nname: plugin\ndescription: An Agent Plugin's skills and MCP servers.\n---\n");
21
+ const isSecretShaped = (base) => base === ".env" || base.startsWith(".env.") || base.endsWith(".pem") || base.endsWith(".key");
22
+ /** The files of `plugins/<name>/` the compiler reads, relative to the plugin's folder. */
23
+ export function pluginTextPaths(paths) {
24
+ return paths.filter((path) => path === PLUGIN_FILE || path === "mcp.json" || path === ".mcp.json" || /^skills\/[^/]+\/SKILL\.md$/.test(path));
25
+ }
26
+ /** Folds every plugin under `plugins/`. */
27
+ export function foldPlugins(ctx) {
28
+ const folded = { servers: new Map(), skills: new Map() };
29
+ for (const [folder, paths] of foldersUnder("plugins", ctx.entries.keys()))
30
+ foldPlugin(ctx, folder, paths, folded);
31
+ return folded;
32
+ }
33
+ function foldPlugin(ctx, folder, paths, folded) {
34
+ const prefix = `plugins/${folder}/`;
35
+ const file = prefix + PLUGIN_FILE;
36
+ const error = (code, message, at, path, key = false) => ctx.report("error", code, message, at, path, { key });
37
+ // What it holds that Nylorun does not read: one note per top-level part.
38
+ const noted = new Set();
39
+ for (const path of paths) {
40
+ const top = path.split("/")[0];
41
+ if (READ.has(top) || isSecretShaped(path.split("/").at(-1)) || noted.has(top))
42
+ continue;
43
+ noted.add(top);
44
+ const isFolder = path.includes("/");
45
+ 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
+ }
47
+ 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);
49
+ return;
50
+ }
51
+ const manifest = ctx.readJson(file);
52
+ if (!manifest)
53
+ return;
54
+ let valid = true;
55
+ const invalid = (message, path, key = false) => {
56
+ valid = false;
57
+ error("plugin_invalid", message, file, path, key);
58
+ };
59
+ for (const key of Object.keys(manifest))
60
+ if (!PLUGIN_KEYS.includes(key)) {
61
+ const close = ctx.suggest(key, PLUGIN_KEYS);
62
+ 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
+ }
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"]);
66
+ if (!isPluginName(manifest.name))
67
+ 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
+ for (const field of ["version", "description", "homepage", "repository", "license"])
69
+ if (manifest[field] !== undefined && typeof manifest[field] !== "string")
70
+ invalid(`${field} is a string`, [field]);
71
+ if (manifest.keywords !== undefined && (!Array.isArray(manifest.keywords) || manifest.keywords.some((item) => typeof item !== "string")))
72
+ invalid("keywords is a list of strings", ["keywords"]);
73
+ if (manifest.author !== undefined) {
74
+ if (!isObject(manifest.author))
75
+ invalid("author is an object: name, email and url", ["author"]);
76
+ else
77
+ for (const [key, value] of Object.entries(manifest.author))
78
+ if (!AUTHOR_KEYS.includes(key) || typeof value !== "string")
79
+ invalid("author takes name, email and url, each a string", ["author", key], true);
80
+ }
81
+ if (manifest.extensions !== undefined) {
82
+ if (!isObject(manifest.extensions))
83
+ ctx.report("warning", "plugin_unknown_key", "extensions is an object of namespaces: it is not read", file, ["extensions"]);
84
+ else
85
+ for (const namespace of Object.keys(manifest.extensions))
86
+ ctx.report("note", "plugin_part_ignored", `The extension namespace '${namespace}' is not run by Nylorun`, file, ["extensions", namespace], { key: true });
87
+ }
88
+ if (!valid)
89
+ 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.
92
+ const mcpFile = paths.includes("mcp.json") ? "mcp.json" : paths.includes(".mcp.json") ? ".mcp.json" : undefined;
93
+ if (mcpFile === "mcp.json" && paths.includes(".mcp.json"))
94
+ ctx.report("note", "plugin_part_ignored", "Claude Code's server file is not read: the plugin's mcp.json is", `${prefix}.mcp.json`);
95
+ if (mcpFile === "mcp.json") {
96
+ 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", []),
100
+ });
101
+ }
102
+ // Its skills and servers, read as an agent's own by the compiler itself, inside a wrapper.
103
+ const entries = [{ path: "AGENT.md", size: WRAPPER.byteLength, sha256: "0".repeat(64) }];
104
+ const files = new Map([["AGENT.md", WRAPPER]]);
105
+ const real = (path) => (path === "mcp.json" && mcpFile ? prefix + mcpFile : prefix + path);
106
+ const take = (inner, path) => {
107
+ const entry = ctx.entries.get(prefix + path);
108
+ if (!entry)
109
+ return;
110
+ entries.push({ ...entry, path: inner });
111
+ const bytes = ctx.files.get(prefix + path);
112
+ if (bytes)
113
+ files.set(inner, bytes);
114
+ };
115
+ if (mcpFile)
116
+ take("mcp.json", mcpFile);
117
+ for (const path of paths)
118
+ if (path.startsWith("skills/") || (!READ.has(path.split("/")[0]) && isSecretShaped(path.split("/").at(-1))))
119
+ take(path, path);
120
+ const result = ctx.compile({ entries, files }, {
121
+ role: "plugin",
122
+ deriveSlot: (credential, type, url, at, position, header) => ctx.deriveSlot(credential, type, url, real(at), [], header, position),
123
+ schema: () => ({ code: "schema_invalid", message: "A plugin's skills and servers name no schema files" }),
124
+ });
125
+ addInner(ctx, prefix, result.diagnostics.filter((item) => item.file !== "AGENT.md"), real);
126
+ const harness = result.manifest?.harness;
127
+ if (!harness)
128
+ return;
129
+ for (const [key, server] of Object.entries(harness.mcpServers ?? {})) {
130
+ const at = real("mcp.json");
131
+ const other = folded.servers.get(key);
132
+ if (other) {
133
+ error("plugin_duplicate", `MCP server ${key} is also in ${other.file}: an agent has one server of a name`, at, ["mcpServers", key], true);
134
+ continue;
135
+ }
136
+ folded.servers.set(key, { server: { ...server, plugin: label }, file: at });
137
+ }
138
+ for (const [key, skill] of Object.entries(harness.skills ?? {})) {
139
+ const at = `${prefix}skills/${key}/SKILL.md`;
140
+ const other = folded.skills.get(key);
141
+ if (other) {
142
+ error("plugin_duplicate", `Skill ${key} is also in ${other.file}: an agent has one skill of a name`, at);
143
+ continue;
144
+ }
145
+ folded.skills.set(key, { skill: { ...skill, plugin: label }, file: at });
146
+ }
147
+ }
148
+ /** An Agent Plugins name: 1-64 lowercase letters, digits, hyphens and periods (the SDK loader's rule). */
149
+ function isPluginName(value) {
150
+ if (typeof value !== "string" || value.length < 1 || value.length > 64)
151
+ return false;
152
+ if (value.length === 1)
153
+ return /^[a-z0-9]$/.test(value);
154
+ return /^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(value) && !value.includes("--") && !value.includes("..");
155
+ }
@@ -0,0 +1,8 @@
1
+ /** The kinds of file an agent folder has a JSON Schema document for. */
2
+ export declare const AGENT_FOLDER_SCHEMA_KINDS: readonly ["agent-md", "trigger-md", "runtime", "tool", "mcp", "flow"];
3
+ export type AgentFolderSchemaKind = (typeof AGENT_FOLDER_SCHEMA_KINDS)[number];
4
+ /**
5
+ * The JSON Schema document (2020-12) of each kind of file in an agent folder, by kind, as the
6
+ * build writes them (`dist/schemas/agent-folder/<kind>.schema.json`).
7
+ */
8
+ export declare function agentFolderJsonSchemas(): Record<AgentFolderSchemaKind, Record<string, unknown>>;