@nylorun/core 0.27.0-beta → 0.29.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.
- package/CHANGELOG.md +56 -0
- package/README.md +3 -1
- package/dist/compatibility.d.ts +7 -1
- package/dist/compatibility.js +8 -0
- package/dist/contracts.d.ts +212 -4
- package/dist/contracts.js +112 -10
- package/dist/define.d.ts +2 -1
- package/dist/define.js +2 -1
- package/dist/definition/cron.d.ts +15 -0
- package/dist/definition/cron.js +155 -0
- package/dist/definition/sections.d.ts +11 -0
- package/dist/definition/sections.js +29 -20
- package/dist/folder/compile.d.ts +43 -5
- package/dist/folder/compile.js +499 -88
- package/dist/folder/context.d.ts +97 -0
- package/dist/folder/context.js +79 -0
- package/dist/folder/decompile.d.ts +18 -0
- package/dist/folder/decompile.js +660 -0
- package/dist/folder/fix.d.ts +22 -0
- package/dist/folder/fix.js +191 -0
- package/dist/folder/flow.d.ts +42 -0
- package/dist/folder/flow.js +215 -0
- package/dist/folder/frontmatter.d.ts +5 -2
- package/dist/folder/frontmatter.js +8 -4
- package/dist/folder/index.d.ts +7 -2
- package/dist/folder/index.js +6 -1
- package/dist/folder/json-schema.d.ts +15 -0
- package/dist/folder/json-schema.js +212 -0
- package/dist/folder/nested.d.ts +24 -0
- package/dist/folder/nested.js +378 -0
- package/dist/folder/plugins.d.ts +23 -0
- package/dist/folder/plugins.js +155 -0
- package/dist/folder/schemas.d.ts +8 -0
- package/dist/folder/schemas.js +238 -0
- package/dist/folder/suggest.d.ts +13 -0
- package/dist/folder/suggest.js +63 -0
- package/dist/schemas/agent-folder/agent-md.schema.json +143 -0
- package/dist/schemas/agent-folder/flow.schema.json +466 -0
- package/dist/schemas/agent-folder/mcp.schema.json +59 -0
- package/dist/schemas/agent-folder/runtime.schema.json +447 -0
- package/dist/schemas/agent-folder/tool.schema.json +77 -0
- package/dist/schemas/agent-folder/trigger-md.schema.json +65 -0
- package/dist/utils/runtime-limits.d.ts +8 -0
- package/dist/utils/runtime-limits.js +19 -0
- package/package.json +8 -2
|
@@ -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>>;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema document of each kind of file in an agent folder (track T7, design §3.10), so
|
|
3
|
+
* an editor checks and completes a folder's files as it is written, from the `json.schemas`
|
|
4
|
+
* mapping `nylorun init` writes. Each `$id` is `https://docs.nylorun.com/schemas/agent-folder/v1/
|
|
5
|
+
* <kind>.json`; the build writes them to `dist/schemas/agent-folder/`, exported as
|
|
6
|
+
* `@nylorun/core/schemas/agent-folder-<kind>.json`, and the docs site publishes each at its `$id`.
|
|
7
|
+
*
|
|
8
|
+
* - `runtime`, `tool`, `mcp` and `flow`: `runtime.json`, `tools/<name>.json`, `mcp.json` and
|
|
9
|
+
* `flow.json`, the `$schema` URLs the compiler takes (`SCHEMA_URLS`).
|
|
10
|
+
* - `agent-md` and `trigger-md`: the frontmatter of `AGENT.md` and of `triggers/<id>.md`.
|
|
11
|
+
*
|
|
12
|
+
* They are built from what the compiler checks, so they cannot drift from it: its key lists name
|
|
13
|
+
* each document's properties (a key left out or added is a type error here), and a value the
|
|
14
|
+
* manifest takes as it is comes from the manifest's own zod schema (`runtime.json` from
|
|
15
|
+
* `RuntimeSectionSchema`, `http` from `HttpToolTargetSchema`, `memory`, a trigger's fields). Where
|
|
16
|
+
* the compiler refuses an unknown key, so does the document; `loop` and `metadata` stay open. A
|
|
17
|
+
* document says less than the compiler only where JSON Schema cannot: that a path names a file of
|
|
18
|
+
* the folder, a cron, a time zone, which server or skill a name means.
|
|
19
|
+
*/
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { AGENT_MANIFEST_NAME_PATTERN, ENVIRONMENT_NAME_PATTERN, HarnessIdSchema, HarnessMemorySchema, HttpToolTargetSchema, McpToolSettingsSchema, RuntimeSectionSchema, TOOL_SECRET_NAME_PATTERN, TriggerSchema, } from "../contracts.js";
|
|
22
|
+
import { DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
|
|
23
|
+
import { AGENT_KEYS, FOLDER_SCHEMAS, MCP_KEYS, PLUGIN_SERVER_SETTING_KEYS, SERVER_KEYS, TOOL_KEYS, TRIGGER_KEYS, } from "./compile.js";
|
|
24
|
+
import { LOOP_KEYS, MAP_KEYS, NODE_KINDS, SWITCH_KEYS, VERIFY_KEYS } from "./flow.js";
|
|
25
|
+
/** The kinds of file an agent folder has a JSON Schema document for. */
|
|
26
|
+
export const AGENT_FOLDER_SCHEMA_KINDS = ["agent-md", "trigger-md", "runtime", "tool", "mcp", "flow"];
|
|
27
|
+
const DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
28
|
+
const ref = (name, description) => ({ $ref: `#/$defs/${name}`, ...(description ? { description } : {}) });
|
|
29
|
+
/** A map whose keys are names matching `pattern`, each value `value`. */
|
|
30
|
+
const namedMap = (pattern, value, description) => ({
|
|
31
|
+
type: "object",
|
|
32
|
+
...(pattern ? { propertyNames: { pattern: pattern.source } } : {}),
|
|
33
|
+
additionalProperties: value,
|
|
34
|
+
description,
|
|
35
|
+
});
|
|
36
|
+
const SCHEMA_KEY = { type: "string", description: "This file's JSON Schema, for editors; the compiler leaves it out of the manifest" };
|
|
37
|
+
/**
|
|
38
|
+
* A zod schema as JSON Schema (its input), without `$schema`, its `$defs` moved into `defs` so a
|
|
39
|
+
* `$ref` in it still resolves once it sits inside a document.
|
|
40
|
+
*/
|
|
41
|
+
function fromZod(schema, defs, description) {
|
|
42
|
+
const { $schema: _, $defs, ...definition } = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
|
|
43
|
+
for (const [name, def] of Object.entries(($defs ?? {}))) {
|
|
44
|
+
if (name in defs && JSON.stringify(defs[name]) !== JSON.stringify(def))
|
|
45
|
+
throw new Error(`Two schemas are named ${name} in one document`);
|
|
46
|
+
defs[name] = def;
|
|
47
|
+
}
|
|
48
|
+
return description ? { ...definition, description } : definition;
|
|
49
|
+
}
|
|
50
|
+
/** One document: its `$id` from its kind, then the body, then the `$defs` its parts named. */
|
|
51
|
+
function document(kind, title, description, body, defs) {
|
|
52
|
+
return {
|
|
53
|
+
$schema: DIALECT,
|
|
54
|
+
$id: `${FOLDER_SCHEMAS}${kind}.json`,
|
|
55
|
+
title,
|
|
56
|
+
description,
|
|
57
|
+
...body,
|
|
58
|
+
...(Object.keys(defs).length === 0 ? {} : { $defs: defs }),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** `inputSchema` and `outputSchema`: a JSON Schema inline, or the path of a schema file. */
|
|
62
|
+
const JSON_SCHEMA_OR_PATH = {
|
|
63
|
+
anyOf: [
|
|
64
|
+
{
|
|
65
|
+
type: "string",
|
|
66
|
+
pattern: "\\.json$",
|
|
67
|
+
description: "The path of a JSON Schema file in the folder (./output.schema.json; /schemas/x.json from the uploaded folder's root), named *.schema.json or kept under schemas/",
|
|
68
|
+
},
|
|
69
|
+
{ type: "object", description: "A JSON Schema (2020-12), inline" },
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
function agentMd() {
|
|
73
|
+
const defs = { JsonSchemaOrPath: JSON_SCHEMA_OR_PATH };
|
|
74
|
+
const serverSettings = {
|
|
75
|
+
deferred: { type: "boolean", description: "Offer the server's tools on demand, by search, instead of in every turn" },
|
|
76
|
+
tools: namedMap(undefined, fromZod(McpToolSettingsSchema.omit({ approval: true }), defs), "Settings for each of the server's tools by name, \"*\" for the rest; approval is the Tenant's tool policy, not set here"),
|
|
77
|
+
credential: {
|
|
78
|
+
type: "string",
|
|
79
|
+
pattern: TOOL_SECRET_NAME_PATTERN.source,
|
|
80
|
+
description: "The secret slot a plugin's server authenticates with, which the plugin cannot name; a server of mcp.json names it in a header",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
defs.McpServerSettings = { type: "object", properties: serverSettings, additionalProperties: false };
|
|
84
|
+
const properties = {
|
|
85
|
+
name: { type: "string", pattern: AGENT_MANIFEST_NAME_PATTERN.source, description: "The agent manifest's name, the folder's when it is saved under one" },
|
|
86
|
+
description: { type: "string", minLength: 1, description: "What the agent does, in a sentence" },
|
|
87
|
+
format: { const: 1, description: "The folder's format: 1 (agent-folder/1), the default" },
|
|
88
|
+
harness: fromZod(HarnessIdSchema, defs, "The harness that runs the loop: nylorun (ours, the default) or a custom harness's id"),
|
|
89
|
+
inputSchema: ref("JsonSchemaOrPath", "A flow's input (a folder with flow.json); an agent's input is the message"),
|
|
90
|
+
outputSchema: ref("JsonSchemaOrPath", "The JSON Schema of the agent's final answer"),
|
|
91
|
+
mcpServers: namedMap(DELEGATE_NAME_PATTERN, ref("McpServerSettings"), "How this agent uses each MCP server of mcp.json or a plugin, by its name"),
|
|
92
|
+
skills: namedMap(undefined, {
|
|
93
|
+
type: "object",
|
|
94
|
+
properties: {
|
|
95
|
+
secrets: {
|
|
96
|
+
type: "array",
|
|
97
|
+
items: { type: "string", pattern: ENVIRONMENT_NAME_PATTERN.source },
|
|
98
|
+
description: "The secret slots the skill's scripts read, as environment variables",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
}, "This agent's settings for each skill of skills/ or a plugin, by its name"),
|
|
103
|
+
memory: fromZod(HarnessMemorySchema, defs, "The Agent's memory: Markdown files under /memories it keeps across sessions"),
|
|
104
|
+
loop: { type: "object", description: "The harness's own settings, passed to it each turn; the nylorun harness reads none yet" },
|
|
105
|
+
metadata: { type: "object", description: "The manifest's metadata, as it is" },
|
|
106
|
+
};
|
|
107
|
+
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);
|
|
108
|
+
}
|
|
109
|
+
/** A trigger has exactly one of schedule, at and webhook (`TriggerSchema` refines it), and timezone goes with schedule. */
|
|
110
|
+
const ONE_TRIGGER_KIND = [
|
|
111
|
+
{ required: ["schedule"] },
|
|
112
|
+
{ required: ["at"], properties: { timezone: false } },
|
|
113
|
+
{ required: ["webhook"], properties: { timezone: false } },
|
|
114
|
+
];
|
|
115
|
+
function triggerMd() {
|
|
116
|
+
const defs = {};
|
|
117
|
+
const fields = TriggerSchema.shape;
|
|
118
|
+
const properties = {
|
|
119
|
+
schedule: fromZod(fields.schedule, defs, "Five cron fields: minute hour day-of-month month day-of-week, in timezone"),
|
|
120
|
+
timezone: fromZod(fields.timezone, defs, "The schedule's IANA time zone, such as Asia/Kolkata; UTC without one"),
|
|
121
|
+
at: fromZod(fields.at, defs, "One run, at an RFC 3339 time with an offset"),
|
|
122
|
+
webhook: fromZod(fields.webhook, defs, "A webhook endpoint, verified with this signature scheme"),
|
|
123
|
+
session: fromZod(fields.session, defs, "The session each run goes to: a session id, or new for a new one per run"),
|
|
124
|
+
};
|
|
125
|
+
return document("trigger-md", "Nylorun agent folder: trigger frontmatter", "The frontmatter of a trigger of an agent folder, triggers/<id>.md: exactly one of schedule, at and webhook, and the session; the body below it is the prompt", {
|
|
126
|
+
type: "object",
|
|
127
|
+
properties,
|
|
128
|
+
required: ["session"],
|
|
129
|
+
additionalProperties: false,
|
|
130
|
+
oneOf: ONE_TRIGGER_KIND,
|
|
131
|
+
}, defs);
|
|
132
|
+
}
|
|
133
|
+
function runtime() {
|
|
134
|
+
const defs = {};
|
|
135
|
+
const file = RuntimeSectionSchema.extend({ kind: RuntimeSectionSchema.shape.kind.optional() });
|
|
136
|
+
const { properties, required, ...section } = fromZod(file, defs);
|
|
137
|
+
// runtime.json's triggers are the manifest's, with what TriggerSchema refines.
|
|
138
|
+
if (typeof defs.Trigger !== "object")
|
|
139
|
+
throw new Error("runtime.json's schema has no Trigger");
|
|
140
|
+
defs.Trigger = { ...defs.Trigger, oneOf: ONE_TRIGGER_KIND };
|
|
141
|
+
return document("runtime", "Nylorun agent folder: runtime.json", "An agent folder's runtime.json: the runtime section of the agent manifest. kind is required unless extends names a file that gives it", {
|
|
142
|
+
...section,
|
|
143
|
+
properties: {
|
|
144
|
+
$schema: SCHEMA_KEY,
|
|
145
|
+
extends: {
|
|
146
|
+
type: "string",
|
|
147
|
+
minLength: 1,
|
|
148
|
+
description: "The path of a shared runtime file, relative to this one, merged under it (this file's keys win: objects merge, arrays replace) by nylorun apply and packFolder before upload",
|
|
149
|
+
},
|
|
150
|
+
...properties,
|
|
151
|
+
},
|
|
152
|
+
...(required && required.length > 0 ? { required } : {}),
|
|
153
|
+
anyOf: [{ required: ["kind"] }, { required: ["extends"] }],
|
|
154
|
+
}, defs);
|
|
155
|
+
}
|
|
156
|
+
function tool() {
|
|
157
|
+
const defs = { JsonSchemaOrPath: JSON_SCHEMA_OR_PATH };
|
|
158
|
+
const properties = {
|
|
159
|
+
description: { type: "string", description: "What the tool does, for the model" },
|
|
160
|
+
inputSchema: ref("JsonSchemaOrPath", "The JSON Schema of the tool's input"),
|
|
161
|
+
outputSchema: ref("JsonSchemaOrPath", "The JSON Schema of the tool's output"),
|
|
162
|
+
http: fromZod(HttpToolTargetSchema, defs, "The request the tool makes; credential names the bearer slot it authenticates with"),
|
|
163
|
+
};
|
|
164
|
+
return document("tool", "Nylorun agent folder: tools/<name>.json", "An HTTP tool of an agent folder, tools/<name>.json: its file name is the tool's name", { type: "object", properties: { $schema: SCHEMA_KEY, ...properties }, required: ["inputSchema", "http"], additionalProperties: false }, defs);
|
|
165
|
+
}
|
|
166
|
+
function mcp() {
|
|
167
|
+
const server = {
|
|
168
|
+
type: { enum: ["streamable-http", "sse"], description: "The server's transport: the Runtime runs remote servers only" },
|
|
169
|
+
url: { type: "string", minLength: 1, pattern: "^(?!.*\\$\\{)", description: "The server's URL; a credential goes in a header, never here" },
|
|
170
|
+
headers: namedMap(undefined, { type: "string" }, 'Headers sent to the server. "Bearer ${NAME}" in Authorization, or "${NAME}" alone in another header, names the secret slot the server authenticates with'),
|
|
171
|
+
};
|
|
172
|
+
const properties = {
|
|
173
|
+
$schema: { ...SCHEMA_KEY, description: "This file's JSON Schema, for editors: ours, or Agent Plugins' MCP schema" },
|
|
174
|
+
mcpServers: namedMap(DELEGATE_NAME_PATTERN, ref("McpServer"), "The MCP servers, by name"),
|
|
175
|
+
};
|
|
176
|
+
return document("mcp", "Nylorun agent folder: mcp.json", "An agent folder's MCP servers, in Agent Plugins syntax", { type: "object", properties, required: ["mcpServers"], additionalProperties: false }, { McpServer: { type: "object", properties: server, required: ["type", "url"], additionalProperties: false } });
|
|
177
|
+
}
|
|
178
|
+
function flow() {
|
|
179
|
+
const node = ref("Node");
|
|
180
|
+
const id = { type: "string", minLength: 1, description: "The node's id, which names its step in a run" };
|
|
181
|
+
const leaf = (description) => ({ type: "string", minLength: 1, description });
|
|
182
|
+
const switchKeys = {
|
|
183
|
+
cases: namedMap(undefined, node, "The node each route runs, by route"),
|
|
184
|
+
default: { ...node, description: "The node that runs when no route matches" },
|
|
185
|
+
};
|
|
186
|
+
const loopKeys = {
|
|
187
|
+
run: { ...node, description: "The node each attempt runs" },
|
|
188
|
+
verify: ref("Verifier"),
|
|
189
|
+
max: { type: "integer", minimum: 1, description: "The most attempts the loop makes" },
|
|
190
|
+
};
|
|
191
|
+
const verifyKeys = {
|
|
192
|
+
agent: leaf("An agent of the flow root's agents/, by its id, that judges each attempt"),
|
|
193
|
+
tool: leaf("A tool of tools/ beside this flow.json, by its name, that judges each attempt"),
|
|
194
|
+
id,
|
|
195
|
+
};
|
|
196
|
+
const bodies = {
|
|
197
|
+
agent: leaf("An agent of the flow root's agents/, by its id"),
|
|
198
|
+
tool: leaf("A tool of tools/ beside this flow.json, by its name (tools/<name>.json)"),
|
|
199
|
+
chain: { type: "array", items: node, minItems: 1, description: "Nodes run in order, each given the one before's output" },
|
|
200
|
+
switch: { type: "object", properties: switchKeys, required: ["cases"], additionalProperties: false, description: "Runs the node of the route the input names" },
|
|
201
|
+
parallel: { type: "object", additionalProperties: node, minProperties: 1, description: "Runs each branch's node at once, by branch name" },
|
|
202
|
+
map: { type: "object", properties: { each: node }, required: ["each"], additionalProperties: false, description: "Runs the node once per item of its input" },
|
|
203
|
+
loop: { type: "object", properties: loopKeys, required: ["run", "verify", "max"], additionalProperties: false, description: "Runs a node until verify passes it, up to max attempts" },
|
|
204
|
+
};
|
|
205
|
+
const pascal = (kind) => `${kind[0].toUpperCase()}${kind.slice(1)}Node`;
|
|
206
|
+
const defs = {
|
|
207
|
+
Node: { oneOf: NODE_KINDS.map((kind) => ref(pascal(kind))), description: `A node: exactly one of ${NODE_KINDS.join(", ")}, and an optional id` },
|
|
208
|
+
};
|
|
209
|
+
for (const kind of NODE_KINDS)
|
|
210
|
+
defs[pascal(kind)] = { type: "object", properties: { [kind]: bodies[kind], id }, required: [kind], additionalProperties: false };
|
|
211
|
+
// The file's own node may also name this schema; a node inside it may not.
|
|
212
|
+
const root = {
|
|
213
|
+
oneOf: NODE_KINDS.map((kind) => ({ type: "object", properties: { $schema: SCHEMA_KEY, [kind]: bodies[kind], id }, required: [kind], additionalProperties: false })),
|
|
214
|
+
};
|
|
215
|
+
defs.Verifier = {
|
|
216
|
+
oneOf: [
|
|
217
|
+
{ type: "object", properties: { agent: verifyKeys.agent, id: verifyKeys.id }, required: ["agent"], additionalProperties: false },
|
|
218
|
+
{ type: "object", properties: { tool: verifyKeys.tool }, required: ["tool"], additionalProperties: false },
|
|
219
|
+
],
|
|
220
|
+
description: "What judges each attempt: an agent, or an HTTP tool",
|
|
221
|
+
};
|
|
222
|
+
return document("flow", "Nylorun agent folder: flow.json", "A flow's node tree (workflow manifest v3's), naming agents of the flow root's agents/ by id and tools beside the file by name", root, defs);
|
|
223
|
+
}
|
|
224
|
+
const BUILD = {
|
|
225
|
+
"agent-md": agentMd,
|
|
226
|
+
"trigger-md": triggerMd,
|
|
227
|
+
runtime,
|
|
228
|
+
tool,
|
|
229
|
+
mcp,
|
|
230
|
+
flow,
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* The JSON Schema document (2020-12) of each kind of file in an agent folder, by kind, as the
|
|
234
|
+
* build writes them (`dist/schemas/agent-folder/<kind>.schema.json`).
|
|
235
|
+
*/
|
|
236
|
+
export function agentFolderJsonSchemas() {
|
|
237
|
+
return Object.fromEntries(AGENT_FOLDER_SCHEMA_KINDS.map((kind) => [kind, BUILD[kind]()]));
|
|
238
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** "Did you mean": the closest of `known` to `name`, when one is close enough to be a typo. */
|
|
2
|
+
export declare function suggestion(name: string, known: readonly string[]): string | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Every one of `known` closest to `name`, when close enough to be a typo, in `known`'s order. A
|
|
5
|
+
* fix-it renames only when there is one: with two, which was meant is the author's call.
|
|
6
|
+
*/
|
|
7
|
+
export declare function suggestions(name: string, known: readonly string[]): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Compares two strings with their runs of digits as numbers, so `2-style.md` comes before
|
|
10
|
+
* `10-voice.md`. Equal numbers with different zero padding, and everything else, fall back to
|
|
11
|
+
* UTF-16 order, so the order is total and the same on every platform.
|
|
12
|
+
*/
|
|
13
|
+
export declare function naturalCompare(a: string, b: string): number;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** "Did you mean": the closest of `known` to `name`, when one is close enough to be a typo. */
|
|
2
|
+
export function suggestion(name, known) {
|
|
3
|
+
return suggestions(name, known)[0];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Every one of `known` closest to `name`, when close enough to be a typo, in `known`'s order. A
|
|
7
|
+
* fix-it renames only when there is one: with two, which was meant is the author's call.
|
|
8
|
+
*/
|
|
9
|
+
export function suggestions(name, known) {
|
|
10
|
+
let best;
|
|
11
|
+
for (const candidate of new Set(known)) {
|
|
12
|
+
const distance = editDistance(name.toLowerCase(), candidate.toLowerCase());
|
|
13
|
+
if (distance > Math.max(2, Math.floor(candidate.length / 3)))
|
|
14
|
+
continue;
|
|
15
|
+
if (!best || distance < best.distance)
|
|
16
|
+
best = { values: [candidate], distance };
|
|
17
|
+
else if (distance === best.distance)
|
|
18
|
+
best.values.push(candidate);
|
|
19
|
+
}
|
|
20
|
+
return best?.values ?? [];
|
|
21
|
+
}
|
|
22
|
+
function editDistance(a, b) {
|
|
23
|
+
const row = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
24
|
+
for (let i = 1; i <= a.length; i++) {
|
|
25
|
+
let previous = row[0];
|
|
26
|
+
row[0] = i;
|
|
27
|
+
for (let j = 1; j <= b.length; j++) {
|
|
28
|
+
const current = row[j];
|
|
29
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
30
|
+
previous = current;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return row[b.length];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Compares two strings with their runs of digits as numbers, so `2-style.md` comes before
|
|
37
|
+
* `10-voice.md`. Equal numbers with different zero padding, and everything else, fall back to
|
|
38
|
+
* UTF-16 order, so the order is total and the same on every platform.
|
|
39
|
+
*/
|
|
40
|
+
export function naturalCompare(a, b) {
|
|
41
|
+
const chunks = /(\d+|\D+)/g;
|
|
42
|
+
const left = a.match(chunks) ?? [];
|
|
43
|
+
const right = b.match(chunks) ?? [];
|
|
44
|
+
for (let index = 0; index < Math.min(left.length, right.length); index++) {
|
|
45
|
+
const x = left[index];
|
|
46
|
+
const y = right[index];
|
|
47
|
+
if (x === y)
|
|
48
|
+
continue;
|
|
49
|
+
if (/^\d/.test(x) && /^\d/.test(y)) {
|
|
50
|
+
const p = x.replace(/^0+(?=\d)/, "");
|
|
51
|
+
const q = y.replace(/^0+(?=\d)/, "");
|
|
52
|
+
if (p.length !== q.length)
|
|
53
|
+
return p.length - q.length;
|
|
54
|
+
if (p !== q)
|
|
55
|
+
return p < q ? -1 : 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
return x < y ? -1 : 1;
|
|
59
|
+
}
|
|
60
|
+
if (left.length !== right.length)
|
|
61
|
+
return left.length - right.length;
|
|
62
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
63
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://docs.nylorun.com/schemas/agent-folder/v1/agent-md.json",
|
|
4
|
+
"title": "Nylorun agent folder: AGENT.md frontmatter",
|
|
5
|
+
"description": "The frontmatter of an agent folder's AGENT.md; the body below it is the instructions",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$",
|
|
11
|
+
"description": "The agent manifest's name, the folder's when it is saved under one"
|
|
12
|
+
},
|
|
13
|
+
"description": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1,
|
|
16
|
+
"description": "What the agent does, in a sentence"
|
|
17
|
+
},
|
|
18
|
+
"format": {
|
|
19
|
+
"const": 1,
|
|
20
|
+
"description": "The folder's format: 1 (agent-folder/1), the default"
|
|
21
|
+
},
|
|
22
|
+
"harness": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^[a-z][a-z0-9-]{1,62}$",
|
|
25
|
+
"description": "The harness that runs the loop: nylorun (ours, the default) or a custom harness's id"
|
|
26
|
+
},
|
|
27
|
+
"inputSchema": {
|
|
28
|
+
"$ref": "#/$defs/JsonSchemaOrPath",
|
|
29
|
+
"description": "A flow's input (a folder with flow.json); an agent's input is the message"
|
|
30
|
+
},
|
|
31
|
+
"outputSchema": {
|
|
32
|
+
"$ref": "#/$defs/JsonSchemaOrPath",
|
|
33
|
+
"description": "The JSON Schema of the agent's final answer"
|
|
34
|
+
},
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"propertyNames": {
|
|
38
|
+
"pattern": "^[A-Za-z0-9_-]{1,64}$"
|
|
39
|
+
},
|
|
40
|
+
"additionalProperties": {
|
|
41
|
+
"$ref": "#/$defs/McpServerSettings"
|
|
42
|
+
},
|
|
43
|
+
"description": "How this agent uses each MCP server of mcp.json or a plugin, by its name"
|
|
44
|
+
},
|
|
45
|
+
"skills": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"properties": {
|
|
50
|
+
"secrets": {
|
|
51
|
+
"type": "array",
|
|
52
|
+
"items": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
|
|
55
|
+
},
|
|
56
|
+
"description": "The secret slots the skill's scripts read, as environment variables"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"additionalProperties": false
|
|
60
|
+
},
|
|
61
|
+
"description": "This agent's settings for each skill of skills/ or a plugin, by its name"
|
|
62
|
+
},
|
|
63
|
+
"memory": {
|
|
64
|
+
"type": "object",
|
|
65
|
+
"properties": {
|
|
66
|
+
"access": {
|
|
67
|
+
"description": "`read_write` (the default) or `read_only`",
|
|
68
|
+
"type": "string",
|
|
69
|
+
"enum": [
|
|
70
|
+
"read_write",
|
|
71
|
+
"read_only"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"instructions": {
|
|
75
|
+
"description": "What this agent should remember, after the engine's own memory rules",
|
|
76
|
+
"type": "string",
|
|
77
|
+
"maxLength": 4096
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"description": "The Agent's memory: Markdown files under /memories it keeps across sessions"
|
|
82
|
+
},
|
|
83
|
+
"loop": {
|
|
84
|
+
"type": "object",
|
|
85
|
+
"description": "The harness's own settings, passed to it each turn; the nylorun harness reads none yet"
|
|
86
|
+
},
|
|
87
|
+
"metadata": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"description": "The manifest's metadata, as it is"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"required": [
|
|
93
|
+
"name",
|
|
94
|
+
"description"
|
|
95
|
+
],
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"$defs": {
|
|
98
|
+
"JsonSchemaOrPath": {
|
|
99
|
+
"anyOf": [
|
|
100
|
+
{
|
|
101
|
+
"type": "string",
|
|
102
|
+
"pattern": "\\.json$",
|
|
103
|
+
"description": "The path of a JSON Schema file in the folder (./output.schema.json; /schemas/x.json from the uploaded folder's root), named *.schema.json or kept under schemas/"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "object",
|
|
107
|
+
"description": "A JSON Schema (2020-12), inline"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
"McpServerSettings": {
|
|
112
|
+
"type": "object",
|
|
113
|
+
"properties": {
|
|
114
|
+
"deferred": {
|
|
115
|
+
"type": "boolean",
|
|
116
|
+
"description": "Offer the server's tools on demand, by search, instead of in every turn"
|
|
117
|
+
},
|
|
118
|
+
"tools": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"additionalProperties": {
|
|
121
|
+
"type": "object",
|
|
122
|
+
"properties": {
|
|
123
|
+
"enabled": {
|
|
124
|
+
"type": "boolean"
|
|
125
|
+
},
|
|
126
|
+
"deferred": {
|
|
127
|
+
"type": "boolean"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"additionalProperties": false
|
|
131
|
+
},
|
|
132
|
+
"description": "Settings for each of the server's tools by name, \"*\" for the rest; approval is the Tenant's tool policy, not set here"
|
|
133
|
+
},
|
|
134
|
+
"credential": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"pattern": "^[A-Za-z0-9._-]{1,64}$",
|
|
137
|
+
"description": "The secret slot a plugin's server authenticates with, which the plugin cannot name; a server of mcp.json names it in a header"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"additionalProperties": false
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|