@nylorun/core 0.51.0-beta → 0.53.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/contracts.js +5 -2
- package/dist/definition/assemble.js +5 -2
- package/dist/definition/builder.js +2 -2
- package/dist/definition/code-tools.js +1 -1
- package/dist/definition/delegate.d.ts +9 -0
- package/dist/definition/delegate.js +37 -0
- package/dist/definition/flow/compile.js +5 -5
- package/dist/definition/flow/from.js +1 -1
- package/dist/folder/compile.d.ts +1 -1
- package/dist/folder/compile.js +94 -7
- package/dist/folder/engine.d.ts +6 -0
- package/dist/folder/index.d.ts +2 -0
- package/dist/folder/index.js +2 -0
- package/dist/folder/migrate-v4.d.ts +33 -0
- package/dist/folder/migrate-v4.js +207 -0
- package/dist/folder/nested.js +19 -9
- package/dist/folder/schemas.js +25 -5
- package/dist/folder/subagent-files.d.ts +106 -0
- package/dist/folder/subagent-files.js +440 -0
- package/dist/schemas/agent-folder/agent-md.schema.json +67 -18
- package/package.json +1 -1
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { parseMarkdown } from "./frontmatter.js";
|
|
2
|
+
import { PLUGIN_NAMES, pluginOfTool, pluginTools, RUNTIME_SERVER } from "../plugins/index.js";
|
|
3
|
+
import { suggestion } from "./suggest.js";
|
|
4
|
+
/** The format name a v4 folder writes. */
|
|
5
|
+
export const AGENT_FOLDER_V4 = "agent-folder/4";
|
|
6
|
+
/** Whether `value` names the v4 format: `agent-folder/4` or `4`. */
|
|
7
|
+
export function isFolderV4(value) {
|
|
8
|
+
return value === 4 || value === AGENT_FOLDER_V4;
|
|
9
|
+
}
|
|
10
|
+
/** The keys a subagent file adds to `AGENT.md`'s, and the root's in format 4. */
|
|
11
|
+
export const SUBAGENT_FILE_KEYS = ["tools", "disallowedTools", "flow", "readonly"];
|
|
12
|
+
/** The root's own narrowing keys in format 4. */
|
|
13
|
+
export const ROOT_V4_KEYS = ["tools", "disallowedTools"];
|
|
14
|
+
/**
|
|
15
|
+
* Keys Claude Code and Cursor write that mean nothing here: noted and ignored, so their files drop
|
|
16
|
+
* in. `memory` is one only as a string (Claude Code's `user`, `project` or `local`).
|
|
17
|
+
*/
|
|
18
|
+
export const HOST_KEYS = [
|
|
19
|
+
"model",
|
|
20
|
+
"color",
|
|
21
|
+
"permissionMode",
|
|
22
|
+
"hooks",
|
|
23
|
+
"maxTurns",
|
|
24
|
+
"background",
|
|
25
|
+
"isolation",
|
|
26
|
+
"effort",
|
|
27
|
+
"initialPrompt",
|
|
28
|
+
"omitClaudeMd",
|
|
29
|
+
"autoCompactWindow",
|
|
30
|
+
"experimental",
|
|
31
|
+
"is_background",
|
|
32
|
+
];
|
|
33
|
+
/** Claude Code's tool names that are ours under another spelling. */
|
|
34
|
+
export const CLAUDE_TOOL_ALIASES = { Read: "read", Grep: "grep", Glob: "glob", Write: "write", Edit: "edit", Bash: "bash" };
|
|
35
|
+
/** Claude Code's other tool names: noted and ignored. */
|
|
36
|
+
const CLAUDE_TOOLS = ["WebFetch", "WebSearch", "Agent", "Task", "Skill", "TodoWrite", "NotebookEdit", "NotebookRead", "MultiEdit", "LS", "BashOutput", "KillShell", "KillBash", "ExitPlanMode", "SlashCommand", "ListMcpResourcesTool", "ReadMcpResourceTool"];
|
|
37
|
+
/** The Runtime plugins only the root agent uses: a subagent never inherits them, and names their tools only with an error. */
|
|
38
|
+
export const ROOT_ONLY_PLUGINS = ["nylorun-triggers", "nylorun-plan", "nylorun-interactions"];
|
|
39
|
+
/** The Runtime plugin a subagent inherits only when it names its tool. */
|
|
40
|
+
const NAMED_ONLY_PLUGINS = ["nylorun-memory"];
|
|
41
|
+
const READONLY_TOOLS = ["read", "grep", "glob"];
|
|
42
|
+
const AGENT_FILE = "AGENT.md";
|
|
43
|
+
const FLOW_FILE = "flow.json";
|
|
44
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
45
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
46
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
47
|
+
function textOf(bytes) {
|
|
48
|
+
if (!bytes)
|
|
49
|
+
return undefined;
|
|
50
|
+
try {
|
|
51
|
+
return decoder.decode(bytes).replace(/^/, "");
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function frontOf(bytes) {
|
|
58
|
+
const text = textOf(bytes);
|
|
59
|
+
if (text === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
const result = parseMarkdown(text);
|
|
62
|
+
return result.ok ? result.data : undefined;
|
|
63
|
+
}
|
|
64
|
+
function jsonOf(bytes) {
|
|
65
|
+
const text = textOf(bytes);
|
|
66
|
+
if (text === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(text);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Whether the uploaded folder's `AGENT.md` names format 4, read quietly. */
|
|
76
|
+
export function folderIsV4(input) {
|
|
77
|
+
return isFolderV4(frontOf(input.files.get(AGENT_FILE))?.format);
|
|
78
|
+
}
|
|
79
|
+
/** A subagent file's id from its path, or undefined: `agents/<id>.md`. */
|
|
80
|
+
export function subagentFileId(path) {
|
|
81
|
+
const match = /^agents\/([^/]+)\.md$/.exec(path);
|
|
82
|
+
return match?.[1];
|
|
83
|
+
}
|
|
84
|
+
/** The path `flow:` names, from the file at `agents/<id>.md`: `./x` and `x` from `agents/`, `/x` from the root. */
|
|
85
|
+
export function flowPathOf(value) {
|
|
86
|
+
if (typeof value !== "string" || value === "")
|
|
87
|
+
return undefined;
|
|
88
|
+
const target = value.startsWith("/") ? value.slice(1) : `agents/${value.replace(/^\.\//, "")}`;
|
|
89
|
+
return target.split("/").some((segment) => segment === "" || segment === "." || segment === "..") ? undefined : target;
|
|
90
|
+
}
|
|
91
|
+
/** The ids a flow's nodes name as `agent` and the names they name as `tool`. */
|
|
92
|
+
function flowNames(tree) {
|
|
93
|
+
const agents = new Set();
|
|
94
|
+
const tools = new Set();
|
|
95
|
+
const walk = (value) => {
|
|
96
|
+
if (Array.isArray(value))
|
|
97
|
+
value.forEach(walk);
|
|
98
|
+
else if (isObject(value)) {
|
|
99
|
+
if (typeof value.agent === "string")
|
|
100
|
+
agents.add(value.agent);
|
|
101
|
+
if (typeof value.tool === "string")
|
|
102
|
+
tools.add(value.tool);
|
|
103
|
+
Object.values(value).forEach(walk);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
walk(tree);
|
|
107
|
+
return { agents, tools };
|
|
108
|
+
}
|
|
109
|
+
const isLibrary = (path) => path === "mcp.json" || /^(tools|skills|plugins)\//.test(path);
|
|
110
|
+
/**
|
|
111
|
+
* Compiles a format 4 folder: expands its subagent files, compiles the result as `compile` does a
|
|
112
|
+
* format 3 folder, and moves each diagnostic back to the file people wrote.
|
|
113
|
+
*/
|
|
114
|
+
export function compileFormat4(input, compile) {
|
|
115
|
+
const byPath = new Map(input.entries.map((entry) => [entry.path, entry]));
|
|
116
|
+
const library = input.entries.filter((entry) => isLibrary(entry.path));
|
|
117
|
+
const ids = input.entries.map((entry) => subagentFileId(entry.path)).filter((id) => id !== undefined).sort(compare);
|
|
118
|
+
const fronts = new Map(ids.map((id) => [id, frontOf(input.files.get(`agents/${id}.md`)) ?? {}]));
|
|
119
|
+
const flowRoot = byPath.has(FLOW_FILE);
|
|
120
|
+
const entries = [];
|
|
121
|
+
const files = new Map(input.files);
|
|
122
|
+
const extra = [];
|
|
123
|
+
/** Where each subagent's flow file is, by id. */
|
|
124
|
+
const flows = new Map();
|
|
125
|
+
// A folder under agents/ is format 3's: refused, and left out of the expansion.
|
|
126
|
+
const folders = new Set();
|
|
127
|
+
for (const entry of input.entries) {
|
|
128
|
+
const segments = entry.path.split("/");
|
|
129
|
+
if (segments[0] === "agents" && segments.length >= 3) {
|
|
130
|
+
if (!folders.has(segments[1]))
|
|
131
|
+
extra.push({
|
|
132
|
+
severity: "error",
|
|
133
|
+
code: "subagent_folder",
|
|
134
|
+
message: `agents/${segments[1]}/ is a subagent folder, which agent-folder/4 writes as one file, agents/${segments[1]}.md, drawing on the manifest's tools/, skills/ and mcp.json. Fix: run nylorun migrate folder <dir> --to 4`,
|
|
135
|
+
file: `agents/${segments[1]}/${byPath.has(`agents/${segments[1]}/AGENT.md`) ? AGENT_FILE : segments.slice(2).join("/")}`,
|
|
136
|
+
});
|
|
137
|
+
folders.add(segments[1]);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
entries.push(entry);
|
|
141
|
+
}
|
|
142
|
+
const add = (path, source) => {
|
|
143
|
+
if (entries.some((entry) => entry.path === path))
|
|
144
|
+
return;
|
|
145
|
+
entries.push({ path, size: source.size, sha256: source.sha256 });
|
|
146
|
+
const bytes = input.files.get(source.path);
|
|
147
|
+
if (bytes)
|
|
148
|
+
files.set(path, bytes);
|
|
149
|
+
};
|
|
150
|
+
/** Expands one subagent file at `prefix` (`agents/<id>/`); `nested` is a flow subagent's own agents/ under a root driven by a model loop. */
|
|
151
|
+
const expand = (prefix, id, namespace) => {
|
|
152
|
+
const source = byPath.get(`agents/${id}.md`);
|
|
153
|
+
if (!source)
|
|
154
|
+
return;
|
|
155
|
+
add(`${prefix}${AGENT_FILE}`, source);
|
|
156
|
+
const front = fronts.get(id) ?? {};
|
|
157
|
+
if (front.flow === undefined) {
|
|
158
|
+
for (const entry of library)
|
|
159
|
+
add(prefix + entry.path, entry);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const flowPath = flowPathOf(front.flow);
|
|
163
|
+
const flowEntry = flowPath === undefined ? undefined : byPath.get(flowPath);
|
|
164
|
+
if (!flowEntry || !flowPath)
|
|
165
|
+
return;
|
|
166
|
+
flows.set(id, flowPath);
|
|
167
|
+
add(`${prefix}${FLOW_FILE}`, flowEntry);
|
|
168
|
+
const names = flowNames(jsonOf(input.files.get(flowPath)));
|
|
169
|
+
for (const tool of names.tools) {
|
|
170
|
+
const entry = byPath.get(`tools/${tool}.json`);
|
|
171
|
+
if (entry)
|
|
172
|
+
add(`${prefix}tools/${tool}.json`, entry);
|
|
173
|
+
}
|
|
174
|
+
// Its stages: the root's, when the root is a flow; else its own agents/, from the sibling files.
|
|
175
|
+
if (namespace === undefined)
|
|
176
|
+
return;
|
|
177
|
+
for (const stage of names.agents)
|
|
178
|
+
if (fronts.has(stage) && !entries.some((entry) => entry.path === `${namespace}${stage}/${AGENT_FILE}`))
|
|
179
|
+
expand(`${namespace}${stage}/`, stage, namespace);
|
|
180
|
+
};
|
|
181
|
+
for (const id of ids) {
|
|
182
|
+
const front = fronts.get(id) ?? {};
|
|
183
|
+
const prefix = `agents/${id}/`;
|
|
184
|
+
expand(prefix, id, front.flow !== undefined && !flowRoot ? `${prefix}agents/` : undefined);
|
|
185
|
+
}
|
|
186
|
+
const compiled = compile({ ...input, entries, files });
|
|
187
|
+
/** A path of the expansion, as the folder people wrote names it. */
|
|
188
|
+
const real = (path) => {
|
|
189
|
+
let rest = path;
|
|
190
|
+
let id;
|
|
191
|
+
for (;;) {
|
|
192
|
+
const match = /^agents\/([^/]+)\/(.*)$/.exec(rest);
|
|
193
|
+
if (!match || !fronts.has(match[1]))
|
|
194
|
+
break;
|
|
195
|
+
id = match[1];
|
|
196
|
+
rest = match[2];
|
|
197
|
+
}
|
|
198
|
+
if (id === undefined) {
|
|
199
|
+
const bare = /^agents\/([^/]+)$/.exec(path)?.[1];
|
|
200
|
+
return bare !== undefined && fronts.has(bare) ? `agents/${bare}.md` : path;
|
|
201
|
+
}
|
|
202
|
+
if (rest === AGENT_FILE || rest === "")
|
|
203
|
+
return `agents/${id}.md`;
|
|
204
|
+
if (rest === FLOW_FILE)
|
|
205
|
+
return flows.get(id) ?? `agents/${id}.md`;
|
|
206
|
+
return rest;
|
|
207
|
+
};
|
|
208
|
+
const seen = new Set();
|
|
209
|
+
const diagnostics = [];
|
|
210
|
+
for (const item of [...extra, ...compiled.diagnostics]) {
|
|
211
|
+
const moved = {
|
|
212
|
+
...item,
|
|
213
|
+
...(item.file === undefined ? {} : { file: real(item.file) }),
|
|
214
|
+
...(item.fix === undefined ? {} : { fix: { ...item.fix, file: real(item.fix.file) } }),
|
|
215
|
+
};
|
|
216
|
+
const key = JSON.stringify([moved.severity, moved.code, moved.message, moved.file, moved.line, moved.column]);
|
|
217
|
+
if (seen.has(key))
|
|
218
|
+
continue;
|
|
219
|
+
seen.add(key);
|
|
220
|
+
diagnostics.push(moved);
|
|
221
|
+
}
|
|
222
|
+
const order = { error: 0, warning: 1, info: 2, note: 3 };
|
|
223
|
+
diagnostics.sort((a, b) => order[a.severity] - order[b.severity] || compare(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0));
|
|
224
|
+
const failed = diagnostics.some((item) => item.severity === "error");
|
|
225
|
+
return { ...(failed || !compiled.manifest ? {} : { manifest: compiled.manifest }), diagnostics, compiler: AGENT_FOLDER_V4 };
|
|
226
|
+
}
|
|
227
|
+
/** A tool list as written: a YAML list, or a comma-separated string as Claude Code writes it. */
|
|
228
|
+
function namesOf(value) {
|
|
229
|
+
if (typeof value === "string")
|
|
230
|
+
return value
|
|
231
|
+
.split(",")
|
|
232
|
+
.map((name) => name.trim())
|
|
233
|
+
.filter((name) => name !== "")
|
|
234
|
+
.map((name) => ({ name, index: -1 }));
|
|
235
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string"))
|
|
236
|
+
return value.map((name, index) => ({ name: name.trim(), index }));
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Reads and strips the format 4 keys of `front` (a subagent file's, or a v4 root's), noting other
|
|
241
|
+
* hosts' keys, and writes the Runtime `plugins:` and `mcpServers.nylorun` its tools leave on, so the
|
|
242
|
+
* format 3 compiler that follows sees a folder it knows. Returns what it keeps of the rest.
|
|
243
|
+
*/
|
|
244
|
+
export function narrowFront(front, options) {
|
|
245
|
+
const { role, error, note } = options;
|
|
246
|
+
const subagent = role === "subagent";
|
|
247
|
+
if (subagent) {
|
|
248
|
+
for (const key of HOST_KEYS)
|
|
249
|
+
if (front[key] !== undefined) {
|
|
250
|
+
note("host_key", `${key} is a key other hosts write (Claude Code, Cursor), with no meaning here: ignored`, [key], { key: true });
|
|
251
|
+
delete front[key];
|
|
252
|
+
}
|
|
253
|
+
if (typeof front.memory === "string") {
|
|
254
|
+
note("host_key", "memory as a string is Claude Code's memory directory, with no meaning here: ignored. A subagent may view the Agent's memories when the root has them", ["memory"], { key: true });
|
|
255
|
+
delete front.memory;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const flow = subagent && front.flow !== undefined;
|
|
259
|
+
if (flow && typeof front.flow !== "string")
|
|
260
|
+
error("value_invalid", "flow is the path of the subagent's flow file, such as ./research.flow.json", ["flow"]);
|
|
261
|
+
if (flow)
|
|
262
|
+
for (const key of ["tools", "disallowedTools", "skills", "mcpServers", "readonly", "plugins"])
|
|
263
|
+
if (front[key] !== undefined)
|
|
264
|
+
error("flow_refused", `${key} belongs to a model loop: a subagent driven by a flow has none of its own, and its stages each have theirs`, [key], { key: true });
|
|
265
|
+
delete front.flow;
|
|
266
|
+
if (flow) {
|
|
267
|
+
for (const key of ["tools", "disallowedTools", "skills", "mcpServers", "readonly", "plugins"])
|
|
268
|
+
delete front[key];
|
|
269
|
+
return { httpDenied: new Set(), flow: true };
|
|
270
|
+
}
|
|
271
|
+
// The servers it names, before the Runtime's own (`nylorun`) is touched below: its allowlist.
|
|
272
|
+
const servers = subagent && isObject(front.mcpServers) ? Object.keys(front.mcpServers).filter((key) => key !== RUNTIME_SERVER) : undefined;
|
|
273
|
+
// tools and disallowedTools: HTTP tools and the Runtime plugins' tools, by name.
|
|
274
|
+
const known = [...new Set([...options.httpTools, ...options.plugins.flatMap((plugin) => plugin.tools)])];
|
|
275
|
+
const read = (key) => {
|
|
276
|
+
const value = front[key];
|
|
277
|
+
delete front[key];
|
|
278
|
+
if (value === undefined)
|
|
279
|
+
return undefined;
|
|
280
|
+
const names = namesOf(value);
|
|
281
|
+
if (!names) {
|
|
282
|
+
error("value_invalid", `${key} is a list of tool names, such as [read, grep, glob]`, [key]);
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
const kept = [];
|
|
286
|
+
for (const { name, index } of names) {
|
|
287
|
+
const at = index < 0 ? [key] : [key, index];
|
|
288
|
+
const alias = CLAUDE_TOOL_ALIASES[name];
|
|
289
|
+
if (alias !== undefined) {
|
|
290
|
+
note("tool_alias", `${name} is Claude Code's name for ${alias}: read as ${alias}. Fix: write ${alias}`, at);
|
|
291
|
+
if (known.includes(alias))
|
|
292
|
+
kept.push(alias);
|
|
293
|
+
else
|
|
294
|
+
error("library_unknown", `${alias} is not a tool this agent can have: its library holds ${known.join(", ") || "none"}`, at);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (CLAUDE_TOOLS.includes(name) || name.startsWith("mcp__")) {
|
|
298
|
+
note("host_key", `${name} is Claude Code's tool name, with no meaning here: ignored${name.startsWith("mcp__") ? ". An MCP server's tools are narrowed with mcpServers" : ""}`, at);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (!known.includes(name)) {
|
|
302
|
+
const close = suggestion(name, known);
|
|
303
|
+
error("library_unknown", `No tool ${name} is in the manifest's library (tools/ and the Runtime plugins it declares).${close ? ` Did you mean '${close}'?` : ""}`, at);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const plugin = pluginOfTool(name);
|
|
307
|
+
if (subagent && plugin && ROOT_ONLY_PLUGINS.includes(plugin)) {
|
|
308
|
+
error("library_unknown", `${name} is the root agent's (${plugin}): a subagent can't pause, set triggers or plan for the whole turn`, at);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
kept.push(name);
|
|
312
|
+
}
|
|
313
|
+
return kept;
|
|
314
|
+
};
|
|
315
|
+
let allowed = read("tools");
|
|
316
|
+
const denied = new Set(read("disallowedTools") ?? []);
|
|
317
|
+
if (subagent && front.readonly !== undefined) {
|
|
318
|
+
if (typeof front.readonly !== "boolean")
|
|
319
|
+
error("value_invalid", "readonly is true or false", ["readonly"]);
|
|
320
|
+
else if (front.readonly && allowed === undefined) {
|
|
321
|
+
note("host_key", "readonly: true is Cursor's: read as tools: [read, grep, glob]", ["readonly"], { key: true });
|
|
322
|
+
allowed = READONLY_TOOLS.filter((tool) => known.includes(tool));
|
|
323
|
+
}
|
|
324
|
+
else if (front.readonly)
|
|
325
|
+
note("host_key", "readonly: true is Cursor's, and tools already lists what this subagent gets: ignored", ["readonly"], { key: true });
|
|
326
|
+
}
|
|
327
|
+
delete front.readonly;
|
|
328
|
+
const keep = (tool) => (allowed === undefined || allowed.includes(tool)) && !denied.has(tool);
|
|
329
|
+
// The Runtime plugins: a subagent inherits its parent's, but the root's only, and memory only
|
|
330
|
+
// when it names it; the root keeps its own. Either keeps only the tools it allows.
|
|
331
|
+
if (subagent && front.plugins !== undefined)
|
|
332
|
+
error("value_invalid", "plugins is the root agent's: a subagent file gets the root's Runtime plugins, narrowed with tools", ["plugins"], { key: true });
|
|
333
|
+
const plugins = subagent
|
|
334
|
+
? options.plugins.filter((plugin) => !ROOT_ONLY_PLUGINS.includes(plugin.name) &&
|
|
335
|
+
(!NAMED_ONLY_PLUGINS.includes(plugin.name) || (allowed !== undefined && plugin.tools.some((tool) => allowed.includes(tool)))))
|
|
336
|
+
: options.plugins;
|
|
337
|
+
const on = plugins.filter((plugin) => plugin.tools.some(keep));
|
|
338
|
+
if (subagent) {
|
|
339
|
+
if (on.length > 0)
|
|
340
|
+
front.plugins = on.map((plugin) => plugin.name);
|
|
341
|
+
else
|
|
342
|
+
delete front.plugins;
|
|
343
|
+
}
|
|
344
|
+
const off = plugins.flatMap((plugin) => plugin.tools.filter((tool) => !keep(tool)));
|
|
345
|
+
if (off.length > 0) {
|
|
346
|
+
const servers = isObject(front.mcpServers) ? front.mcpServers : (front.mcpServers = {});
|
|
347
|
+
const settings = isObject(servers[RUNTIME_SERVER]) ? servers[RUNTIME_SERVER] : (servers[RUNTIME_SERVER] = {});
|
|
348
|
+
const tools = isObject(settings.tools) ? settings.tools : (settings.tools = {});
|
|
349
|
+
for (const tool of off)
|
|
350
|
+
if (on.some((plugin) => plugin.tools.includes(tool)) || !subagent)
|
|
351
|
+
tools[tool] = { enabled: false };
|
|
352
|
+
if (Object.keys(tools).length === 0)
|
|
353
|
+
delete servers[RUNTIME_SERVER];
|
|
354
|
+
if (Object.keys(servers).length === 0)
|
|
355
|
+
delete front.mcpServers;
|
|
356
|
+
}
|
|
357
|
+
const http = allowed === undefined ? undefined : new Set(allowed.filter((tool) => options.httpTools.includes(tool)));
|
|
358
|
+
const httpDenied = new Set([...denied].filter((tool) => options.httpTools.includes(tool)));
|
|
359
|
+
// skills: a list in a subagent file; the root's stays the map that gives skills secrets.
|
|
360
|
+
let skills;
|
|
361
|
+
if (subagent && front.skills !== undefined) {
|
|
362
|
+
const names = namesOf(front.skills);
|
|
363
|
+
if (!names)
|
|
364
|
+
error("value_invalid", "skills in a subagent file lists the library's skills it gets, by name: [checklist]. Only the root agent's skills get secrets", ["skills"]);
|
|
365
|
+
skills = names ?? [];
|
|
366
|
+
delete front.skills;
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
...(http === undefined ? {} : { http }),
|
|
370
|
+
httpDenied,
|
|
371
|
+
...(skills === undefined ? {} : { skills }),
|
|
372
|
+
...(servers === undefined ? {} : { servers }),
|
|
373
|
+
flow: false,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/** The root's skills with secrets and plugin servers it gives a credential, read from its frontmatter. */
|
|
377
|
+
export function rootSecretsOf(front) {
|
|
378
|
+
const skills = isObject(front.skills)
|
|
379
|
+
? Object.entries(front.skills)
|
|
380
|
+
.filter(([, value]) => isObject(value) && Array.isArray(value.secrets) && value.secrets.length > 0)
|
|
381
|
+
.map(([key]) => key)
|
|
382
|
+
: [];
|
|
383
|
+
const servers = isObject(front.mcpServers)
|
|
384
|
+
? Object.entries(front.mcpServers)
|
|
385
|
+
.filter(([, value]) => isObject(value) && value.credential !== undefined)
|
|
386
|
+
.map(([key]) => key)
|
|
387
|
+
: [];
|
|
388
|
+
return { skills, servers };
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Keeps, of the HTTP tools, skills and servers a subagent file inherited (or a v4 root holds),
|
|
392
|
+
* what its narrowing allows. A subagent also drops the root's skills with secrets and servers with
|
|
393
|
+
* a credential unless it names them, which then fail the checks that follow.
|
|
394
|
+
*/
|
|
395
|
+
export function narrowParts(harness, narrowing, options) {
|
|
396
|
+
if (narrowing.flow)
|
|
397
|
+
return;
|
|
398
|
+
if (Array.isArray(harness.tools)) {
|
|
399
|
+
const tools = harness.tools.filter((tool) => {
|
|
400
|
+
const name = String(tool.name);
|
|
401
|
+
if (tool.agent !== undefined)
|
|
402
|
+
return true;
|
|
403
|
+
return (narrowing.http === undefined || narrowing.http.has(name)) && !narrowing.httpDenied.has(name);
|
|
404
|
+
});
|
|
405
|
+
if (tools.length > 0)
|
|
406
|
+
harness.tools = tools;
|
|
407
|
+
else
|
|
408
|
+
delete harness.tools;
|
|
409
|
+
}
|
|
410
|
+
if (options.role !== "subagent")
|
|
411
|
+
return;
|
|
412
|
+
const skills = isObject(harness.skills) ? harness.skills : {};
|
|
413
|
+
if (narrowing.skills)
|
|
414
|
+
for (const { name, index } of narrowing.skills)
|
|
415
|
+
if (!(name in skills)) {
|
|
416
|
+
const close = suggestion(name, Object.keys(skills));
|
|
417
|
+
options.error("library_unknown", `No skill ${name} is in the manifest's library (skills/ and its plugins).${close ? ` Did you mean '${close}'?` : ""}`, ["skills", index]);
|
|
418
|
+
}
|
|
419
|
+
else if (options.secrets.skills.includes(name))
|
|
420
|
+
options.error("credential_unsupported", `Only the root agent's skills get secrets: ${name} gets them from the root's AGENT.md, so a subagent can't use it`, ["skills", index]);
|
|
421
|
+
for (const key of Object.keys(skills)) {
|
|
422
|
+
const named = narrowing.skills?.some((item) => item.name === key);
|
|
423
|
+
if ((narrowing.skills !== undefined && !named) || (!named && options.secrets.skills.includes(key)))
|
|
424
|
+
delete skills[key];
|
|
425
|
+
}
|
|
426
|
+
if (isObject(harness.skills) && Object.keys(skills).length === 0)
|
|
427
|
+
delete harness.skills;
|
|
428
|
+
const servers = isObject(harness.mcpServers) ? harness.mcpServers : {};
|
|
429
|
+
for (const [key, server] of Object.entries(servers)) {
|
|
430
|
+
const named = narrowing.servers?.includes(key) === true;
|
|
431
|
+
const secret = (isObject(server) && server.credential !== undefined) || options.secrets.servers.includes(key);
|
|
432
|
+
if (named && options.secrets.servers.includes(key))
|
|
433
|
+
options.error("credential_unsupported", `${key} authenticates with a credential the root's AGENT.md gives it, and a subagent's MCP servers take no credential: give the server to the root agent`, ["mcpServers", key]);
|
|
434
|
+
if ((narrowing.servers !== undefined && !named) || (!named && secret))
|
|
435
|
+
delete servers[key];
|
|
436
|
+
}
|
|
437
|
+
if (isObject(harness.mcpServers) && Object.keys(servers).length === 0)
|
|
438
|
+
delete harness.mcpServers;
|
|
439
|
+
}
|
|
440
|
+
export { PLUGIN_NAMES, pluginTools };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://docs.nylorun.com/schemas/agent-folder/v1/agent-md.
|
|
3
|
+
"$id": "https://docs.nylorun.com/schemas/agent-folder/v1/agent-md.6.json",
|
|
4
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",
|
|
5
|
+
"description": "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",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"name": {
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
1,
|
|
21
21
|
2,
|
|
22
22
|
3,
|
|
23
|
+
4,
|
|
23
24
|
"agent-folder/1",
|
|
24
25
|
"agent-folder/2",
|
|
25
|
-
"agent-folder/3"
|
|
26
|
+
"agent-folder/3",
|
|
27
|
+
"agent-folder/4"
|
|
26
28
|
],
|
|
27
|
-
"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;
|
|
29
|
+
"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"
|
|
28
30
|
},
|
|
29
31
|
"harness": {
|
|
30
32
|
"type": "string",
|
|
@@ -50,22 +52,33 @@
|
|
|
50
52
|
"description": "How this agent uses each MCP server of mcp.json or a plugin, by its name"
|
|
51
53
|
},
|
|
52
54
|
"skills": {
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
"anyOf": [
|
|
56
|
+
{
|
|
57
|
+
"type": "object",
|
|
58
|
+
"additionalProperties": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"properties": {
|
|
61
|
+
"secrets": {
|
|
62
|
+
"type": "array",
|
|
63
|
+
"items": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
|
|
66
|
+
},
|
|
67
|
+
"description": "The secret slots the skill's scripts read, as environment variables"
|
|
68
|
+
}
|
|
62
69
|
},
|
|
63
|
-
"
|
|
64
|
-
}
|
|
70
|
+
"additionalProperties": false
|
|
71
|
+
},
|
|
72
|
+
"description": "This agent's settings for each skill of skills/ or a plugin, by its name"
|
|
65
73
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
{
|
|
75
|
+
"type": "array",
|
|
76
|
+
"items": {
|
|
77
|
+
"type": "string"
|
|
78
|
+
},
|
|
79
|
+
"description": "agent-folder/4, a subagent file: the only skills of the manifest's library it gets, by name"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
69
82
|
},
|
|
70
83
|
"memory": {
|
|
71
84
|
"type": "object",
|
|
@@ -206,6 +219,42 @@
|
|
|
206
219
|
"metadata": {
|
|
207
220
|
"type": "object",
|
|
208
221
|
"description": "The manifest's metadata, as it is"
|
|
222
|
+
},
|
|
223
|
+
"tools": {
|
|
224
|
+
"anyOf": [
|
|
225
|
+
{
|
|
226
|
+
"type": "array",
|
|
227
|
+
"items": {
|
|
228
|
+
"type": "string"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"type": "string"
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
"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"
|
|
236
|
+
},
|
|
237
|
+
"disallowedTools": {
|
|
238
|
+
"anyOf": [
|
|
239
|
+
{
|
|
240
|
+
"type": "array",
|
|
241
|
+
"items": {
|
|
242
|
+
"type": "string"
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"type": "string"
|
|
247
|
+
}
|
|
248
|
+
],
|
|
249
|
+
"description": "agent-folder/4: library tools this agent does not get, by name"
|
|
250
|
+
},
|
|
251
|
+
"flow": {
|
|
252
|
+
"type": "string",
|
|
253
|
+
"description": "agent-folder/4, a subagent file: the flow file that drives it (./research.flow.json); its body is then empty"
|
|
254
|
+
},
|
|
255
|
+
"readonly": {
|
|
256
|
+
"type": "boolean",
|
|
257
|
+
"description": "agent-folder/4, a subagent file (Cursor's key): true reads as tools: [read, grep, glob] when tools is left out"
|
|
209
258
|
}
|
|
210
259
|
},
|
|
211
260
|
"required": [
|