@nylorun/core 0.33.0-beta → 0.35.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/compatibility.d.ts +25 -1
  3. package/dist/compatibility.js +24 -0
  4. package/dist/contracts.d.ts +749 -17
  5. package/dist/contracts.js +360 -22
  6. package/dist/define.d.ts +1 -1
  7. package/dist/define.js +1 -1
  8. package/dist/definition/assemble.d.ts +2 -1
  9. package/dist/definition/assemble.js +1 -0
  10. package/dist/definition/from.js +1 -0
  11. package/dist/definition/manifest.d.ts +2 -1
  12. package/dist/definition/manifest.js +1 -0
  13. package/dist/definition/sections.d.ts +1 -1
  14. package/dist/definition/sections.js +5 -1
  15. package/dist/definition/variant.d.ts +16 -1
  16. package/dist/definition/variant.js +81 -3
  17. package/dist/engine/blocks.d.ts +54 -0
  18. package/dist/engine/blocks.js +162 -0
  19. package/dist/engine/explain.d.ts +36 -0
  20. package/dist/engine/explain.js +113 -0
  21. package/dist/engine/features.d.ts +28 -0
  22. package/dist/engine/features.js +34 -0
  23. package/dist/engine/index.d.ts +14 -0
  24. package/dist/engine/index.js +14 -0
  25. package/dist/engine/mcp.d.ts +119 -0
  26. package/dist/engine/mcp.js +267 -0
  27. package/dist/engine/names.d.ts +12 -0
  28. package/dist/engine/names.js +26 -0
  29. package/dist/engine/preview.d.ts +93 -0
  30. package/dist/engine/preview.js +120 -0
  31. package/dist/engine/projection.d.ts +63 -0
  32. package/dist/engine/projection.js +109 -0
  33. package/dist/engine/tools.d.ts +118 -0
  34. package/dist/engine/tools.js +508 -0
  35. package/dist/folder/compile.d.ts +11 -4
  36. package/dist/folder/compile.js +126 -13
  37. package/dist/folder/context.d.ts +5 -0
  38. package/dist/folder/decompile.js +22 -1
  39. package/dist/folder/engine.d.ts +73 -0
  40. package/dist/folder/engine.js +224 -0
  41. package/dist/folder/nested.js +6 -0
  42. package/dist/folder/schemas.js +47 -3
  43. package/dist/harness-api/harness-api.schema.json +29 -7
  44. package/dist/harness-api/json-schema.js +6 -2
  45. package/dist/harness-api/messages.d.ts +4 -2
  46. package/dist/harness-api/messages.js +4 -1
  47. package/dist/harness-api/schema.d.ts +15 -4
  48. package/dist/harness-api/schema.js +20 -4
  49. package/dist/manifest-schemas.js +9 -4
  50. package/dist/schemas/agent-folder/agent-md.schema.json +84 -3
  51. package/dist/schemas/agent-folder/runtime.schema.json +34 -1
  52. package/dist/schemas/agent-manifest.schema.json +166 -1
  53. package/dist/schemas/harness-manifest.schema.json +130 -1
  54. package/dist/schemas/runtime-manifest.schema.json +34 -1
  55. package/dist/types/manifest.d.ts +49 -0
  56. package/package.json +5 -1
@@ -9,8 +9,14 @@ import { parseJson, pointerOf } from "./json.js";
9
9
  import { jsonSchemaIssues } from "./json-schema.js";
10
10
  import { naturalCompare, suggestion, suggestions } from "./suggest.js";
11
11
  import { folderParts, nestedTextPaths, scopedSchema } from "./nested.js";
12
- /** The compiler format this version builds: a folder with no `format`, or `format: 1`. */
12
+ import { ENGINE_TEXT_DIR, compiledEngine, engineBlocksOf, engineDeclarations, folderFormatOf, unusedInstructions, } from "./engine.js";
13
+ /** The compiler format this version builds by default: a folder with no `format`, or `format: 1`. */
13
14
  export const AGENT_FOLDER_COMPILER = "agent-folder/1";
15
+ /**
16
+ * The formats this compiler builds: `agent-folder/1`, and `agent-folder/2` (ADR-100), whose
17
+ * folder declares every engine feature it uses (`folder/engine.ts`).
18
+ */
19
+ export const AGENT_FOLDER_FORMATS = ["agent-folder/1", "agent-folder/2"];
14
20
  /**
15
21
  * What a folder may hold, unless `compileAgentFolder` is given other limits (a Tenant's Runtime
16
22
  * limits `folderFiles`, `folderBytes` and `folderTextFileBytes`, which default to these).
@@ -35,13 +41,20 @@ const AGENT_PLUGINS_MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.sc
35
41
  */
36
42
  export const FOLDER_SCHEMAS = "https://docs.nylorun.com/schemas/agent-folder/v1/";
37
43
  export const SCHEMA_URLS = {
38
- runtime: [`${FOLDER_SCHEMAS}runtime.json`, "https://docs.nylorun.com/schemas/runtime-manifest/v1.json"],
44
+ runtime: [
45
+ `${FOLDER_SCHEMAS}runtime.2.json`,
46
+ `${FOLDER_SCHEMAS}runtime.1.json`,
47
+ `${FOLDER_SCHEMAS}runtime.json`,
48
+ "https://docs.nylorun.com/schemas/runtime-manifest/v1.2.json",
49
+ "https://docs.nylorun.com/schemas/runtime-manifest/v1.1.json",
50
+ "https://docs.nylorun.com/schemas/runtime-manifest/v1.json",
51
+ ],
39
52
  tool: [`${FOLDER_SCHEMAS}tool.json`],
40
53
  mcp: [`${FOLDER_SCHEMAS}mcp.json`, AGENT_PLUGINS_MCP_SCHEMA],
41
54
  flow: [`${FOLDER_SCHEMAS}flow.json`],
42
55
  };
43
56
  const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
44
- export const AGENT_KEYS = ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "metadata"];
57
+ export const AGENT_KEYS = ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "engine", "metadata"];
45
58
  const SKILL_KEYS = ["name", "description", "license", "compatibility", "metadata", "allowed-tools"];
46
59
  export const TRIGGER_KEYS = ["schedule", "timezone", "at", "webhook", "session"];
47
60
  export const MCP_KEYS = ["$schema", "mcpServers"];
@@ -141,6 +154,9 @@ function classify(path) {
141
154
  return base.endsWith(".json") ? { kind: "schema" } : { code: "reserved_directory", error: "schemas/ holds JSON Schema files (.json)" };
142
155
  if (top === ".nylorun")
143
156
  return { kind: "other" };
157
+ // A block's wording, replaced (agent-folder/2, `engine.instructions`): read when it is named.
158
+ if (top === ENGINE_TEXT_DIR && base.endsWith(".md"))
159
+ return { kind: "engine_text" };
144
160
  if (base.endsWith(".schema.json"))
145
161
  return { kind: "schema" };
146
162
  return { kind: "other" };
@@ -160,6 +176,7 @@ export function folderTextPaths(entries) {
160
176
  kind.kind === "trigger" ||
161
177
  kind.kind === "schema" ||
162
178
  kind.kind === "flow" ||
179
+ kind.kind === "engine_text" ||
163
180
  (kind.kind === "skill" && entry.path.split("/").length === 3 && entry.path.endsWith(`/${SKILL_ENTRY}`));
164
181
  if (textual)
165
182
  paths.push(entry.path);
@@ -198,6 +215,8 @@ const show = (value) => JSON.stringify(value) ?? String(value);
198
215
  export function compileAgentFolder(input, scope) {
199
216
  const limits = { ...AGENT_FOLDER_LIMITS, ...input.limits };
200
217
  const diagnostics = [];
218
+ /** The folder's format: the uploaded folder's `format`, which a folder inside it shares. */
219
+ let format = scope?.engineFacts?.format ?? 1;
201
220
  const parsed = new Map();
202
221
  const report = (severity, code, message, file, path, options = {}) => {
203
222
  let at = options.at;
@@ -452,8 +471,10 @@ export function compileAgentFolder(input, scope) {
452
471
  error("description_missing", "description is required: what the agent does, in a sentence", AGENT_FILE, front.description === undefined ? undefined : ["description"]);
453
472
  else
454
473
  description = front.description.trim();
455
- if (front.format !== undefined && front.format !== 1)
456
- error("format_unsupported", `format ${JSON.stringify(front.format)} is not supported: this compiler builds format 1 (${AGENT_FOLDER_COMPILER})`, AGENT_FILE, ["format"]);
474
+ if (!scope && folderFormatOf(front.format) === undefined)
475
+ 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
+ else if (!scope)
477
+ format = folderFormatOf(front.format);
457
478
  if (front.harness !== undefined) {
458
479
  if (HarnessIdSchema.safeParse(front.harness).success)
459
480
  harness.id = front.harness;
@@ -538,6 +559,69 @@ export function compileAgentFolder(input, scope) {
538
559
  checkSchedule(RUNTIME_FILE, ["triggers", id], trigger);
539
560
  }
540
561
  }
562
+ // --- engine: (agent-folder/2, ADR-100; folder/engine.ts) -------------------------------
563
+ /** Whether the session's Agent has a computer: the uploaded folder's runtime kind. */
564
+ const runtimeKind = isObject(runtime) && typeof runtime.kind === "string" ? runtime.kind : "none";
565
+ const computer = scope?.engineFacts ? scope.engineFacts.computer : runtimeKind === "virtual" || runtimeKind === "pod";
566
+ const role = scope?.role === "subagent" ? "subagent" : "root";
567
+ let declared;
568
+ /** The engine text files a block's wording was read from. */
569
+ const engineTexts = new Set();
570
+ if (agent && scope?.role !== "plugin") {
571
+ const migrate = "add format: agent-folder/2 to AGENT.md, or run nylorun migrate folder <dir> --to 2, which writes the declarations that keep what the agent gets today";
572
+ if (format === 1) {
573
+ if (front.engine !== undefined)
574
+ error("engine_format", `engine declares the engine features of an agent-folder/2 folder, and this folder is agent-folder/1, which gets them all by default. Fix: ${migrate}`, AGENT_FILE, ["engine"], {
575
+ key: true,
576
+ });
577
+ if (isObject(front.memory) && front.memory.index !== undefined)
578
+ error("engine_format", `memory.index is a key of agent-folder/2: an agent-folder/1 folder always pins its memory index. Fix: ${migrate}`, AGENT_FILE, ["memory", "index"], {
579
+ key: true,
580
+ });
581
+ }
582
+ else if ([...kinds.values()].includes("flow")) {
583
+ if (front.engine !== undefined)
584
+ error("flow_refused", "engine is an agent's: set it in the AGENT.md of each agent under agents/ that uses an engine feature", AGENT_FILE, ["engine"], { key: true });
585
+ }
586
+ else {
587
+ declared = engineDeclarations(front.engine, {
588
+ error: (code, message, path, options) => error(code, message, AGENT_FILE, path, options),
589
+ computer,
590
+ role,
591
+ ...(scope?.engineFacts?.engine === undefined ? {} : { parent: scope.engineFacts.engine }),
592
+ text: (path, at) => {
593
+ if (kinds.get(path) !== "engine_text") {
594
+ error("engine_text_missing", `${path} is not a file in the folder: write the block's wording there, in Markdown`, AGENT_FILE, at);
595
+ return undefined;
596
+ }
597
+ const text = textOf(path);
598
+ if (text === undefined)
599
+ return undefined;
600
+ engineTexts.add(path);
601
+ const trimmed = trimBlankLines(text);
602
+ if (trimmed === "") {
603
+ error("engine_text_empty", `${path} is empty: write the block's wording, or leave engine.instructions out to keep the engine's`, path);
604
+ return undefined;
605
+ }
606
+ return trimmed;
607
+ },
608
+ });
609
+ if (declared && !scope && computer && (declared.engine.sandbox ?? []).length === 0)
610
+ 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
+ origins.push([["harness", "engine"], { file: AGENT_FILE, path: ["engine"] }]);
612
+ }
613
+ }
614
+ for (const [path, kind] of kinds)
615
+ if (kind === "engine_text" && !engineTexts.has(path) && !(declared && Object.values(declared.sources).includes(path)))
616
+ report("note", "file_not_compiled", "Kept with the source; not part of the agent", path);
617
+ /** What a folder inside this one knows of it (folder/nested.ts). */
618
+ const engineFacts = () => scope?.engineFacts ?? {
619
+ format,
620
+ computer,
621
+ ...(format === 2 && declared ? { engine: declared.engine } : {}),
622
+ memory: isObject(front.memory),
623
+ selfWake: isObject(runtime) && runtime.selfWake === true,
624
+ };
541
625
  const derivedSlots = new Map();
542
626
  /**
543
627
  * A slot for `credential`, derived when runtime.json does not declare it. `at` places it in a
@@ -585,6 +669,7 @@ export function compileAgentFolder(input, scope) {
585
669
  suggest: suggestion,
586
670
  compile: compileAgentFolder,
587
671
  folderTextPaths,
672
+ engineFacts,
588
673
  });
589
674
  // --- mcp.json --------------------------------------------------------------------------
590
675
  const servers = {};
@@ -931,7 +1016,35 @@ export function compileAgentFolder(input, scope) {
931
1016
  seeded[path.slice("files/".length)] = `sha256:${byPath.get(path).sha256}`;
932
1017
  // --- agents/, flow.json and plugins/ (folder/nested.ts) ----------------------------------
933
1018
  if (!parts.compose())
934
- return finish(diagnostics);
1019
+ return finish(format, diagnostics);
1020
+ // --- The engine blocks the agent gets (agent-folder/2) ------------------------------------
1021
+ if (declared && harness.kind !== "workflow") {
1022
+ const facts = engineFacts();
1023
+ const loop = isObject(harness.loop) && (harness.id === undefined || harness.id === DEFAULT_HARNESS) ? harness.loop : {};
1024
+ const memory = isObject(harness.memory) ? harness.memory : undefined;
1025
+ const names = engineBlocksOf({
1026
+ engine: declared.engine,
1027
+ ...(Array.isArray(harness.tools) ? { tools: harness.tools } : {}),
1028
+ ...(isObject(harness.skills) ? { skills: harness.skills } : {}),
1029
+ ...(isObject(harness.mcpServers) ? { mcpServers: harness.mcpServers } : {}),
1030
+ }, {
1031
+ computer,
1032
+ selfWake: facts.selfWake,
1033
+ ...(role === "root"
1034
+ ? memory
1035
+ ? { memory: { root: true, ...(memory.access === "read_only" ? { access: "read_only" } : {}), index: memory.index !== false } }
1036
+ : {}
1037
+ : facts.memory
1038
+ ? { memory: { root: false } }
1039
+ : {}),
1040
+ plan: role === "root" && loop.plan === true,
1041
+ connections: role === "root" && loop.connections === true,
1042
+ triggers: role === "root" && declared.engine.triggers === true,
1043
+ });
1044
+ for (const name of unusedInstructions(declared.engine, names))
1045
+ 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 });
1046
+ harness.engine = compiledEngine(declared.engine, names, declared.sources);
1047
+ }
935
1048
  // --- The runtime section -----------------------------------------------------------------
936
1049
  const needsRuntime = derivedSlots.size > 0 || Object.keys(triggers).length > 0 || Object.keys(seeded).length > 0;
937
1050
  if (!runtime && needsRuntime)
@@ -952,7 +1065,7 @@ export function compileAgentFolder(input, scope) {
952
1065
  }
953
1066
  // --- Every field checked as the Runtime checks the manifest ------------------------------
954
1067
  if (diagnostics.some((item) => item.severity === "error") || name === undefined || description === undefined)
955
- return finish(diagnostics);
1068
+ return finish(format, diagnostics);
956
1069
  const document = {
957
1070
  manifestSchemaVersion: AGENT_MANIFEST_V8_SCHEMA_VERSION,
958
1071
  name,
@@ -988,10 +1101,10 @@ export function compileAgentFolder(input, scope) {
988
1101
  continue;
989
1102
  place(issue, [], fromOrigins);
990
1103
  }
991
- return finish(diagnostics);
1104
+ return finish(format, diagnostics);
992
1105
  }
993
1106
  if (diagnostics.some((item) => item.severity === "error"))
994
- return finish(diagnostics);
1107
+ return finish(format, diagnostics);
995
1108
  const manifest = checked.data;
996
1109
  // --- What the Runtime checks at save, where it needs no Tenant ---------------------------
997
1110
  const hasRuntimeFile = byPath.has(RUNTIME_FILE);
@@ -1029,8 +1142,8 @@ export function compileAgentFolder(input, scope) {
1029
1142
  : `${field} ${POD_ONLY[field]}`, RUNTIME_FILE, [field], { key: true, pointer: pointerOf(["runtime", field]) });
1030
1143
  }
1031
1144
  if (diagnostics.some((item) => item.severity === "error"))
1032
- return finish(diagnostics);
1033
- return finish(diagnostics, manifest);
1145
+ return finish(format, diagnostics);
1146
+ return finish(format, diagnostics, manifest);
1034
1147
  /** A schema issue in the compiler's words, at the file and field that wrote it. */
1035
1148
  function place(issue, base, where) {
1036
1149
  const full = [...base, ...issue.path];
@@ -1187,13 +1300,13 @@ function issueMessage(issue, field, value) {
1187
1300
  return `${named} does not fit any form it can take`;
1188
1301
  }
1189
1302
  }
1190
- function finish(diagnostics, manifest) {
1303
+ function finish(format, diagnostics, manifest) {
1191
1304
  const order = { error: 0, warning: 1, info: 2, note: 3 };
1192
1305
  const sorted = [...diagnostics].sort((a, b) => order[a.severity] - order[b.severity] ||
1193
1306
  compare(a.file ?? "", b.file ?? "") ||
1194
1307
  (a.line ?? 0) - (b.line ?? 0) ||
1195
1308
  (a.column ?? 0) - (b.column ?? 0));
1196
- return { ...(manifest === undefined ? {} : { manifest }), diagnostics: sorted, compiler: AGENT_FOLDER_COMPILER };
1309
+ return { ...(manifest === undefined ? {} : { manifest }), diagnostics: sorted, compiler: AGENT_FOLDER_FORMATS[format - 1] };
1197
1310
  }
1198
1311
  /** The closest recorded position for `path` in `file`: the field, else its nearest parent. */
1199
1312
  function locate(file, path) {
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { AgentFolderDiagnostic, AgentFolderEntry, AgentFolderFix, CompileAgentFolderInput, CompiledAgentFolder } from "./compile.js";
8
8
  import { type Position } from "./json.js";
9
+ import type { EngineScopeFacts } from "./engine.js";
9
10
  /** A JSON Schema named by `/x` from a folder inside another: found, refused, or already reported. */
10
11
  export type SchemaLookup = {
11
12
  readonly schema: Record<string, unknown>;
@@ -23,6 +24,8 @@ export interface FolderScope {
23
24
  readonly deriveSlot: (credential: string, type: "bearer" | "headers", url: string, file: string, at: Position | undefined, header?: string) => void;
24
25
  /** `/x`: a JSON Schema file of the uploaded folder, by its path there. */
25
26
  readonly schema: (target: string) => SchemaLookup;
27
+ /** The uploaded folder's format, computer and engine declarations (agent-folder/2, `engine.ts`). */
28
+ readonly engineFacts?: EngineScopeFacts;
26
29
  }
27
30
  /** What a loop manifest embeds for an agent of a flow: agent manifest v7 or workflow manifest v3. */
28
31
  export type EmbeddedAgent = Record<string, unknown>;
@@ -78,6 +81,8 @@ export interface FolderContext {
78
81
  readonly suggest: (name: string, known: readonly string[]) => string | undefined;
79
82
  readonly compile: (input: CompileAgentFolderInput, scope?: FolderScope) => CompiledAgentFolder;
80
83
  readonly folderTextPaths: (entries: readonly AgentFolderEntry[]) => string[];
84
+ /** What a folder inside this one knows of it: its format, computer and engine declarations. */
85
+ readonly engineFacts: () => EngineScopeFacts;
81
86
  }
82
87
  export declare const isObject: (value: unknown) => value is Record<string, unknown>;
83
88
  export declare const compare: (a: string, b: string) => -1 | 0 | 1;
@@ -6,7 +6,8 @@
6
6
  *
7
7
  * Each manifest field goes where the compiler reads it:
8
8
  *
9
- * - `name`, `description`, `metadata`, `harness.id`, `memory`, `loop`, `model`, and this agent's
9
+ * - `name`, `description`, `metadata`, `harness.id`, `memory`, `loop`, `model`, `engine` (with
10
+ * `format: agent-folder/2`; each replaced wording as `engine/<block>.md`), and this agent's
10
11
  * server and skill settings: `AGENT.md` frontmatter. `harness.outputSchema`:
11
12
  * `output.schema.json`, named by `outputSchema`.
12
13
  * - `harness.instructions`: the first as `AGENT.md`'s body, each other as
@@ -108,6 +109,7 @@ export function folderOfManifest(manifest, options = {}) {
108
109
  };
109
110
  const identity = { name: manifest.name, description: manifest.description, metadata: manifest.metadata };
110
111
  const root = { prefix: "", role: "root" };
112
+ writer.declares = !isWorkflow(manifest.harness) && manifest.harness.engine !== undefined;
111
113
  if (isWorkflow(manifest.harness))
112
114
  writeFlow(writer, root, identity, manifest.harness);
113
115
  else
@@ -272,6 +274,25 @@ function writeAgent(writer, place, identity, harness) {
272
274
  else
273
275
  note("harness.loop is not a map, which AGENT.md needs: it is left out.");
274
276
  }
277
+ // agent-folder/2 (ADR-100): the declarations, each replaced wording a file under engine/. The
278
+ // blocks are the compiler's to list again.
279
+ if (harness.engine !== undefined && !root && !writer.declares)
280
+ note("The subagent declares its engine features and the manifest does not: an agent-folder/1 folder cannot say so, so it gets the defaults.");
281
+ else if (harness.engine !== undefined) {
282
+ if (root)
283
+ front.format = "agent-folder/2";
284
+ const { instructions, blocks: _, ...declared } = harness.engine;
285
+ const engine = { ...declared };
286
+ for (const [block, text] of Object.entries(instructions ?? {})) {
287
+ const file = `engine/${block}.md`;
288
+ files.set(at + file, `${text}\n`);
289
+ engine.instructions = { ...engine.instructions, [block]: file };
290
+ }
291
+ if (Object.keys(engine).length > 0)
292
+ front.engine = engine;
293
+ }
294
+ else if (!root && writer.declares)
295
+ note("The subagent declares no engine features, and in an agent-folder/2 folder it gets none: it is written as such.");
275
296
  if (identity.metadata !== undefined) {
276
297
  if (isObject(identity.metadata))
277
298
  front.metadata = identity.metadata;
@@ -0,0 +1,73 @@
1
+ import { type EngineBlockName } from "../engine/names.js";
2
+ import type { HarnessEngine, SkillManifest, ToolManifest } from "../types/manifest.js";
3
+ import type { ReportOptions } from "./context.js";
4
+ /** The keys of `AGENT.md`'s `engine:` block. */
5
+ export declare const ENGINE_KEYS: readonly ["sandbox", "artifacts", "outputs", "toolSearch", "triggers", "instructions"];
6
+ /** Where a folder keeps the files that replace a block's wording. */
7
+ export declare const ENGINE_TEXT_DIR = "engine";
8
+ /** A folder's format: 1 (`agent-folder/1`, the default) or 2 (`agent-folder/2`); undefined when it is neither. */
9
+ export declare function folderFormatOf(value: unknown): 1 | 2 | undefined;
10
+ /** What a folder inside another needs to know of the folder that holds it. */
11
+ export interface EngineScopeFacts {
12
+ readonly format: 1 | 2;
13
+ /** The uploaded folder's runtime has a computer (kind `virtual` or `pod`). */
14
+ readonly computer: boolean;
15
+ /** The root agent's declarations, under format 2: a subagent's are a subset. */
16
+ readonly engine?: HarnessEngine;
17
+ /** The root agent has memory: a subagent may view it. */
18
+ readonly memory: boolean;
19
+ /** The uploaded folder's runtime sets `selfWake`. */
20
+ readonly selfWake: boolean;
21
+ }
22
+ type Fail = (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
23
+ /**
24
+ * `AGENT.md`'s `engine:` block, checked: the declarations, with each replaced wording read from
25
+ * its file (`text`), and the files they came from (`sources`). Undefined, with the errors
26
+ * reported, when it is not one. `parent` is a subagent's parent's declarations.
27
+ */
28
+ export declare function engineDeclarations(value: unknown, options: {
29
+ readonly error: Fail;
30
+ readonly computer: boolean;
31
+ readonly role: "root" | "subagent";
32
+ readonly parent?: HarnessEngine;
33
+ /** The text of a file of the folder that replaces a block's wording, or undefined after reporting why not. */
34
+ readonly text: (path: string, at: readonly PropertyKey[]) => string | undefined;
35
+ }): {
36
+ engine: HarnessEngine;
37
+ sources: Partial<Record<EngineBlockName, string>>;
38
+ } | undefined;
39
+ /**
40
+ * The text blocks an agent gets, from what it declares and what the folder says of its session:
41
+ * whether its runtime has a computer and sets `selfWake`, its skills, memory and loop settings,
42
+ * whether it is the root agent declaring `engine.triggers`, and whether its MCP tools may be
43
+ * deferred. The harness's own projection decides them
44
+ * (`engineProjection`), so the list is what a session's system text holds.
45
+ */
46
+ export declare function engineBlocksOf(agent: {
47
+ readonly engine: HarnessEngine;
48
+ readonly tools?: readonly ToolManifest[];
49
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
50
+ readonly mcpServers?: Readonly<Record<string, {
51
+ readonly deferred?: boolean;
52
+ readonly tools?: Readonly<Record<string, {
53
+ readonly deferred?: boolean;
54
+ }>>;
55
+ }>>;
56
+ }, facts: {
57
+ readonly computer: boolean;
58
+ readonly selfWake: boolean;
59
+ readonly memory?: {
60
+ readonly root: boolean;
61
+ readonly access?: "read_write" | "read_only";
62
+ readonly index?: boolean;
63
+ };
64
+ readonly plan: boolean;
65
+ readonly connections: boolean;
66
+ /** The root agent declares `engine.triggers` (D83). */
67
+ readonly triggers?: boolean;
68
+ }): EngineBlockName[];
69
+ /** `harness.engine` as the compiled manifest holds it: the declarations, then the blocks. */
70
+ export declare function compiledEngine(engine: HarnessEngine, blocks: readonly EngineBlockName[], sources: Partial<Record<EngineBlockName, string>>): HarnessEngine;
71
+ /** The blocks whose wording `engine` replaces that the agent does not get. */
72
+ export declare function unusedInstructions(engine: HarnessEngine, blocks: readonly EngineBlockName[]): EngineBlockName[];
73
+ export {};
@@ -0,0 +1,224 @@
1
+ /**
2
+ * `agent-folder/2` (ADR-100): a folder declares every engine feature it uses, and our engine adds
3
+ * nothing else. `AGENT.md` names the format (`format: agent-folder/2`, or `2`) and, in its
4
+ * `engine:` block, the features no other key declares:
5
+ *
6
+ * ```yaml
7
+ * format: agent-folder/2
8
+ * memory: { access: read_write, index: true } # index can be turned off
9
+ * engine:
10
+ * sandbox: [bash, read, write, edit, grep, glob] # any subset; needs a computer in runtime.json
11
+ * artifacts: { read: true, save: false } # save needs a computer
12
+ * outputs: true # save /workspace/outputs when a turn ends; needs a computer
13
+ * toolSearch: false # no automatic deferral; a server's own `deferred` still applies
14
+ * triggers: true # the triggers tool and its text (D83); the root agent's only
15
+ * instructions: # a block's wording, replaced by a file under engine/
16
+ * memory: engine/memory.md
17
+ * ```
18
+ *
19
+ * The compiled manifest's `harness.engine` holds the declarations, each replaced wording's text,
20
+ * and the text blocks the agent gets (`blocks`), each with its version and hash, so an engine
21
+ * release that changes a block changes the version's hash. A subagent (`agents/<id>/`) declares
22
+ * its own `engine:` block, a subset of its parent's; without one it gets no engine feature.
23
+ */
24
+ import { SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE } from "../utils/sandbox.js";
25
+ import { ENGINE_BLOCK_NAMES, isEngineBlockName } from "../engine/names.js";
26
+ import { blockRefs } from "../engine/blocks.js";
27
+ import { DEFAULT_ENGINE_TOOL_LIMITS, engineProjection } from "../engine/projection.js";
28
+ import { TOOL_SEARCH_TOOL } from "../engine/tools.js";
29
+ import { suggestion } from "./suggest.js";
30
+ /** The keys of `AGENT.md`'s `engine:` block. */
31
+ export const ENGINE_KEYS = ["sandbox", "artifacts", "outputs", "toolSearch", "triggers", "instructions"];
32
+ const ARTIFACT_KEYS = ["read", "save"];
33
+ /** Where a folder keeps the files that replace a block's wording. */
34
+ export const ENGINE_TEXT_DIR = "engine";
35
+ /** A folder's format: 1 (`agent-folder/1`, the default) or 2 (`agent-folder/2`); undefined when it is neither. */
36
+ export function folderFormatOf(value) {
37
+ if (value === undefined || value === 1 || value === "agent-folder/1")
38
+ return 1;
39
+ if (value === 2 || value === "agent-folder/2")
40
+ return 2;
41
+ return undefined;
42
+ }
43
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
44
+ /**
45
+ * `AGENT.md`'s `engine:` block, checked: the declarations, with each replaced wording read from
46
+ * its file (`text`), and the files they came from (`sources`). Undefined, with the errors
47
+ * reported, when it is not one. `parent` is a subagent's parent's declarations.
48
+ */
49
+ export function engineDeclarations(value, options) {
50
+ const { error, computer, role, parent } = options;
51
+ const sources = {};
52
+ if (value === undefined)
53
+ return { engine: {}, sources };
54
+ if (!isObject(value)) {
55
+ error("value_invalid", `engine is a map of the engine features the agent uses: ${ENGINE_KEYS.join(", ")}`, ["engine"]);
56
+ return undefined;
57
+ }
58
+ let valid = true;
59
+ const fail = (...args) => {
60
+ valid = false;
61
+ error(...args);
62
+ };
63
+ const needsComputer = (what, path) => fail("engine_needs_computer", `${what} needs a computer, and the runtime has none. Fix: set "kind": "virtual" (or "pod") in runtime.json, or leave it out`, path);
64
+ const subset = (what, path) => fail("engine_subset", `${what}, and the agent that holds this subagent does not: a subagent's engine block is a subset of its parent's`, path);
65
+ for (const key of Object.keys(value))
66
+ if (!ENGINE_KEYS.includes(key)) {
67
+ const close = suggestion(key, ENGINE_KEYS);
68
+ fail("unknown_key", `Unknown key '${key}'.${close ? ` Did you mean '${close}'?` : ` Known keys: ${ENGINE_KEYS.join(", ")}.`}`, ["engine", key], {
69
+ key: true,
70
+ rename: ENGINE_KEYS,
71
+ });
72
+ }
73
+ const engine = {};
74
+ // sandbox: any of the six, each once.
75
+ if (value.sandbox !== undefined) {
76
+ const at = ["engine", "sandbox"];
77
+ if (!Array.isArray(value.sandbox) || !value.sandbox.every((item) => typeof item === "string"))
78
+ fail("value_invalid", `engine.sandbox is a list of sandbox tools: any of ${SANDBOX_TOOL_NAMES.join(", ")}`, at);
79
+ else {
80
+ const names = [];
81
+ for (const [index, name] of value.sandbox.entries()) {
82
+ if (!SANDBOX_TOOL_NAMES.includes(name)) {
83
+ const close = suggestion(name, SANDBOX_TOOL_NAMES);
84
+ fail("value_invalid", `${name} is not a sandbox tool: ${SANDBOX_TOOL_NAMES.join(", ")}.${close ? ` Did you mean '${close}'?` : ""}`, [...at, index]);
85
+ }
86
+ else if (names.includes(name))
87
+ fail("value_invalid", `engine.sandbox names ${name} twice`, [...at, index]);
88
+ else
89
+ names.push(name);
90
+ }
91
+ if (names.length > 0 && !computer)
92
+ needsComputer("engine.sandbox", at);
93
+ const outside = names.filter((name) => parent !== undefined && !(parent.sandbox ?? []).includes(name));
94
+ if (role === "subagent" && outside.length > 0)
95
+ subset(`engine.sandbox names ${outside.join(", ")}`, at);
96
+ engine.sandbox = SANDBOX_TOOL_NAMES.filter((name) => names.includes(name));
97
+ }
98
+ }
99
+ if (value.artifacts !== undefined) {
100
+ const at = ["engine", "artifacts"];
101
+ if (!isObject(value.artifacts))
102
+ fail("value_invalid", "engine.artifacts is a map: read and save, each true or false", at);
103
+ else {
104
+ const artifacts = {};
105
+ for (const [key, flag] of Object.entries(value.artifacts)) {
106
+ if (!ARTIFACT_KEYS.includes(key)) {
107
+ fail("unknown_key", `Unknown key '${key}'. Known keys: read, save.`, [...at, key], { key: true, rename: ARTIFACT_KEYS });
108
+ continue;
109
+ }
110
+ if (typeof flag !== "boolean") {
111
+ fail("value_invalid", `engine.artifacts.${key} is true or false`, [...at, key]);
112
+ continue;
113
+ }
114
+ artifacts[key] = flag;
115
+ }
116
+ if (artifacts.save === true && !computer)
117
+ needsComputer("engine.artifacts.save (save_artifact saves a file of the sandbox)", [...at, "save"]);
118
+ if (role === "subagent" && artifacts.read === true && parent?.artifacts?.read !== true)
119
+ subset("engine.artifacts.read is true", [...at, "read"]);
120
+ if (role === "subagent" && artifacts.save === true && parent?.artifacts?.save !== true)
121
+ subset("engine.artifacts.save is true", [...at, "save"]);
122
+ engine.artifacts = artifacts;
123
+ }
124
+ }
125
+ if (value.outputs !== undefined) {
126
+ const at = ["engine", "outputs"];
127
+ if (typeof value.outputs !== "boolean")
128
+ fail("value_invalid", `engine.outputs is true or false: true saves ${SANDBOX_WORKSPACE}/outputs when a turn ends`, at);
129
+ // A subagent shares its parent's sandbox: with outputs, it is told of the folder its parent's
130
+ // turn saves.
131
+ else if (role === "subagent" && value.outputs && parent?.outputs !== true)
132
+ subset("engine.outputs is true", at);
133
+ else {
134
+ if (value.outputs && !computer)
135
+ needsComputer(`engine.outputs (${SANDBOX_WORKSPACE}/outputs is a folder of the sandbox)`, at);
136
+ engine.outputs = value.outputs;
137
+ }
138
+ }
139
+ if (value.toolSearch !== undefined) {
140
+ const at = ["engine", "toolSearch"];
141
+ if (typeof value.toolSearch !== "boolean")
142
+ fail("value_invalid", "engine.toolSearch is true or false: true defers MCP tools behind tool_search past the threshold", at);
143
+ else {
144
+ if (role === "subagent" && value.toolSearch && parent?.toolSearch !== true)
145
+ subset("engine.toolSearch is true", at);
146
+ engine.toolSearch = value.toolSearch;
147
+ }
148
+ }
149
+ // triggers: the root agent's (D83). A subagent whose parent declares them is refused in
150
+ // `nested.ts`; one whose parent does not, here.
151
+ if (value.triggers !== undefined) {
152
+ const at = ["engine", "triggers"];
153
+ if (typeof value.triggers !== "boolean")
154
+ fail("value_invalid", "engine.triggers is true or false: true offers the agent the triggers tool, to set up its own schedules and follow-ups", at);
155
+ else {
156
+ if (role === "subagent" && value.triggers && parent?.triggers !== true)
157
+ subset("engine.triggers is true", at);
158
+ engine.triggers = value.triggers;
159
+ }
160
+ }
161
+ if (value.instructions !== undefined) {
162
+ const at = ["engine", "instructions"];
163
+ if (!isObject(value.instructions))
164
+ fail("value_invalid", `engine.instructions is a map of block names to Markdown files under ${ENGINE_TEXT_DIR}/: ${ENGINE_BLOCK_NAMES.join(", ")}`, at);
165
+ else {
166
+ const texts = {};
167
+ for (const [block, path] of Object.entries(value.instructions)) {
168
+ if (!isEngineBlockName(block)) {
169
+ const close = suggestion(block, ENGINE_BLOCK_NAMES);
170
+ fail("unknown_key", `${block} is not an engine text block.${close ? ` Did you mean '${close}'?` : ` The blocks are ${ENGINE_BLOCK_NAMES.join(", ")}.`}`, [...at, block], {
171
+ key: true,
172
+ rename: ENGINE_BLOCK_NAMES,
173
+ });
174
+ continue;
175
+ }
176
+ if (typeof path !== "string" || path === "") {
177
+ fail("value_invalid", `engine.instructions.${block} is the path of a Markdown file under ${ENGINE_TEXT_DIR}/, such as ${ENGINE_TEXT_DIR}/${block}.md`, [...at, block]);
178
+ continue;
179
+ }
180
+ const relative = path.replace(/^\.\//, "");
181
+ if (!relative.startsWith(`${ENGINE_TEXT_DIR}/`) || !relative.endsWith(".md")) {
182
+ fail("value_invalid", `engine.instructions.${block} names ${path}: a block's wording is a Markdown file under ${ENGINE_TEXT_DIR}/, such as ${ENGINE_TEXT_DIR}/${block}.md`, [...at, block]);
183
+ continue;
184
+ }
185
+ const text = options.text(relative, [...at, block]);
186
+ if (text === undefined) {
187
+ valid = false;
188
+ continue;
189
+ }
190
+ texts[block] = text;
191
+ sources[block] = relative;
192
+ }
193
+ if (Object.keys(texts).length > 0)
194
+ engine.instructions = texts;
195
+ }
196
+ }
197
+ return valid ? { engine, sources } : undefined;
198
+ }
199
+ /**
200
+ * The text blocks an agent gets, from what it declares and what the folder says of its session:
201
+ * whether its runtime has a computer and sets `selfWake`, its skills, memory and loop settings,
202
+ * whether it is the root agent declaring `engine.triggers`, and whether its MCP tools may be
203
+ * deferred. The harness's own projection decides them
204
+ * (`engineProjection`), so the list is what a session's system text holds.
205
+ */
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);
208
+ const names = projection.blocks.map((block) => block.name);
209
+ const servers = Object.values(agent.mcpServers ?? {});
210
+ const deferrable = servers.length > 0 &&
211
+ (agent.engine.toolSearch === true ||
212
+ servers.some((server) => server.deferred === true || Object.values(server.tools ?? {}).some((tool) => tool.deferred === true)));
213
+ if (deferrable && !(agent.tools ?? []).some((tool) => tool.name === TOOL_SEARCH_TOOL))
214
+ names.push("tool_search");
215
+ return names;
216
+ }
217
+ /** `harness.engine` as the compiled manifest holds it: the declarations, then the blocks. */
218
+ export function compiledEngine(engine, blocks, sources) {
219
+ return { ...engine, blocks: blockRefs(blocks, engine, sources) };
220
+ }
221
+ /** The blocks whose wording `engine` replaces that the agent does not get. */
222
+ export function unusedInstructions(engine, blocks) {
223
+ return Object.keys(engine.instructions ?? {}).filter((name) => !blocks.includes(name));
224
+ }
@@ -128,6 +128,7 @@ function innerScope(ctx, prefix, role, namespace) {
128
128
  ...(namespace === undefined ? {} : { namespace }),
129
129
  deriveSlot: (credential, type, url, file, at, header) => ctx.deriveSlot(credential, type, url, prefix + file, [], header, at),
130
130
  schema: ctx.scope?.schema ?? rootSchema(ctx),
131
+ engineFacts: ctx.engineFacts(),
131
132
  };
132
133
  }
133
134
  /** `/x` read from the uploaded folder: a JSON Schema file anywhere in it. */
@@ -196,6 +197,11 @@ function nestedChecks(ctx) {
196
197
  for (const [key, message] of Object.entries(keys))
197
198
  if (ctx.front[key] !== undefined)
198
199
  refuse(message, AGENT_FILE, [key]);
200
+ // Triggers are the root agent's (D83): a subagent of a parent without them fails engine_subset.
201
+ if (isObject(ctx.front.engine) &&
202
+ ctx.front.engine.triggers === true &&
203
+ (ctx.scope.role === "stage" || ctx.scope.engineFacts?.engine?.triggers === true))
204
+ refuse(`triggers are the root agent's: ${what} never sets up triggers, so leave engine.triggers out here`, AGENT_FILE, ["engine", "triggers"]);
199
205
  // Agent manifest v7, which embeds an agent, has no place for a credential or a skill's secrets.
200
206
  const settings = isObject(ctx.front.mcpServers) ? ctx.front.mcpServers : {};
201
207
  for (const [key, server] of Object.entries(isObject(ctx.harness.mcpServers) ? ctx.harness.mcpServers : {})) {