@nylorun/core 0.35.0-beta → 0.37.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 +19 -0
- package/dist/compatibility.d.ts +8 -1
- package/dist/compatibility.js +7 -0
- package/dist/contracts.d.ts +82 -4
- package/dist/contracts.js +42 -9
- 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/harness-api/harness-api.schema.json +5 -3
- package/dist/harness-api/json-schema.js +4 -2
- package/dist/harness-api/schema.d.ts +7 -0
- package/dist/harness-api/schema.js +6 -1
- 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ARTIFACTS_READ_TEXT, ARTIFACTS_SAVE_TEXT, CONNECTION_TEXT, ENGINE_BLOCK_VERSIONS, MEMORY_DATA_RULE, MEMORY_READ_ONLY_DATA_RULE, OUTPUTS_AFTER_SAVE_TEXT, OUTPUTS_TEXT, PLAN_TEXT, SKILLS_USAGE, TRIGGERS_TEXT, WAKE_TEXT, formatSkillCatalog, memoryRules, sandboxNote, skillFolderNote, } from "./blocks.js";
|
|
2
2
|
import { engineFeaturesOf } from "./features.js";
|
|
3
|
-
import { DEFAULT_SANDBOX_TOOL_LIMITS, REQUEST_CONNECTION_TOOL, TRIGGERS_TOOL, UPDATE_PLAN_TOOL, artifactTools, connectionToolOf, memoryToolOf, planToolOf, sandboxTools, skillTools, triggersToolOf, wakeToolOf, } from "./tools.js";
|
|
3
|
+
import { ASK_TOOL, DEFAULT_SANDBOX_TOOL_LIMITS, REQUEST_CONNECTION_TOOL, TRIGGERS_TOOL, UPDATE_PLAN_TOOL, artifactTools, askToolOf, connectionToolOf, memoryToolOf, planToolOf, sandboxTools, skillTools, triggersToolOf, wakeToolOf, } from "./tools.js";
|
|
4
|
+
import { PLUGIN_NAMES, pluginOf, pluginSkills, runtimeToolName } from "../plugins/index.js";
|
|
4
5
|
/** The default of the harness's `artifactPageBytes` setting: one `read_artifact` page. */
|
|
5
6
|
export const DEFAULT_ARTIFACT_PAGE_BYTES = 32 * 1024;
|
|
6
7
|
/** The most bytes of one skill file the skill tools read into the model's context by default. */
|
|
@@ -21,7 +22,9 @@ export const DEFAULT_ENGINE_TOOL_LIMITS = Object.freeze({
|
|
|
21
22
|
* the version declares `harness.engine.triggers` (`turn.start.agent.triggers`). What the agent
|
|
22
23
|
* declares (`agent.engine`) decides the rest; a block it replaces is in its words.
|
|
23
24
|
*/
|
|
24
|
-
export function engineProjection(agent, runsOn, options, memory, plan = false, connections = false, triggers = false) {
|
|
25
|
+
export function engineProjection(agent, runsOn, options, memory, plan = false, connections = false, triggers = false, ask = false) {
|
|
26
|
+
if (agent.engine?.plugins !== undefined)
|
|
27
|
+
return pluginProjection(agent, agent.engine.plugins, runsOn, options, memory, plan, connections, triggers, ask);
|
|
25
28
|
const skills = Object.values(agent.skills ?? {});
|
|
26
29
|
const workspace = runsOn?.sandbox?.workspace;
|
|
27
30
|
const features = engineFeaturesOf(agent.engine, { computer: workspace !== undefined });
|
|
@@ -107,3 +110,95 @@ export function engineProjection(agent, runsOn, options, memory, plan = false, c
|
|
|
107
110
|
features,
|
|
108
111
|
};
|
|
109
112
|
}
|
|
113
|
+
/** The first line of server `nylorun`'s text (ADR-106). */
|
|
114
|
+
export const RUNTIME_SERVER_HEADING = "# Server nylorun\nThe Runtime's own tools, from the plugins this agent declares. Their names begin with nylorun__.";
|
|
115
|
+
/** A sandbox section's network sentence: the hosts the runtime allows, or the policy note. */
|
|
116
|
+
function networkSentence(hosts) {
|
|
117
|
+
if (hosts === undefined || hosts.length === 0)
|
|
118
|
+
return "Network egress is limited by policy; a failed download usually means the host is not allowed.";
|
|
119
|
+
return `It can reach only these hosts: ${hosts.join(", ")}. A download from any other host fails.`;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Our engine's tools and text for an agent that declares the Runtime's plugins (`agent-folder/3`,
|
|
123
|
+
* ADR-106). The same tools as without plugins, with the same effects, named `nylorun__<tool>` for
|
|
124
|
+
* the model; the Runtime's words are one text, server `nylorun`, built from the declared plugins'
|
|
125
|
+
* sections in their order; their skills join the agent's own. `outputs`, the skills' usage and
|
|
126
|
+
* catalog, and the skills' folder note stay our engine's blocks.
|
|
127
|
+
*/
|
|
128
|
+
function pluginProjection(agent, declared, runsOn, options, memory, plan, connections, triggers, ask) {
|
|
129
|
+
const names = PLUGIN_NAMES.filter((name) => declared.some((plugin) => plugin.name === name));
|
|
130
|
+
const on = (plugin, tool) => declared.some((item) => item.name === plugin && item.tools.includes(tool));
|
|
131
|
+
const own = (name) => (agent.tools ?? []).some((tool) => tool.name === name);
|
|
132
|
+
const folderSkills = Object.values(agent.skills ?? {});
|
|
133
|
+
const extra = pluginSkills(names).filter((skill) => !folderSkills.some((item) => item.name === skill.name));
|
|
134
|
+
const catalog = [...folderSkills.map(({ name, description }) => ({ name, description })), ...extra.map(({ name, description }) => ({ name, description }))];
|
|
135
|
+
const workspace = runsOn?.sandbox?.workspace;
|
|
136
|
+
const features = engineFeaturesOf(agent.engine, { computer: workspace !== undefined });
|
|
137
|
+
const sandbox = features.sandbox.filter((tool) => on("nylorun-sandbox", tool));
|
|
138
|
+
const sandboxed = sandbox.length > 0;
|
|
139
|
+
const readArtifacts = features.artifactsRead && on("nylorun-artifacts", "read_artifact");
|
|
140
|
+
const saveArtifacts = features.artifactsSave && on("nylorun-artifacts", "save_artifact");
|
|
141
|
+
const triggering = triggers && on("nylorun-triggers", "triggers") && !own(TRIGGERS_TOOL);
|
|
142
|
+
const remembering = memory !== undefined && (memory.root === false || on("nylorun-memory", "memory"));
|
|
143
|
+
const writes = memory !== undefined && memory.root && memory.access === "read_write";
|
|
144
|
+
const planning = plan && on("nylorun-plan", UPDATE_PLAN_TOOL) && !own(UPDATE_PLAN_TOOL);
|
|
145
|
+
const asking = ask && on("nylorun-interactions", ASK_TOOL) && !own(ASK_TOOL);
|
|
146
|
+
const connecting = connections && on("nylorun-interactions", REQUEST_CONNECTION_TOOL) && !own(REQUEST_CONNECTION_TOOL);
|
|
147
|
+
const instructions = [];
|
|
148
|
+
const blocks = [];
|
|
149
|
+
const use = (name) => blocks.push({ name, version: ENGINE_BLOCK_VERSIONS[name] });
|
|
150
|
+
if (catalog.length > 0) {
|
|
151
|
+
use("skills");
|
|
152
|
+
instructions.push(SKILLS_USAGE, formatSkillCatalog(catalog));
|
|
153
|
+
}
|
|
154
|
+
if (sandboxed && folderSkills.length > 0) {
|
|
155
|
+
use("skill_folder");
|
|
156
|
+
instructions.push(skillFolderNote(folderSkills));
|
|
157
|
+
}
|
|
158
|
+
if (features.outputs) {
|
|
159
|
+
use("outputs");
|
|
160
|
+
instructions.push(saveArtifacts ? OUTPUTS_AFTER_SAVE_TEXT : OUTPUTS_TEXT);
|
|
161
|
+
}
|
|
162
|
+
// Server nylorun: the declared plugins' sections, in plugin order.
|
|
163
|
+
const text = (plugin, section) => pluginOf(plugin).instructions[section];
|
|
164
|
+
const sections = [];
|
|
165
|
+
if (remembering)
|
|
166
|
+
sections.push(text("nylorun-memory", writes ? "memory" : "memory.view"));
|
|
167
|
+
if (triggering)
|
|
168
|
+
sections.push(text("nylorun-triggers", "triggers"));
|
|
169
|
+
if (planning)
|
|
170
|
+
sections.push(text("nylorun-plan", "update_plan"));
|
|
171
|
+
if (asking || connecting)
|
|
172
|
+
sections.push([text("nylorun-interactions", "_"), ...(asking ? [text("nylorun-interactions", "ask")] : []), ...(connecting ? [text("nylorun-interactions", "request_connection")] : [])].join("\n"));
|
|
173
|
+
if (readArtifacts || saveArtifacts)
|
|
174
|
+
sections.push([text("nylorun-artifacts", "_"), ...(saveArtifacts ? [text("nylorun-artifacts", "save_artifact")] : []), ...(readArtifacts ? [text("nylorun-artifacts", "read_artifact")] : [])].join("\n"));
|
|
175
|
+
if (sandboxed) {
|
|
176
|
+
const hosts = declared.find((plugin) => plugin.name === "nylorun-sandbox")?.hosts;
|
|
177
|
+
sections.push(text("nylorun-sandbox", "_")
|
|
178
|
+
.replace("{workspace}", workspace)
|
|
179
|
+
.replace("{tools}", sandbox.map(runtimeToolName).join(", "))
|
|
180
|
+
.replace("{network}", networkSentence(hosts)));
|
|
181
|
+
}
|
|
182
|
+
if (sections.length > 0)
|
|
183
|
+
instructions.push([RUNTIME_SERVER_HEADING, ...sections].join("\n\n"));
|
|
184
|
+
const named = (tool) => ({ ...tool, name: runtimeToolName(tool.name), effectName: tool.name });
|
|
185
|
+
const skillManifests = [
|
|
186
|
+
...folderSkills,
|
|
187
|
+
...extra.map((skill) => ({ name: skill.name, description: skill.description, files: { "SKILL.md": "sha256:" + "0".repeat(64) } })),
|
|
188
|
+
];
|
|
189
|
+
return {
|
|
190
|
+
tools: [
|
|
191
|
+
...(sandboxed ? sandboxTools(options.sandboxTools, workspace, sandbox).map(named) : []),
|
|
192
|
+
...skillTools(skillManifests),
|
|
193
|
+
...artifactTools({ read: readArtifacts, save: saveArtifacts, sandboxed }, { pageBytes: options.artifactPageBytes }).map(named),
|
|
194
|
+
...(triggering ? [named(triggersToolOf())] : []),
|
|
195
|
+
...(remembering ? [named(memoryToolOf(writes))] : []),
|
|
196
|
+
...(planning ? [named(planToolOf())] : []),
|
|
197
|
+
...(asking ? [named(askToolOf())] : []),
|
|
198
|
+
...(connecting ? [named(connectionToolOf())] : []),
|
|
199
|
+
],
|
|
200
|
+
instructions,
|
|
201
|
+
blocks,
|
|
202
|
+
features: { ...features, sandbox, artifactsRead: readArtifacts, artifactsSave: saveArtifacts },
|
|
203
|
+
};
|
|
204
|
+
}
|
package/dist/engine/tools.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface EngineTool {
|
|
|
22
22
|
readonly instructions?: readonly string[];
|
|
23
23
|
/** What runs its calls: their effects' `target` (an MCP tool's identity, our engine's `harness`). */
|
|
24
24
|
readonly target?: EffectTarget;
|
|
25
|
+
/**
|
|
26
|
+
* The name its calls' effects carry (`toolName`), when the model reads another (ADR-106): a
|
|
27
|
+
* Runtime plugin's tool is `nylorun__memory` to the model and `memory` to its effect, so the
|
|
28
|
+
* record, tool policy and the harness's dispatch see it as without plugins.
|
|
29
|
+
*/
|
|
30
|
+
readonly effectName?: string;
|
|
25
31
|
}
|
|
26
32
|
/** What the sandbox tools hold a call to: the harness's configuration of them. */
|
|
27
33
|
export interface SandboxToolLimits {
|
|
@@ -116,3 +122,19 @@ export declare function deferredToolsTools(config: {
|
|
|
116
122
|
readonly toolSearchDefaultLimit: number;
|
|
117
123
|
readonly toolSearchMaxLimit: number;
|
|
118
124
|
}): readonly EngineTool[];
|
|
125
|
+
/** The question tool's name (ADR-106, `nylorun-interactions`). */
|
|
126
|
+
export declare const ASK_TOOL = "ask";
|
|
127
|
+
/** The most characters of a question, of a reason, and of one choice, and the most choices. */
|
|
128
|
+
export declare const ASK_LIMITS: Readonly<{
|
|
129
|
+
questionChars: 1000;
|
|
130
|
+
whyChars: 280;
|
|
131
|
+
choiceChars: 120;
|
|
132
|
+
choices: 6;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* `ask` (ADR-106): the agent asks whoever gave it the task a question it can't answer itself,
|
|
136
|
+
* and waits. It runs in the harness, as `request_connection` does: a first call pauses the turn
|
|
137
|
+
* with an interaction of kind `response` whose metadata says `kind: "question"`, which the A2A
|
|
138
|
+
* server shows as a question (`INPUT_REQUIRED`); the answer runs it again with the value.
|
|
139
|
+
*/
|
|
140
|
+
export declare function askToolOf(): EngineTool;
|
package/dist/engine/tools.js
CHANGED
|
@@ -506,3 +506,39 @@ export function deferredToolsTools(config) {
|
|
|
506
506
|
function definedOf(value) {
|
|
507
507
|
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
|
|
508
508
|
}
|
|
509
|
+
// --- ask -------------------------------------------------------------------------------------
|
|
510
|
+
/** The question tool's name (ADR-106, `nylorun-interactions`). */
|
|
511
|
+
export const ASK_TOOL = "ask";
|
|
512
|
+
/** The most characters of a question, of a reason, and of one choice, and the most choices. */
|
|
513
|
+
export const ASK_LIMITS = Object.freeze({ questionChars: 1000, whyChars: 280, choiceChars: 120, choices: 6 });
|
|
514
|
+
/**
|
|
515
|
+
* `ask` (ADR-106): the agent asks whoever gave it the task a question it can't answer itself,
|
|
516
|
+
* and waits. It runs in the harness, as `request_connection` does: a first call pauses the turn
|
|
517
|
+
* with an interaction of kind `response` whose metadata says `kind: "question"`, which the A2A
|
|
518
|
+
* server shows as a question (`INPUT_REQUIRED`); the answer runs it again with the value.
|
|
519
|
+
*/
|
|
520
|
+
export function askToolOf() {
|
|
521
|
+
return {
|
|
522
|
+
name: ASK_TOOL,
|
|
523
|
+
description: [
|
|
524
|
+
"Ask whoever gave you this task a question you can't answer yourself, and wait for the answer.",
|
|
525
|
+
"Give the question, optionally up to " + ASK_LIMITS.choices + " short choices to pick from, and why you need it. Ask once, with everything you need.",
|
|
526
|
+
].join(" "),
|
|
527
|
+
inputSchema: {
|
|
528
|
+
type: "object",
|
|
529
|
+
properties: {
|
|
530
|
+
question: { type: "string", minLength: 1, description: `The question, at most ${ASK_LIMITS.questionChars} characters.` },
|
|
531
|
+
choices: {
|
|
532
|
+
type: "array",
|
|
533
|
+
maxItems: ASK_LIMITS.choices,
|
|
534
|
+
items: { type: "string", minLength: 1 },
|
|
535
|
+
description: `Answers to pick from, each at most ${ASK_LIMITS.choiceChars} characters; leave it out for a free answer.`,
|
|
536
|
+
},
|
|
537
|
+
why: { type: "string", description: `Why you need the answer, at most ${ASK_LIMITS.whyChars} characters.` },
|
|
538
|
+
},
|
|
539
|
+
required: ["question"],
|
|
540
|
+
additionalProperties: false,
|
|
541
|
+
},
|
|
542
|
+
target: HARNESS,
|
|
543
|
+
};
|
|
544
|
+
}
|
package/dist/folder/compile.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const AGENT_FOLDER_COMPILER = "agent-folder/1";
|
|
|
6
6
|
* The formats this compiler builds: `agent-folder/1`, and `agent-folder/2` (ADR-100), whose
|
|
7
7
|
* folder declares every engine feature it uses (`folder/engine.ts`).
|
|
8
8
|
*/
|
|
9
|
-
export declare const AGENT_FOLDER_FORMATS: readonly ["agent-folder/1", "agent-folder/2"];
|
|
9
|
+
export declare const AGENT_FOLDER_FORMATS: readonly ["agent-folder/1", "agent-folder/2", "agent-folder/3"];
|
|
10
10
|
export type AgentFolderFormat = (typeof AGENT_FOLDER_FORMATS)[number];
|
|
11
11
|
/**
|
|
12
12
|
* What a folder may hold, unless `compileAgentFolder` is given other limits (a Tenant's Runtime
|
|
@@ -77,7 +77,7 @@ export declare const SCHEMA_URLS: {
|
|
|
77
77
|
readonly mcp: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/mcp.json", "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json"];
|
|
78
78
|
readonly flow: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/flow.json"];
|
|
79
79
|
};
|
|
80
|
-
export declare const AGENT_KEYS: readonly ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "engine", "metadata"];
|
|
80
|
+
export declare const AGENT_KEYS: readonly ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "engine", "plugins", "metadata"];
|
|
81
81
|
export declare const TRIGGER_KEYS: readonly ["schedule", "timezone", "at", "webhook", "session"];
|
|
82
82
|
export declare const MCP_KEYS: readonly ["$schema", "mcpServers"];
|
|
83
83
|
export declare const SERVER_KEYS: readonly ["type", "url", "headers"];
|
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
|
+
}
|