@nylorun/core 0.35.0-beta → 0.36.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 +6 -0
- package/dist/contracts.d.ts +41 -0
- package/dist/contracts.js +18 -2
- package/dist/definition/variant.js +8 -1
- package/dist/engine/explain.js +22 -5
- package/dist/engine/index.d.ts +1 -0
- package/dist/engine/index.js +1 -0
- package/dist/engine/preview.d.ts +1 -0
- package/dist/engine/preview.js +2 -1
- package/dist/engine/projection.d.ts +3 -1
- package/dist/engine/projection.js +97 -2
- package/dist/engine/tools.d.ts +22 -0
- package/dist/engine/tools.js +36 -0
- package/dist/folder/compile.d.ts +2 -2
- package/dist/folder/compile.js +79 -12
- package/dist/folder/engine.d.ts +9 -0
- package/dist/folder/engine.js +1 -1
- package/dist/folder/index.d.ts +2 -0
- package/dist/folder/index.js +2 -0
- package/dist/folder/migrate-v3.d.ts +20 -0
- package/dist/folder/migrate-v3.js +124 -0
- package/dist/folder/schemas.js +12 -4
- package/dist/folder/v3.d.ts +66 -0
- package/dist/folder/v3.js +139 -0
- package/dist/manifest-schemas.js +4 -3
- package/dist/plugins/bundle.generated.d.ts +120 -0
- package/dist/plugins/bundle.generated.js +143 -0
- package/dist/plugins/index.d.ts +65 -0
- package/dist/plugins/index.js +62 -0
- package/dist/schemas/agent-folder/agent-md.schema.json +20 -3
- package/dist/schemas/agent-manifest.schema.json +45 -1
- package/dist/schemas/harness-manifest.schema.json +45 -1
- package/dist/types/manifest.d.ts +12 -0
- package/package.json +1 -1
package/dist/folder/compile.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AGENT_MANIFEST_V8_SCHEMA_VERSION, AGENT_MODEL_MAX_CHARS, AgentManifestV8Schema, ENVIRONMENT_NAME_PATTERN, HarnessIdSchema, RuntimeSectionSchema, TOOL_SECRET_NAME_PATTERN, TriggerSchema, agentModelChoice, isAgentManifestName, } from "../contracts.js";
|
|
2
2
|
import { cronScheduleIssue, isTimeZone, timeZoneNames } from "../definition/cron.js";
|
|
3
|
+
import { RUNTIME_SERVER } from "../plugins/index.js";
|
|
4
|
+
import { enginePlugins, isFolderV3, pluginSkillNames, v3Declarations } from "./v3.js";
|
|
3
5
|
import { DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
|
|
4
6
|
import { sectionGapsAt } from "../definition/sections.js";
|
|
5
7
|
import { DEFAULT_HARNESS } from "../utils/harness-id.js";
|
|
@@ -16,7 +18,7 @@ export const AGENT_FOLDER_COMPILER = "agent-folder/1";
|
|
|
16
18
|
* The formats this compiler builds: `agent-folder/1`, and `agent-folder/2` (ADR-100), whose
|
|
17
19
|
* folder declares every engine feature it uses (`folder/engine.ts`).
|
|
18
20
|
*/
|
|
19
|
-
export const AGENT_FOLDER_FORMATS = ["agent-folder/1", "agent-folder/2"];
|
|
21
|
+
export const AGENT_FOLDER_FORMATS = ["agent-folder/1", "agent-folder/2", "agent-folder/3"];
|
|
20
22
|
/**
|
|
21
23
|
* What a folder may hold, unless `compileAgentFolder` is given other limits (a Tenant's Runtime
|
|
22
24
|
* limits `folderFiles`, `folderBytes` and `folderTextFileBytes`, which default to these).
|
|
@@ -54,7 +56,7 @@ export const SCHEMA_URLS = {
|
|
|
54
56
|
flow: [`${FOLDER_SCHEMAS}flow.json`],
|
|
55
57
|
};
|
|
56
58
|
const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
57
|
-
export const AGENT_KEYS = ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "engine", "metadata"];
|
|
59
|
+
export const AGENT_KEYS = ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "engine", "plugins", "metadata"];
|
|
58
60
|
const SKILL_KEYS = ["name", "description", "license", "compatibility", "metadata", "allowed-tools"];
|
|
59
61
|
export const TRIGGER_KEYS = ["schedule", "timezone", "at", "webhook", "session"];
|
|
60
62
|
export const MCP_KEYS = ["$schema", "mcpServers"];
|
|
@@ -67,8 +69,8 @@ export const TOOL_KEYS = ["description", "inputSchema", "outputSchema", "http"];
|
|
|
67
69
|
* The loop settings our harness reads from `loop`: `plan` (`true` offers the agent `update_plan`)
|
|
68
70
|
* and `connections` (`true` offers it `request_connection`). A custom harness reads its own.
|
|
69
71
|
*/
|
|
70
|
-
const NYLORUN_LOOP_KEYS = ["plan", "connections"];
|
|
71
|
-
const LOOP_TOOLS = { plan: "update_plan", connections: "request_connection" };
|
|
72
|
+
const NYLORUN_LOOP_KEYS = ["plan", "connections", "ask"];
|
|
73
|
+
const LOOP_TOOLS = { plan: "update_plan", connections: "request_connection", ask: "ask" };
|
|
72
74
|
/** The runtime fields only a sandbox has, and the ones only a pod has. */
|
|
73
75
|
const SANDBOX_FIELDS = ["image", "resources", "storage", "network", "setup", "files"];
|
|
74
76
|
const POD_FIELDS = ["image", "storage", "setup", "files"];
|
|
@@ -217,6 +219,9 @@ export function compileAgentFolder(input, scope) {
|
|
|
217
219
|
const diagnostics = [];
|
|
218
220
|
/** The folder's format: the uploaded folder's `format`, which a folder inside it shares. */
|
|
219
221
|
let format = scope?.engineFacts?.format ?? 1;
|
|
222
|
+
/** The folder is `agent-folder/3` (ADR-106): its plugins stand for v2 declarations (folder/v3.ts). */
|
|
223
|
+
let v3 = scope?.engineFacts?.v3 === true;
|
|
224
|
+
let v3Plugins;
|
|
220
225
|
const parsed = new Map();
|
|
221
226
|
const report = (severity, code, message, file, path, options = {}) => {
|
|
222
227
|
let at = options.at;
|
|
@@ -334,6 +339,19 @@ export function compileAgentFolder(input, scope) {
|
|
|
334
339
|
}
|
|
335
340
|
return result.value;
|
|
336
341
|
};
|
|
342
|
+
/** Whether runtime.json names a computer, read quietly before the runtime section is (v3). */
|
|
343
|
+
const earlyComputer = () => {
|
|
344
|
+
const bytes = input.files.get(RUNTIME_FILE);
|
|
345
|
+
if (!bytes)
|
|
346
|
+
return false;
|
|
347
|
+
try {
|
|
348
|
+
const value = JSON.parse(new TextDecoder().decode(bytes).replace(/^\uFEFF/, ""));
|
|
349
|
+
return value?.kind === "virtual" || value?.kind === "pod";
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
337
355
|
const readMarkdown = (path) => {
|
|
338
356
|
const text = textOf(path);
|
|
339
357
|
if (text === undefined)
|
|
@@ -471,10 +489,44 @@ export function compileAgentFolder(input, scope) {
|
|
|
471
489
|
error("description_missing", "description is required: what the agent does, in a sentence", AGENT_FILE, front.description === undefined ? undefined : ["description"]);
|
|
472
490
|
else
|
|
473
491
|
description = front.description.trim();
|
|
474
|
-
if (!scope &&
|
|
492
|
+
if (!scope && isFolderV3(front.format)) {
|
|
493
|
+
v3 = true;
|
|
494
|
+
format = 2;
|
|
495
|
+
}
|
|
496
|
+
else if (!scope && folderFormatOf(front.format) === undefined)
|
|
475
497
|
error("format_unsupported", `format ${JSON.stringify(front.format)} is not supported: this compiler builds ${AGENT_FOLDER_FORMATS.join(" and ")} (the default, ${AGENT_FOLDER_COMPILER})`, AGENT_FILE, ["format"]);
|
|
476
498
|
else if (!scope)
|
|
477
499
|
format = folderFormatOf(front.format);
|
|
500
|
+
// agent-folder/3 (ADR-106): the plugins stand for agent-folder/2's declarations.
|
|
501
|
+
if (v3 && scope?.role !== "plugin") {
|
|
502
|
+
const role = scope?.role === "subagent" ? "subagent" : "root";
|
|
503
|
+
v3Plugins = v3Declarations(front, {
|
|
504
|
+
error: (code, message, path, options) => error(code, message, AGENT_FILE, path, options),
|
|
505
|
+
computer: scope?.engineFacts ? scope.engineFacts.computer : earlyComputer(),
|
|
506
|
+
role,
|
|
507
|
+
...(scope?.engineFacts?.plugins === undefined ? {} : { parent: scope.engineFacts.plugins }),
|
|
508
|
+
});
|
|
509
|
+
delete front.memory;
|
|
510
|
+
delete front.loop;
|
|
511
|
+
if (isObject(front.mcpServers)) {
|
|
512
|
+
const { [RUNTIME_SERVER]: _runtime, ...rest } = front.mcpServers;
|
|
513
|
+
if (Object.keys(rest).length > 0)
|
|
514
|
+
front.mcpServers = rest;
|
|
515
|
+
else
|
|
516
|
+
delete front.mcpServers;
|
|
517
|
+
}
|
|
518
|
+
if (v3Plugins) {
|
|
519
|
+
if (v3Plugins.memory)
|
|
520
|
+
front.memory = v3Plugins.memory;
|
|
521
|
+
if (v3Plugins.loop)
|
|
522
|
+
front.loop = v3Plugins.loop;
|
|
523
|
+
front.engine = v3Plugins.engine;
|
|
524
|
+
}
|
|
525
|
+
else
|
|
526
|
+
delete front.engine;
|
|
527
|
+
}
|
|
528
|
+
else if (front.plugins !== undefined && scope?.role !== "plugin")
|
|
529
|
+
error("v3_key", "plugins names the Runtime's plugins, a key of agent-folder/3. Fix: add format: agent-folder/3 to AGENT.md, or run nylorun migrate folder <dir> --to 3", AGENT_FILE, ["plugins"], { key: true });
|
|
478
530
|
if (front.harness !== undefined) {
|
|
479
531
|
if (HarnessIdSchema.safeParse(front.harness).success)
|
|
480
532
|
harness.id = front.harness;
|
|
@@ -553,6 +605,8 @@ export function compileAgentFolder(input, scope) {
|
|
|
553
605
|
const { $schema: _, extends: __, ...rest } = value;
|
|
554
606
|
runtime = rest;
|
|
555
607
|
origins.push([["runtime"], { file: RUNTIME_FILE, path: [] }]);
|
|
608
|
+
if (v3 && !scope && rest.selfWake !== undefined)
|
|
609
|
+
error("v3_refused", "selfWake is a key of agent-folder/2: in agent-folder/3, nylorun-triggers sets a follow-up (in or at, session: this). Fix: run nylorun migrate folder <dir> --to 3", RUNTIME_FILE, ["selfWake"], { key: true });
|
|
556
610
|
if (isObject(rest.triggers))
|
|
557
611
|
for (const [id, trigger] of Object.entries(rest.triggers))
|
|
558
612
|
if (isObject(trigger))
|
|
@@ -606,7 +660,12 @@ export function compileAgentFolder(input, scope) {
|
|
|
606
660
|
return trimmed;
|
|
607
661
|
},
|
|
608
662
|
});
|
|
609
|
-
if (declared &&
|
|
663
|
+
if (declared && v3) {
|
|
664
|
+
const network = isObject(runtime) && isObject(runtime.network) ? runtime.network : undefined;
|
|
665
|
+
const hosts = Array.isArray(network?.allowedHosts) ? network.allowedHosts.filter((host) => typeof host === "string") : undefined;
|
|
666
|
+
declared = { ...declared, engine: { ...declared.engine, plugins: enginePlugins(v3Plugins?.plugins ?? [], hosts) } };
|
|
667
|
+
}
|
|
668
|
+
if (declared && !scope && computer && !v3 && (declared.engine.sandbox ?? []).length === 0)
|
|
610
669
|
warn("sandbox_undeclared", `The runtime has a computer (kind ${JSON.stringify(runtimeKind)}), and engine.sandbox names no sandbox tool, so the agent gets no shell or file tools and no sandbox note. Fix: engine: { sandbox: [bash, read, write, edit, grep, glob] } (any of them), or a runtime without a computer`, AGENT_FILE, front.engine === undefined ? undefined : ["engine"], front.engine === undefined ? { at: { line: 1, column: 1 } } : { key: true });
|
|
611
670
|
origins.push([["harness", "engine"], { file: AGENT_FILE, path: ["engine"] }]);
|
|
612
671
|
}
|
|
@@ -619,6 +678,7 @@ export function compileAgentFolder(input, scope) {
|
|
|
619
678
|
format,
|
|
620
679
|
computer,
|
|
621
680
|
...(format === 2 && declared ? { engine: declared.engine } : {}),
|
|
681
|
+
...(v3 ? { v3: true, plugins: v3Plugins?.plugins ?? [] } : {}),
|
|
622
682
|
memory: isObject(front.memory),
|
|
623
683
|
selfWake: isObject(runtime) && runtime.selfWake === true,
|
|
624
684
|
};
|
|
@@ -822,6 +882,8 @@ export function compileAgentFolder(input, scope) {
|
|
|
822
882
|
}
|
|
823
883
|
}
|
|
824
884
|
}
|
|
885
|
+
if (v3 && servers[RUNTIME_SERVER] !== undefined)
|
|
886
|
+
error("server_reserved", `${RUNTIME_SERVER} is the Runtime's own server, which its plugins share: name this server differently`, MCP_FILE, ["mcpServers", RUNTIME_SERVER], { key: true });
|
|
825
887
|
if (Object.keys(servers).length > 0)
|
|
826
888
|
harness.mcpServers = servers;
|
|
827
889
|
// --- skills/ ---------------------------------------------------------------------------
|
|
@@ -934,6 +996,10 @@ export function compileAgentFolder(input, scope) {
|
|
|
934
996
|
origins.push([["harness", "skills", key, "secrets"], { file: AGENT_FILE, path: [...at, "secrets"] }]);
|
|
935
997
|
}
|
|
936
998
|
}
|
|
999
|
+
if (v3 && v3Plugins)
|
|
1000
|
+
for (const name of pluginSkillNames(v3Plugins.plugins))
|
|
1001
|
+
if (skills[name] !== undefined)
|
|
1002
|
+
error("skill_reserved", `${name} is the skill of a plugin this folder declares: name the folder's skill differently`, `skills/${name}/SKILL.md`);
|
|
937
1003
|
if (Object.keys(skills).length > 0)
|
|
938
1004
|
harness.skills = skills;
|
|
939
1005
|
// --- tools/ ----------------------------------------------------------------------------
|
|
@@ -1016,7 +1082,7 @@ export function compileAgentFolder(input, scope) {
|
|
|
1016
1082
|
seeded[path.slice("files/".length)] = `sha256:${byPath.get(path).sha256}`;
|
|
1017
1083
|
// --- agents/, flow.json and plugins/ (folder/nested.ts) ----------------------------------
|
|
1018
1084
|
if (!parts.compose())
|
|
1019
|
-
return finish(format, diagnostics);
|
|
1085
|
+
return finish(v3 ? 3 : format, diagnostics);
|
|
1020
1086
|
// --- The engine blocks the agent gets (agent-folder/2) ------------------------------------
|
|
1021
1087
|
if (declared && harness.kind !== "workflow") {
|
|
1022
1088
|
const facts = engineFacts();
|
|
@@ -1040,6 +1106,7 @@ export function compileAgentFolder(input, scope) {
|
|
|
1040
1106
|
plan: role === "root" && loop.plan === true,
|
|
1041
1107
|
connections: role === "root" && loop.connections === true,
|
|
1042
1108
|
triggers: role === "root" && declared.engine.triggers === true,
|
|
1109
|
+
ask: role === "root" && loop.ask === true,
|
|
1043
1110
|
});
|
|
1044
1111
|
for (const name of unusedInstructions(declared.engine, names))
|
|
1045
1112
|
warn("engine_text_unused", `engine.instructions.${name} replaces the wording of the ${name} block, and the agent does not get that block, so the text is never read`, AGENT_FILE, ["engine", "instructions", name], { key: true });
|
|
@@ -1065,7 +1132,7 @@ export function compileAgentFolder(input, scope) {
|
|
|
1065
1132
|
}
|
|
1066
1133
|
// --- Every field checked as the Runtime checks the manifest ------------------------------
|
|
1067
1134
|
if (diagnostics.some((item) => item.severity === "error") || name === undefined || description === undefined)
|
|
1068
|
-
return finish(format, diagnostics);
|
|
1135
|
+
return finish(v3 ? 3 : format, diagnostics);
|
|
1069
1136
|
const document = {
|
|
1070
1137
|
manifestSchemaVersion: AGENT_MANIFEST_V8_SCHEMA_VERSION,
|
|
1071
1138
|
name,
|
|
@@ -1101,10 +1168,10 @@ export function compileAgentFolder(input, scope) {
|
|
|
1101
1168
|
continue;
|
|
1102
1169
|
place(issue, [], fromOrigins);
|
|
1103
1170
|
}
|
|
1104
|
-
return finish(format, diagnostics);
|
|
1171
|
+
return finish(v3 ? 3 : format, diagnostics);
|
|
1105
1172
|
}
|
|
1106
1173
|
if (diagnostics.some((item) => item.severity === "error"))
|
|
1107
|
-
return finish(format, diagnostics);
|
|
1174
|
+
return finish(v3 ? 3 : format, diagnostics);
|
|
1108
1175
|
const manifest = checked.data;
|
|
1109
1176
|
// --- What the Runtime checks at save, where it needs no Tenant ---------------------------
|
|
1110
1177
|
const hasRuntimeFile = byPath.has(RUNTIME_FILE);
|
|
@@ -1142,8 +1209,8 @@ export function compileAgentFolder(input, scope) {
|
|
|
1142
1209
|
: `${field} ${POD_ONLY[field]}`, RUNTIME_FILE, [field], { key: true, pointer: pointerOf(["runtime", field]) });
|
|
1143
1210
|
}
|
|
1144
1211
|
if (diagnostics.some((item) => item.severity === "error"))
|
|
1145
|
-
return finish(format, diagnostics);
|
|
1146
|
-
return finish(format, diagnostics, manifest);
|
|
1212
|
+
return finish(v3 ? 3 : format, diagnostics);
|
|
1213
|
+
return finish(v3 ? 3 : format, diagnostics, manifest);
|
|
1147
1214
|
/** A schema issue in the compiler's words, at the file and field that wrote it. */
|
|
1148
1215
|
function place(issue, base, where) {
|
|
1149
1216
|
const full = [...base, ...issue.path];
|
package/dist/folder/engine.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export interface EngineScopeFacts {
|
|
|
18
18
|
readonly memory: boolean;
|
|
19
19
|
/** The uploaded folder's runtime sets `selfWake`. */
|
|
20
20
|
readonly selfWake: boolean;
|
|
21
|
+
/** The uploaded folder is `agent-folder/3` (ADR-106). */
|
|
22
|
+
readonly v3?: boolean;
|
|
23
|
+
/** Its plugins, under format 3: a subagent's are a subset. */
|
|
24
|
+
readonly plugins?: readonly {
|
|
25
|
+
readonly name: import("../plugins/index.js").PluginName;
|
|
26
|
+
readonly tools: readonly string[];
|
|
27
|
+
}[];
|
|
21
28
|
}
|
|
22
29
|
type Fail = (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
|
|
23
30
|
/**
|
|
@@ -65,6 +72,8 @@ export declare function engineBlocksOf(agent: {
|
|
|
65
72
|
readonly connections: boolean;
|
|
66
73
|
/** The root agent declares `engine.triggers` (D83). */
|
|
67
74
|
readonly triggers?: boolean;
|
|
75
|
+
/** The root agent has `ask` (`agent-folder/3`, `harness.loop.ask`). */
|
|
76
|
+
readonly ask?: boolean;
|
|
68
77
|
}): EngineBlockName[];
|
|
69
78
|
/** `harness.engine` as the compiled manifest holds it: the declarations, then the blocks. */
|
|
70
79
|
export declare function compiledEngine(engine: HarnessEngine, blocks: readonly EngineBlockName[], sources: Partial<Record<EngineBlockName, string>>): HarnessEngine;
|
package/dist/folder/engine.js
CHANGED
|
@@ -204,7 +204,7 @@ export function engineDeclarations(value, options) {
|
|
|
204
204
|
* (`engineProjection`), so the list is what a session's system text holds.
|
|
205
205
|
*/
|
|
206
206
|
export function engineBlocksOf(agent, facts) {
|
|
207
|
-
const projection = engineProjection(agent, { ...(facts.computer ? { sandbox: { workspace: SANDBOX_WORKSPACE } } : {}), ...(facts.selfWake ? { selfWake: true } : {}) }, DEFAULT_ENGINE_TOOL_LIMITS, facts.memory && { access: facts.memory.access ?? "read_write", root: facts.memory.root, index: facts.memory.index !== false }, facts.plan, facts.connections, facts.triggers === true);
|
|
207
|
+
const projection = engineProjection(agent, { ...(facts.computer ? { sandbox: { workspace: SANDBOX_WORKSPACE } } : {}), ...(facts.selfWake ? { selfWake: true } : {}) }, DEFAULT_ENGINE_TOOL_LIMITS, facts.memory && { access: facts.memory.access ?? "read_write", root: facts.memory.root, index: facts.memory.index !== false }, facts.plan, facts.connections, facts.triggers === true, facts.ask === true);
|
|
208
208
|
const names = projection.blocks.map((block) => block.name);
|
|
209
209
|
const servers = Object.values(agent.mcpServers ?? {});
|
|
210
210
|
const deferrable = servers.length > 0 &&
|
package/dist/folder/index.d.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderT
|
|
|
10
10
|
export { folderOfManifest, type FolderOfManifest, type FolderOfManifestOptions } from "./decompile.js";
|
|
11
11
|
export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas, type AgentFolderSchemaKind } from "./schemas.js";
|
|
12
12
|
export { applyFolderFixes, type AppliedFolderFixes } from "./fix.js";
|
|
13
|
+
export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
|
|
14
|
+
export { folderV3Edit, type FolderV3Edit } from "./migrate-v3.js";
|
package/dist/folder/index.js
CHANGED
|
@@ -10,3 +10,5 @@ export { AGENT_FOLDER_COMPILER, AGENT_FOLDER_LIMITS, compileAgentFolder, folderT
|
|
|
10
10
|
export { folderOfManifest } from "./decompile.js";
|
|
11
11
|
export { AGENT_FOLDER_SCHEMA_KINDS, agentFolderJsonSchemas } from "./schemas.js";
|
|
12
12
|
export { applyFolderFixes } from "./fix.js";
|
|
13
|
+
export { AGENT_FOLDER_V3, isFolderV3 } from "./v3.js";
|
|
14
|
+
export { folderV3Edit } from "./migrate-v3.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type PluginName } from "../plugins/index.js";
|
|
2
|
+
/** A folder file, migrated, or why it can't be. */
|
|
3
|
+
export type FolderV3Edit = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly agentMd: string;
|
|
6
|
+
readonly runtimeJson?: string;
|
|
7
|
+
readonly plugins: readonly PluginName[];
|
|
8
|
+
} | {
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Migrates one `AGENT.md` (and, for the root, its folder's `runtime.json`). `role` is `subagent`
|
|
14
|
+
* for `agents/<id>/AGENT.md`, which declares no memory, loop or triggers of its own.
|
|
15
|
+
*/
|
|
16
|
+
export declare function folderV3Edit(input: {
|
|
17
|
+
readonly agentMd: string;
|
|
18
|
+
readonly runtimeJson?: string;
|
|
19
|
+
readonly role: "root" | "subagent";
|
|
20
|
+
}): FolderV3Edit;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agent-folder/2` → `agent-folder/3` (ADR-106): the plugins that keep what an agent gets, written
|
|
3
|
+
* in place of the declarations they stand for. `nylorun migrate folder <dir> --to 3` runs it on a
|
|
4
|
+
* folder's `AGENT.md` and each subagent's, and on `runtime.json`, then checks that every agent
|
|
5
|
+
* keeps the same tools and features.
|
|
6
|
+
*
|
|
7
|
+
* - `memory` → `nylorun-memory`; its `instructions` move to the end of the body.
|
|
8
|
+
* - `engine.triggers`, or `runtime.selfWake` → `nylorun-triggers`.
|
|
9
|
+
* - `loop.plan` → `nylorun-plan`; `loop.connections` → `nylorun-interactions`, with `ask` off.
|
|
10
|
+
* - `engine.artifacts` → `nylorun-artifacts`, with the tools it left out off.
|
|
11
|
+
* - `engine.sandbox` → `nylorun-sandbox`, with the tools it left out off.
|
|
12
|
+
*
|
|
13
|
+
* A declaration v3 can't express stops it: a read-only root memory, `memory.index: false`, or a
|
|
14
|
+
* replaced wording (`engine.instructions`).
|
|
15
|
+
*/
|
|
16
|
+
import { Document, isMap, parseDocument, YAMLMap, YAMLSeq } from "yaml";
|
|
17
|
+
import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
|
|
18
|
+
import { RUNTIME_SERVER, pluginTools } from "../plugins/index.js";
|
|
19
|
+
import { AGENT_FOLDER_V3 } from "./v3.js";
|
|
20
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
21
|
+
function split(text) {
|
|
22
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
23
|
+
const lines = text.replace(/^/, "").split(/\r?\n/);
|
|
24
|
+
if (lines[0]?.trimEnd() !== "---")
|
|
25
|
+
return undefined;
|
|
26
|
+
const end = lines.findIndex((line, index) => index > 0 && line.trimEnd() === "---");
|
|
27
|
+
if (end < 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
return { front: lines.slice(1, end).join("\n"), body: lines.slice(end + 1).join("\n"), eol };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Migrates one `AGENT.md` (and, for the root, its folder's `runtime.json`). `role` is `subagent`
|
|
33
|
+
* for `agents/<id>/AGENT.md`, which declares no memory, loop or triggers of its own.
|
|
34
|
+
*/
|
|
35
|
+
export function folderV3Edit(input) {
|
|
36
|
+
const parts = split(input.agentMd);
|
|
37
|
+
if (!parts)
|
|
38
|
+
return { ok: false, reason: "AGENT.md has no frontmatter" };
|
|
39
|
+
const doc = parseDocument(parts.front);
|
|
40
|
+
const data = (doc.toJS() ?? {});
|
|
41
|
+
const runtime = input.runtimeJson === undefined ? undefined : JSON.parse(input.runtimeJson);
|
|
42
|
+
const memory = isObject(data.memory) ? data.memory : undefined;
|
|
43
|
+
const loop = isObject(data.loop) ? data.loop : {};
|
|
44
|
+
const engine = isObject(data.engine) ? data.engine : {};
|
|
45
|
+
if (engine.instructions !== undefined)
|
|
46
|
+
return { ok: false, reason: "engine.instructions replaces the engine's wording, which agent-folder/3 doesn't do: the plugins' words are the Runtime's. Remove it first" };
|
|
47
|
+
if (memory && memory.access === "read_only" && input.role === "root")
|
|
48
|
+
return { ok: false, reason: "memory.access: read_only for the root agent has no plugin form: in agent-folder/3 the root agent may write its memory" };
|
|
49
|
+
if (memory && memory.index === false)
|
|
50
|
+
return { ok: false, reason: "memory.index: false has no plugin form: nylorun-memory always pins its index" };
|
|
51
|
+
const plugins = [];
|
|
52
|
+
const off = [];
|
|
53
|
+
if (memory && input.role === "root")
|
|
54
|
+
plugins.push("nylorun-memory");
|
|
55
|
+
if (input.role === "root" && (engine.triggers === true || runtime?.selfWake === true))
|
|
56
|
+
plugins.push("nylorun-triggers");
|
|
57
|
+
if (input.role === "root" && loop.plan === true)
|
|
58
|
+
plugins.push("nylorun-plan");
|
|
59
|
+
if (input.role === "root" && loop.connections === true) {
|
|
60
|
+
plugins.push("nylorun-interactions");
|
|
61
|
+
off.push("ask");
|
|
62
|
+
}
|
|
63
|
+
const artifacts = isObject(engine.artifacts) ? engine.artifacts : {};
|
|
64
|
+
if (artifacts.read === true || artifacts.save === true) {
|
|
65
|
+
plugins.push("nylorun-artifacts");
|
|
66
|
+
if (artifacts.read !== true)
|
|
67
|
+
off.push("read_artifact");
|
|
68
|
+
if (artifacts.save !== true)
|
|
69
|
+
off.push("save_artifact");
|
|
70
|
+
}
|
|
71
|
+
const sandbox = Array.isArray(engine.sandbox) ? engine.sandbox : [];
|
|
72
|
+
if (sandbox.length > 0) {
|
|
73
|
+
plugins.push("nylorun-sandbox");
|
|
74
|
+
off.push(...SANDBOX_TOOL_NAMES.filter((tool) => !sandbox.includes(tool)));
|
|
75
|
+
}
|
|
76
|
+
// The frontmatter, edited in place: comments and the other keys stay as they are.
|
|
77
|
+
doc.delete("memory");
|
|
78
|
+
doc.delete("loop");
|
|
79
|
+
const engineNode = doc.get("engine", true);
|
|
80
|
+
if (isMap(engineNode)) {
|
|
81
|
+
for (const key of ["sandbox", "artifacts", "triggers", "instructions"])
|
|
82
|
+
engineNode.delete(key);
|
|
83
|
+
if (engineNode.items.length === 0)
|
|
84
|
+
doc.delete("engine");
|
|
85
|
+
}
|
|
86
|
+
if (input.role === "root") {
|
|
87
|
+
if (doc.has("format"))
|
|
88
|
+
doc.set("format", AGENT_FOLDER_V3);
|
|
89
|
+
else
|
|
90
|
+
doc.contents.items.unshift(doc.createPair("format", AGENT_FOLDER_V3));
|
|
91
|
+
}
|
|
92
|
+
if (plugins.length > 0) {
|
|
93
|
+
const seq = new YAMLSeq();
|
|
94
|
+
for (const name of plugins)
|
|
95
|
+
seq.add(doc.createNode(name));
|
|
96
|
+
seq.flow = true;
|
|
97
|
+
doc.set("plugins", seq);
|
|
98
|
+
}
|
|
99
|
+
if (off.length > 0) {
|
|
100
|
+
const known = new Set(plugins.flatMap(pluginTools));
|
|
101
|
+
const tools = Object.fromEntries(off.filter((tool) => known.has(tool)).map((tool) => [tool, { enabled: false }]));
|
|
102
|
+
if (Object.keys(tools).length > 0) {
|
|
103
|
+
const node = doc.createNode({ tools });
|
|
104
|
+
for (const pair of node.items)
|
|
105
|
+
if (isMap(pair.value))
|
|
106
|
+
pair.value.flow = false;
|
|
107
|
+
const servers = doc.get("mcpServers", true);
|
|
108
|
+
if (isMap(servers))
|
|
109
|
+
servers.set(RUNTIME_SERVER, node);
|
|
110
|
+
else
|
|
111
|
+
doc.set("mcpServers", doc.createNode({ [RUNTIME_SERVER]: { tools } }));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const front = new Document(doc.contents).toString({ lineWidth: 0 }).replace(/\n$/, "");
|
|
115
|
+
const instructions = memory && typeof memory.instructions === "string" && memory.instructions.trim() !== "" ? memory.instructions.trim() : undefined;
|
|
116
|
+
const body = instructions === undefined ? parts.body : `${parts.body.replace(/\s+$/, "")}\n\n${instructions}\n`;
|
|
117
|
+
const agentMd = ["---", front, "---", body].join("\n").replaceAll("\n", parts.eol);
|
|
118
|
+
let runtimeJson = input.runtimeJson;
|
|
119
|
+
if (runtime && runtime.selfWake !== undefined) {
|
|
120
|
+
const { selfWake: _wake, ...rest } = runtime;
|
|
121
|
+
runtimeJson = `${JSON.stringify(rest, null, 2)}\n`;
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, agentMd, ...(runtimeJson === undefined ? {} : { runtimeJson }), plugins };
|
|
124
|
+
}
|
package/dist/folder/schemas.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* document says less than the compiler only where JSON Schema cannot: that a path names a file of
|
|
18
18
|
* the folder, a cron, a time zone, which server or skill a name means.
|
|
19
19
|
*/
|
|
20
|
+
import { PLUGIN_NAMES } from "../plugins/index.js";
|
|
20
21
|
import { z } from "zod";
|
|
21
22
|
import { AGENT_MANIFEST_NAME_PATTERN, ENVIRONMENT_NAME_PATTERN, HarnessIdSchema, AgentModelSchema, HarnessMemorySchema, HttpToolTargetSchema, McpToolSettingsSchema, RuntimeSectionSchema, TOOL_SECRET_NAME_PATTERN, TriggerSchema, } from "../contracts.js";
|
|
22
23
|
import { DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
|
|
@@ -53,11 +54,12 @@ function fromZod(schema, defs, description) {
|
|
|
53
54
|
* A kind's revision within format 1, when its document gained an optional key (a published `$id`
|
|
54
55
|
* names one document for good): `AGENT.md` took `model` (Host feature `agent-model`), published
|
|
55
56
|
* as `agent-md.1.json`, then `format: agent-folder/2` and `engine` (ADR-100), as `agent-md.2.json`,
|
|
56
|
-
* then `engine.triggers` (D83), as `agent-md.3.json
|
|
57
|
+
* then `engine.triggers` (D83), as `agent-md.3.json`, then `format: agent-folder/3` and
|
|
58
|
+
* `plugins` (ADR-106), as `agent-md.4.json`;
|
|
57
59
|
* `runtime.json` took a secret slot's `toolPrefix` (Host feature `secret-routing`), published as
|
|
58
60
|
* `runtime.1.json`, then `limits.triggers` (D83), as `runtime.2.json`.
|
|
59
61
|
*/
|
|
60
|
-
const REVISIONS = { "agent-md":
|
|
62
|
+
const REVISIONS = { "agent-md": 4, runtime: 2 };
|
|
61
63
|
/** One document: its `$id` from its kind, then the body, then the `$defs` its parts named. */
|
|
62
64
|
function document(kind, title, description, body, defs) {
|
|
63
65
|
const revision = REVISIONS[kind];
|
|
@@ -97,8 +99,8 @@ function agentMd() {
|
|
|
97
99
|
name: { type: "string", pattern: AGENT_MANIFEST_NAME_PATTERN.source, description: "The agent manifest's name, the folder's when it is saved under one" },
|
|
98
100
|
description: { type: "string", minLength: 1, description: "What the agent does, in a sentence" },
|
|
99
101
|
format: {
|
|
100
|
-
enum: [1, 2, "agent-folder/1", "agent-folder/2"],
|
|
101
|
-
description: "The folder's format: agent-folder/1 (or 1, the default), which gets every engine feature by default
|
|
102
|
+
enum: [1, 2, 3, "agent-folder/1", "agent-folder/2", "agent-folder/3"],
|
|
103
|
+
description: "The folder's format: agent-folder/1 (or 1, the default), which gets every engine feature by default; agent-folder/2 (or 2), which declares each in engine; or agent-folder/3 (or 3), which declares the Runtime's features as plugins",
|
|
102
104
|
},
|
|
103
105
|
harness: fromZod(HarnessIdSchema, defs, "The harness that runs the loop: nylorun (ours, the default) or a custom harness's id"),
|
|
104
106
|
inputSchema: ref("JsonSchemaOrPath", "A flow's input (a folder with flow.json); an agent's input is the message"),
|
|
@@ -120,6 +122,12 @@ function agentMd() {
|
|
|
120
122
|
type: "object",
|
|
121
123
|
description: "The harness's own settings, passed to it each turn; the nylorun harness reads plan (true offers the agent update_plan) and connections (true offers it request_connection)",
|
|
122
124
|
},
|
|
125
|
+
plugins: {
|
|
126
|
+
type: "array",
|
|
127
|
+
items: { enum: [...PLUGIN_NAMES] },
|
|
128
|
+
uniqueItems: true,
|
|
129
|
+
description: "agent-folder/3: the Runtime's plugins the agent uses, which share the server nylorun (mcpServers.nylorun.tools turns one of their tools off): nylorun-memory, nylorun-triggers, nylorun-plan, nylorun-interactions, nylorun-artifacts, nylorun-sandbox (needs a computer)",
|
|
130
|
+
},
|
|
123
131
|
model: fromZod(AgentModelSchema, defs, "The model the agent runs on: <provider>/<model>, such as anthropic/claude-sonnet-4-5"),
|
|
124
132
|
engine: {
|
|
125
133
|
type: "object",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agent-folder/3` (ADR-106): a folder declares the Runtime's features as plugins, by name, and
|
|
3
|
+
* narrows their tools with the settings any MCP server takes:
|
|
4
|
+
*
|
|
5
|
+
* ```yaml
|
|
6
|
+
* format: agent-folder/3
|
|
7
|
+
* plugins: [nylorun-memory, nylorun-triggers, nylorun-plan, nylorun-interactions, nylorun-artifacts, nylorun-sandbox]
|
|
8
|
+
* mcpServers:
|
|
9
|
+
* nylorun:
|
|
10
|
+
* tools: { save_artifact: { enabled: false } }
|
|
11
|
+
* engine: { outputs: true, toolSearch: false } # the harness's own, as in agent-folder/2
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The compiler reads it as the `agent-folder/2` declarations it stands for (`memory`, `loop`,
|
|
15
|
+
* `engine.sandbox`, `engine.artifacts`, `engine.triggers`), so the Runtime checks a v3 agent as it
|
|
16
|
+
* checks a v2 one, and records the plugins in `harness.engine.plugins`, each with the tools left on
|
|
17
|
+
* and the hash of its files. The engine's projection then presents those tools as server
|
|
18
|
+
* `nylorun` (`engineProjection`).
|
|
19
|
+
*/
|
|
20
|
+
import { type PluginName } from "../plugins/index.js";
|
|
21
|
+
import type { HarnessEnginePlugin } from "../types/manifest.js";
|
|
22
|
+
import type { ReportOptions } from "./context.js";
|
|
23
|
+
/** The format name a v3 folder writes. */
|
|
24
|
+
export declare const AGENT_FOLDER_V3 = "agent-folder/3";
|
|
25
|
+
/** The keys of `AGENT.md` a v3 folder declares as plugins instead. */
|
|
26
|
+
export declare const V3_REFUSED_KEYS: readonly ["memory", "loop"];
|
|
27
|
+
/** The keys of `engine:` a v3 folder declares as plugins instead. */
|
|
28
|
+
export declare const V3_REFUSED_ENGINE_KEYS: readonly ["sandbox", "artifacts", "triggers", "instructions"];
|
|
29
|
+
/** Whether `value` names the v3 format: `agent-folder/3` or `3`. */
|
|
30
|
+
export declare function isFolderV3(value: unknown): boolean;
|
|
31
|
+
type Fail = (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
|
|
32
|
+
/** The plugins a v3 folder declares, each with the tools left on. */
|
|
33
|
+
export interface V3Plugins {
|
|
34
|
+
readonly plugins: {
|
|
35
|
+
readonly name: PluginName;
|
|
36
|
+
readonly tools: readonly string[];
|
|
37
|
+
}[];
|
|
38
|
+
/** The frontmatter keys they stand for, in `agent-folder/2`'s terms. */
|
|
39
|
+
readonly memory?: Record<string, unknown>;
|
|
40
|
+
readonly loop?: Record<string, unknown>;
|
|
41
|
+
readonly engine: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads a v3 frontmatter's `plugins:` and `mcpServers.nylorun`, refusing the keys it replaces.
|
|
45
|
+
* `parent` is a subagent's parent's plugins: a subagent's are a subset of them. Undefined, with
|
|
46
|
+
* the errors reported, when they are not valid.
|
|
47
|
+
*/
|
|
48
|
+
export declare function v3Declarations(front: Record<string, unknown>, options: {
|
|
49
|
+
readonly error: Fail;
|
|
50
|
+
readonly computer: boolean;
|
|
51
|
+
readonly role: "root" | "subagent";
|
|
52
|
+
readonly parent?: readonly {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly tools: readonly string[];
|
|
55
|
+
}[];
|
|
56
|
+
}): V3Plugins | undefined;
|
|
57
|
+
/** `harness.engine.plugins`: each declared plugin with its tools, its hash, and the sandbox's hosts. */
|
|
58
|
+
export declare function enginePlugins(plugins: readonly {
|
|
59
|
+
readonly name: PluginName;
|
|
60
|
+
readonly tools: readonly string[];
|
|
61
|
+
}[], hosts: readonly string[] | undefined): HarnessEnginePlugin[];
|
|
62
|
+
/** The names of the declared plugins' skills, which a folder's own skill may not take. */
|
|
63
|
+
export declare function pluginSkillNames(plugins: readonly {
|
|
64
|
+
readonly name: PluginName;
|
|
65
|
+
}[]): string[];
|
|
66
|
+
export {};
|