@nylorun/core 0.52.0-beta → 0.54.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 (83) hide show
  1. package/CHANGELOG.md +119 -98
  2. package/dist/compatibility.d.ts +39 -12
  3. package/dist/compatibility.js +37 -10
  4. package/dist/contracts.d.ts +126 -44
  5. package/dist/contracts.js +127 -69
  6. package/dist/define.d.ts +2 -2
  7. package/dist/define.js +1 -1
  8. package/dist/definition/bound.d.ts +3 -1
  9. package/dist/definition/declaration.js +1 -0
  10. package/dist/definition/delegate.d.ts +7 -4
  11. package/dist/definition/delegate.js +4 -3
  12. package/dist/definition/from.js +3 -1
  13. package/dist/definition/manifest.js +7 -1
  14. package/dist/definition/sections.d.ts +9 -8
  15. package/dist/definition/sections.js +13 -5
  16. package/dist/definition/variant.d.ts +2 -2
  17. package/dist/definition/variant.js +4 -4
  18. package/dist/definition/workflow/runnable.d.ts +1 -1
  19. package/dist/definition/workflow/runnable.js +1 -1
  20. package/dist/definition/workflow/verdict.d.ts +1 -1
  21. package/dist/definition/workflow/verdict.js +1 -1
  22. package/dist/engine/blocks.d.ts +2 -2
  23. package/dist/engine/blocks.js +3 -3
  24. package/dist/engine/explain.d.ts +1 -1
  25. package/dist/engine/explain.js +3 -3
  26. package/dist/engine/features.d.ts +1 -1
  27. package/dist/engine/features.js +1 -1
  28. package/dist/engine/index.d.ts +1 -1
  29. package/dist/engine/index.js +1 -1
  30. package/dist/engine/mcp.d.ts +4 -4
  31. package/dist/engine/mcp.js +4 -4
  32. package/dist/engine/names.d.ts +1 -1
  33. package/dist/engine/names.js +1 -1
  34. package/dist/engine/preview.d.ts +2 -2
  35. package/dist/engine/preview.js +1 -1
  36. package/dist/engine/projection.d.ts +3 -3
  37. package/dist/engine/projection.js +8 -8
  38. package/dist/engine/tools.d.ts +8 -8
  39. package/dist/engine/tools.js +7 -7
  40. package/dist/errors.d.ts +1 -1
  41. package/dist/folder/compile.d.ts +2 -2
  42. package/dist/folder/compile.js +111 -15
  43. package/dist/folder/decompile.js +7 -7
  44. package/dist/folder/engine.d.ts +8 -2
  45. package/dist/folder/engine.js +3 -3
  46. package/dist/folder/fix.js +1 -1
  47. package/dist/folder/flow.d.ts +1 -1
  48. package/dist/folder/flow.js +1 -1
  49. package/dist/folder/index.d.ts +4 -2
  50. package/dist/folder/index.js +4 -2
  51. package/dist/folder/migrate-v3.js +2 -2
  52. package/dist/folder/migrate-v4.d.ts +33 -0
  53. package/dist/folder/migrate-v4.js +207 -0
  54. package/dist/folder/nested.js +14 -6
  55. package/dist/folder/plugins.d.ts +13 -1
  56. package/dist/folder/plugins.js +49 -12
  57. package/dist/folder/schemas.js +29 -9
  58. package/dist/folder/subagent-files.d.ts +110 -0
  59. package/dist/folder/subagent-files.js +514 -0
  60. package/dist/folder/v3.d.ts +2 -2
  61. package/dist/folder/v3.js +2 -2
  62. package/dist/harness-api/artifacts.d.ts +1 -1
  63. package/dist/harness-api/json-schema.js +6 -6
  64. package/dist/harness-api/messages.d.ts +1 -1
  65. package/dist/harness-api/messages.js +1 -1
  66. package/dist/harness-api/schema.d.ts +2 -2
  67. package/dist/harness-api/schema.js +8 -8
  68. package/dist/manifest-schemas.js +9 -6
  69. package/dist/plugins/index.js +1 -1
  70. package/dist/schemas/agent-folder/agent-md.schema.json +67 -18
  71. package/dist/schemas/agent-manifest.schema.json +65 -2
  72. package/dist/schemas/harness-manifest.schema.json +55 -2
  73. package/dist/types/manifest.d.ts +32 -7
  74. package/dist/types/model.d.ts +3 -3
  75. package/dist/types/observe.d.ts +1 -1
  76. package/dist/types/part.d.ts +5 -3
  77. package/dist/types/transcript.d.ts +1 -1
  78. package/dist/utils/definition-files.d.ts +23 -0
  79. package/dist/utils/definition-files.js +50 -4
  80. package/dist/utils/memory.js +1 -1
  81. package/dist/utils/runtime-limits.d.ts +2 -2
  82. package/dist/utils/runtime-limits.js +3 -3
  83. package/package.json +1 -1
@@ -18,7 +18,7 @@ export const DEFAULT_ENGINE_TOOL_LIMITS = Object.freeze({
18
18
  * which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
19
19
  * the version sets `harness.loop.plan`; `connections` offers `request_connection` alike
20
20
  * (`harness.loop.connections`). An agent whose own tools name one of them keeps its own.
21
- * `triggers` offers the `triggers` tool and its text (D83): true for the session's root agent when
21
+ * `triggers` offers the `triggers` tool and its text: true for the session's root agent when
22
22
  * the version declares `harness.engine.triggers` (`turn.start.agent.triggers`). What the agent
23
23
  * declares (`agent.engine`) decides the rest; a block it replaces is in its words.
24
24
  */
@@ -60,25 +60,25 @@ export function engineProjection(agent, runsOn, options, memory, plan = false, c
60
60
  use("artifacts_read");
61
61
  instructions.push(text("artifacts_read", ARTIFACTS_READ_TEXT));
62
62
  }
63
- // A session that may book its own next turn (track T4, D77).
63
+ // A session that may book its own next turn.
64
64
  const wake = runsOn?.selfWake === true;
65
65
  if (wake) {
66
66
  use("wake");
67
67
  instructions.push(text("wake", WAKE_TEXT));
68
68
  }
69
- // The triggers the agent sets up itself (D83): the root agent's, when the version declares them.
69
+ // The triggers the agent sets up itself: the root agent's, when the version declares them.
70
70
  const own = (name) => (agent.tools ?? []).some((tool) => tool.name === name);
71
71
  const triggering = triggers && !own(TRIGGERS_TOOL);
72
72
  if (triggering) {
73
73
  use("triggers");
74
74
  instructions.push(text("triggers", TRIGGERS_TEXT));
75
75
  }
76
- // The Agent's memory (track T5, D72).
76
+ // The Agent's memory.
77
77
  const writes = memory !== undefined && memory.root && memory.access === "read_write";
78
78
  if (memory) {
79
79
  use("memory");
80
80
  const own = replaced.memory;
81
- // The rule that text from outside is data stays, whatever the folder's wording (ADR-100).
81
+ // The rule that text from outside is data stays, whatever the folder's wording.
82
82
  const rules = own === undefined ? memoryRules(writes, memory.index !== false) : `${own}\n${writes ? MEMORY_DATA_RULE : MEMORY_READ_ONLY_DATA_RULE}`;
83
83
  instructions.push([rules, ...(memory.instructions ? [`Memory instructions for this agent:\n${memory.instructions}`] : [])].join("\n\n"));
84
84
  }
@@ -110,7 +110,7 @@ export function engineProjection(agent, runsOn, options, memory, plan = false, c
110
110
  features,
111
111
  };
112
112
  }
113
- /** The first line of server `nylorun`'s text (ADR-106). */
113
+ /** The first line of server `nylorun`'s text. */
114
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
115
  /** A sandbox section's network sentence: the hosts the runtime allows, or the policy note. */
116
116
  function networkSentence(hosts) {
@@ -119,8 +119,8 @@ function networkSentence(hosts) {
119
119
  return `It can reach only these hosts: ${hosts.join(", ")}. A download from any other host fails.`;
120
120
  }
121
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
122
+ * Our engine's tools and text for an agent that declares the Runtime's plugins (`agent-folder/3`).
123
+ * The same tools as without plugins, with the same effects, named `nylorun__<tool>` for
124
124
  * the model; the Runtime's words are one text, server `nylorun`, built from the declared plugins'
125
125
  * sections in their order; their skills join the agent's own. `outputs`, the skills' usage and
126
126
  * catalog, and the skills' folder note stay our engine's blocks.
@@ -14,7 +14,7 @@ export interface EngineTool {
14
14
  readonly inputSchema: JsonObject;
15
15
  readonly outputSchema?: JsonObject;
16
16
  /**
17
- * Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
17
+ * Not in the model's tool list: the model finds it with `tool_search` and runs it
18
18
  * with `tool_call`, which makes the call as this tool's own.
19
19
  */
20
20
  readonly deferred?: boolean;
@@ -23,7 +23,7 @@ export interface EngineTool {
23
23
  /** What runs its calls: their effects' `target` (an MCP tool's identity, our engine's `harness`). */
24
24
  readonly target?: EffectTarget;
25
25
  /**
26
- * The name its calls' effects carry (`toolName`), when the model reads another (ADR-106): a
26
+ * The name its calls' effects carry (`toolName`), when the model reads another: a
27
27
  * Runtime plugin's tool is `nylorun__memory` to the model and `memory` to its effect, so the
28
28
  * record, tool policy and the harness's dispatch see it as without plugins.
29
29
  */
@@ -58,7 +58,7 @@ export declare const DEFAULT_SANDBOX_TOOL_LIMITS: SandboxToolLimits;
58
58
  export declare function sandboxToolLimitsOf(set?: Partial<SandboxToolLimits>): SandboxToolLimits;
59
59
  /**
60
60
  * The sandbox tools, in the order the model reads them, with `workspace` named in their text
61
- * and `limits` in their schemas: all six, or those `names` lists (ADR-100, `engine.sandbox`),
61
+ * and `limits` in their schemas: all six, or those `names` lists (`engine.sandbox`),
62
62
  * still in our order. Each is a `sandbox` effect named by its operation.
63
63
  */
64
64
  export declare function sandboxTools(limits: SandboxToolLimits, workspace: string, names?: readonly SandboxToolName[]): EngineTool[];
@@ -85,14 +85,14 @@ export declare const MEMORY_TOOL = "memory";
85
85
  export declare function memoryToolOf(writes: boolean): EngineTool;
86
86
  /** The self-wake tool's name. */
87
87
  export declare const SCHEDULE_WAKE_TOOL = "schedule_wake";
88
- /** `schedule_wake` (track T4): a `runtime` effect. */
88
+ /** `schedule_wake`: a `runtime` effect. */
89
89
  export declare function wakeToolOf(): EngineTool;
90
- /** The triggers tool's name (D83). */
90
+ /** The triggers tool's name. */
91
91
  export declare const TRIGGERS_TOOL = "triggers";
92
92
  /** What serves a `triggers` call: the Runtime, in the call's own transaction. */
93
93
  export declare const RUNTIME_TRIGGERS: EffectTarget;
94
94
  /**
95
- * `triggers` (D83): list, create and delete the triggers the calling session made, for an agent
95
+ * `triggers`: list, create and delete the triggers the calling session made, for an agent
96
96
  * whose version declares `engine.triggers`; the root agent's only. A `runtime` effect, operation
97
97
  * `triggers`; its input is `TriggerToolInputSchema`'s.
98
98
  */
@@ -122,7 +122,7 @@ export declare function deferredToolsTools(config: {
122
122
  readonly toolSearchDefaultLimit: number;
123
123
  readonly toolSearchMaxLimit: number;
124
124
  }): readonly EngineTool[];
125
- /** The question tool's name (ADR-106, `nylorun-interactions`). */
125
+ /** The question tool's name (`nylorun-interactions`). */
126
126
  export declare const ASK_TOOL = "ask";
127
127
  /** The most characters of a question, of a reason, and of one choice, and the most choices. */
128
128
  export declare const ASK_LIMITS: Readonly<{
@@ -132,7 +132,7 @@ export declare const ASK_LIMITS: Readonly<{
132
132
  choices: 6;
133
133
  }>;
134
134
  /**
135
- * `ask` (ADR-106): the agent asks whoever gave it the task a question it can't answer itself,
135
+ * `ask`: the agent asks whoever gave it the task a question it can't answer itself,
136
136
  * and waits. It runs in the harness, as `request_connection` does: a first call pauses the turn
137
137
  * with an interaction of kind `response` whose metadata says `kind: "question"`, which the A2A
138
138
  * server shows as a question (`INPUT_REQUIRED`); the answer runs it again with the value.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Our engine's own tools as the model reads them (protocol 15, ADR-100): each tool's name,
2
+ * Our engine's own tools as the model reads them (protocol 15): each tool's name,
3
3
  * description, input schema and the effect its calls make. Our harness runs them
4
4
  * (`@nylorun/harness`); the compiler and the SDK's `previewTurn` read the same definitions, so
5
5
  * what a preview shows is what a session is offered. Their schemas reach the model: change them
@@ -44,7 +44,7 @@ const object = (properties, required) => ({
44
44
  const pathField = { type: "string", minLength: 1 };
45
45
  /**
46
46
  * The sandbox tools, in the order the model reads them, with `workspace` named in their text
47
- * and `limits` in their schemas: all six, or those `names` lists (ADR-100, `engine.sandbox`),
47
+ * and `limits` in their schemas: all six, or those `names` lists (`engine.sandbox`),
48
48
  * still in our order. Each is a `sandbox` effect named by its operation.
49
49
  */
50
50
  export function sandboxTools(limits, workspace, names = SANDBOX_TOOL_NAMES) {
@@ -314,7 +314,7 @@ export function memoryToolOf(writes) {
314
314
  /** The self-wake tool's name. */
315
315
  export const SCHEDULE_WAKE_TOOL = "schedule_wake";
316
316
  const RUNTIME_WAKE = Object.freeze({ kind: "runtime", operation: "schedule_wake" });
317
- /** `schedule_wake` (track T4): a `runtime` effect. */
317
+ /** `schedule_wake`: a `runtime` effect. */
318
318
  export function wakeToolOf() {
319
319
  return {
320
320
  name: SCHEDULE_WAKE_TOOL,
@@ -333,12 +333,12 @@ export function wakeToolOf() {
333
333
  };
334
334
  }
335
335
  // --- triggers --------------------------------------------------------------------------------
336
- /** The triggers tool's name (D83). */
336
+ /** The triggers tool's name. */
337
337
  export const TRIGGERS_TOOL = "triggers";
338
338
  /** What serves a `triggers` call: the Runtime, in the call's own transaction. */
339
339
  export const RUNTIME_TRIGGERS = Object.freeze({ kind: "runtime", operation: "triggers" });
340
340
  /**
341
- * `triggers` (D83): list, create and delete the triggers the calling session made, for an agent
341
+ * `triggers`: list, create and delete the triggers the calling session made, for an agent
342
342
  * whose version declares `engine.triggers`; the root agent's only. A `runtime` effect, operation
343
343
  * `triggers`; its input is `TriggerToolInputSchema`'s.
344
344
  */
@@ -509,12 +509,12 @@ function definedOf(value) {
509
509
  return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
510
510
  }
511
511
  // --- ask -------------------------------------------------------------------------------------
512
- /** The question tool's name (ADR-106, `nylorun-interactions`). */
512
+ /** The question tool's name (`nylorun-interactions`). */
513
513
  export const ASK_TOOL = "ask";
514
514
  /** The most characters of a question, of a reason, and of one choice, and the most choices. */
515
515
  export const ASK_LIMITS = Object.freeze({ questionChars: 1000, whyChars: 280, choiceChars: 120, choices: 6 });
516
516
  /**
517
- * `ask` (ADR-106): the agent asks whoever gave it the task a question it can't answer itself,
517
+ * `ask`: the agent asks whoever gave it the task a question it can't answer itself,
518
518
  * and waits. It runs in the harness, as `request_connection` does: a first call pauses the turn
519
519
  * with an interaction of kind `response` whose metadata says `kind: "question"`, which the A2A
520
520
  * server shows as a question (`INPUT_REQUIRED`); the answer runs it again with the value.
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Machine-readable error raised by Harness-owned code. */
2
2
  export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema"
3
- /** A provider failure the model adapter classified (Model Calls §6.1). */
3
+ /** A provider failure the model adapter classified. */
4
4
  | `model.${import("./types/model.js").ModelFailureCode}` | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
5
5
  export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
6
6
  export interface HarnessErrorOptions {
@@ -3,10 +3,10 @@ import { type FolderScope } from "./nested.js";
3
3
  /** The compiler format this version builds by default: a folder with no `format`, or `format: 1`. */
4
4
  export declare const AGENT_FOLDER_COMPILER = "agent-folder/1";
5
5
  /**
6
- * The formats this compiler builds: `agent-folder/1`, and `agent-folder/2` (ADR-100), whose
6
+ * The formats this compiler builds: `agent-folder/1`, and `agent-folder/2`, 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", "agent-folder/3"];
9
+ export declare const AGENT_FOLDER_FORMATS: readonly ["agent-folder/1", "agent-folder/2", "agent-folder/3", "agent-folder/4"];
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
@@ -2,6 +2,8 @@ import { AGENT_MANIFEST_V8_SCHEMA_VERSION, AGENT_MODEL_MAX_CHARS, AGENT_ROLE_PAT
2
2
  import { cronScheduleIssue, isTimeZone, timeZoneNames } from "../definition/cron.js";
3
3
  import { RUNTIME_SERVER } from "../plugins/index.js";
4
4
  import { enginePlugins, isFolderV3, pluginSkillNames, v3Declarations } from "./v3.js";
5
+ import { compileFormat4, folderIsV4, isFolderV4, narrowFront, narrowParts, rootSecretsOf } from "./subagent-files.js";
6
+ import { isPluginName, pluginTools } from "../plugins/index.js";
5
7
  import { DELEGATE_NAME_PATTERN } from "../definition/delegate.js";
6
8
  import { sectionGapsAt } from "../definition/sections.js";
7
9
  import { DEFAULT_HARNESS } from "../utils/harness-id.js";
@@ -15,10 +17,10 @@ import { ENGINE_TEXT_DIR, compiledEngine, engineBlocksOf, engineDeclarations, fo
15
17
  /** The compiler format this version builds by default: a folder with no `format`, or `format: 1`. */
16
18
  export const AGENT_FOLDER_COMPILER = "agent-folder/1";
17
19
  /**
18
- * The formats this compiler builds: `agent-folder/1`, and `agent-folder/2` (ADR-100), whose
20
+ * The formats this compiler builds: `agent-folder/1`, and `agent-folder/2`, whose
19
21
  * folder declares every engine feature it uses (`folder/engine.ts`).
20
22
  */
21
- export const AGENT_FOLDER_FORMATS = ["agent-folder/1", "agent-folder/2", "agent-folder/3"];
23
+ export const AGENT_FOLDER_FORMATS = ["agent-folder/1", "agent-folder/2", "agent-folder/3", "agent-folder/4"];
22
24
  /**
23
25
  * What a folder may hold, unless `compileAgentFolder` is given other limits (a Tenant's Runtime
24
26
  * limits `folderFiles`, `folderBytes` and `folderTextFileBytes`, which default to these).
@@ -57,7 +59,8 @@ export const SCHEMA_URLS = {
57
59
  };
58
60
  const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
59
61
  export const AGENT_KEYS = ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "model", "roles", "engine", "plugins", "metadata"];
60
- const SKILL_KEYS = ["name", "description", "license", "compatibility", "metadata", "allowed-tools"];
62
+ /** Agent Skills' keys, and Claude Code's `disable-model-invocation`: a skill only a person starts. */
63
+ const SKILL_KEYS = ["name", "description", "license", "compatibility", "metadata", "allowed-tools", "disable-model-invocation"];
61
64
  export const TRIGGER_KEYS = ["schedule", "timezone", "at", "webhook", "session"];
62
65
  export const MCP_KEYS = ["$schema", "mcpServers"];
63
66
  export const SERVER_KEYS = ["type", "url", "headers"];
@@ -67,7 +70,7 @@ export const PLUGIN_SERVER_SETTING_KEYS = [...SERVER_SETTING_KEYS, "credential"]
67
70
  export const TOOL_KEYS = ["description", "inputSchema", "outputSchema", "http"];
68
71
  /**
69
72
  * The loop settings our harness reads from `loop`: `plan` (`true` offers the agent `update_plan`),
70
- * `connections` (`true` offers it `request_connection`), `ask`, and `compaction` (ADR-157: when
73
+ * `connections` (`true` offers it `request_connection`), `ask`, and `compaction` (when
71
74
  * the agent's sessions compact, `threshold` and `keepTokens`, and `roles.<role>` over them). A
72
75
  * custom harness reads its own.
73
76
  */
@@ -135,10 +138,21 @@ function classify(path) {
135
138
  return { kind: "schema" };
136
139
  return { kind: "other" };
137
140
  }
141
+ // agent-folder/4: a subagent is a file, with its flow file and schemas beside it.
142
+ if (top === "agents" && segments.length === 2) {
143
+ if (base.endsWith(".flow.json"))
144
+ return { kind: "subagent_flow" };
145
+ if (base.endsWith(".schema.json"))
146
+ return { kind: "schema" };
147
+ if (base.endsWith(".md"))
148
+ return { kind: "subagent_file" };
149
+ }
138
150
  if (top === "agents" || top === "plugins")
139
151
  return {
140
152
  code: "reserved_directory",
141
- error: top === "agents" ? "agents/ holds one folder per agent, each with its AGENT.md" : "plugins/ holds one folder per Agent Plugin, each with its plugin.json",
153
+ error: top === "agents"
154
+ ? "agents/ holds one file per subagent, agents/<id>.md (agent-folder/4), or one folder per subagent, each with its AGENT.md (agent-folder/3 and older)"
155
+ : "plugins/ holds one folder per Agent Plugin, each with its plugin.json",
142
156
  };
143
157
  if (top === "instructions")
144
158
  return segments.length === 2 && base.endsWith(".md")
@@ -183,6 +197,8 @@ export function folderTextPaths(entries) {
183
197
  kind.kind === "schema" ||
184
198
  kind.kind === "flow" ||
185
199
  kind.kind === "engine_text" ||
200
+ kind.kind === "subagent_file" ||
201
+ kind.kind === "subagent_flow" ||
186
202
  (kind.kind === "skill" && entry.path.split("/").length === 3 && entry.path.endsWith(`/${SKILL_ENTRY}`));
187
203
  if (textual)
188
204
  paths.push(entry.path);
@@ -219,11 +235,17 @@ const show = (value) => JSON.stringify(value) ?? String(value);
219
235
  * compiler sets it when it compiles a folder inside another (`agents/<id>/`, a plugin's parts).
220
236
  */
221
237
  export function compileAgentFolder(input, scope) {
238
+ // agent-folder/4: its subagent files, expanded into the layout format 3 compiles.
239
+ if (!scope && folderIsV4(input))
240
+ return compileFormat4(input, (expanded) => compileFolder(expanded, undefined));
241
+ return compileFolder(input, scope);
242
+ }
243
+ function compileFolder(input, scope) {
222
244
  const limits = { ...AGENT_FOLDER_LIMITS, ...input.limits };
223
245
  const diagnostics = [];
224
246
  /** The folder's format: the uploaded folder's `format`, which a folder inside it shares. */
225
247
  let format = scope?.engineFacts?.format ?? 1;
226
- /** The folder is `agent-folder/3` (ADR-106): its plugins stand for v2 declarations (folder/v3.ts). */
248
+ /** The folder is `agent-folder/3`: its plugins stand for v2 declarations (folder/v3.ts). */
227
249
  let v3 = scope?.engineFacts?.v3 === true;
228
250
  let v3Plugins;
229
251
  const parsed = new Map();
@@ -448,6 +470,10 @@ export function compileAgentFolder(input, scope) {
448
470
  // `/x` in a folder inside another names a file of the uploaded folder (folder/nested.ts).
449
471
  if (scope && value.startsWith("/"))
450
472
  return scopedSchema(scope, value, (code, message) => error(code, message, file, field));
473
+ // In a format 4 subagent file, `./x` is beside the file, under agents/; in its copy of the
474
+ // library, it is the library file's, from the root (folder/subagent-files.ts).
475
+ if (scope && scope.role !== "plugin" && scope.engineFacts?.v4 !== undefined)
476
+ return scopedSchema(scope, file === AGENT_FILE ? `/agents/${value.replace(/^\.\//, "")}` : `/${value.replace(/^\.\//, "")}`, (code, message) => error(code, message, file, field));
451
477
  const target = value.startsWith("/") ? value.slice(1) : value.replace(/^\.\//, "");
452
478
  if (target.split("/").some((segment) => segment === ".." || segment === "")) {
453
479
  error("path_outside", `${value} leaves the folder: a path names a file inside it`, file, field);
@@ -477,23 +503,67 @@ export function compileAgentFolder(input, scope) {
477
503
  const instructions = [];
478
504
  let metadata;
479
505
  const origins = [];
506
+ /** agent-folder/4: the uploaded folder is format 4, or this is one of its subagent files. */
507
+ const v4File = scope !== undefined && scope.role !== "plugin" && scope.engineFacts?.v4 !== undefined;
508
+ let v4Root = false;
509
+ /** What a format 4 subagent file, or root, keeps of what it inherits (folder/subagent-files.ts). */
510
+ let narrowing;
511
+ /** A format 4 root's frontmatter before it narrows itself: its library, which subagents inherit. */
512
+ let libraryFront;
513
+ let rootSecrets;
514
+ let libraryPlugins;
480
515
  if (agent) {
481
516
  if (!agent.hasFrontmatter)
482
517
  error("frontmatter_missing", `${AGENT_FILE} opens with frontmatter between --- lines, with name and description`, AGENT_FILE, undefined, { at: { line: 1, column: 1 } });
518
+ v4Root = !scope && isFolderV4(front.format);
519
+ if (v4Root || v4File) {
520
+ if (v4Root)
521
+ rootSecrets = rootSecretsOf(front);
522
+ if (v4Root && [...kinds.values()].includes("flow")) {
523
+ for (const key of ["tools", "disallowedTools"])
524
+ if (front[key] !== undefined) {
525
+ error("flow_refused", `${key} belongs to a model loop: a manifest driven by a flow has none, and each subagent narrows its own`, AGENT_FILE, [key], { key: true });
526
+ delete front[key];
527
+ }
528
+ }
529
+ else {
530
+ if (v4Root && (front.tools !== undefined || front.disallowedTools !== undefined)) {
531
+ libraryFront = JSON.parse(JSON.stringify(front));
532
+ delete libraryFront.tools;
533
+ delete libraryFront.disallowedTools;
534
+ }
535
+ const httpTools = [...kinds].filter(([, kind]) => kind === "tool").map(([path]) => path.slice("tools/".length, -".json".length));
536
+ const plugins = v4File
537
+ ? (scope.engineFacts.plugins ?? [])
538
+ : Array.isArray(front.plugins)
539
+ ? front.plugins.filter(isPluginName).map((name) => ({ name, tools: pluginTools(name) }))
540
+ : [];
541
+ narrowing = narrowFront(front, {
542
+ role: v4File ? "subagent" : "root",
543
+ httpTools,
544
+ plugins,
545
+ error: (code, message, path, options) => error(code, message, AGENT_FILE, path, options),
546
+ note: (code, message, path, options) => report("note", code, message, AGENT_FILE, path, options),
547
+ });
548
+ }
549
+ }
483
550
  checkKeys(AGENT_FILE, front, AGENT_KEYS);
484
551
  if (typeof front.name !== "string" || front.name === "")
485
552
  error("name_missing", "name is required: the agent manifest's name", AGENT_FILE, front.name === undefined ? undefined : ["name"]);
486
553
  else if (!isAgentManifestName(front.name))
487
554
  error("name_invalid", "name is 1-64 letters, digits, '.', '_' and '-', starting with a letter or digit", AGENT_FILE, ["name"]);
555
+ // A subagent file goes by its name, whatever the file is called: the tool the model calls.
556
+ else if (v4File && !/^[A-Za-z0-9_-]{1,64}$/.test(front.name))
557
+ error("name_invalid", "name is the tool the model calls: 1-64 letters, digits, '_' and '-'", AGENT_FILE, ["name"]);
488
558
  else if (input.name !== undefined && front.name !== input.name)
489
- error("name_mismatch", `name is ${front.name}, and the folder is saved as ${input.name}: they must match`, AGENT_FILE, ["name"]);
559
+ error("name_mismatch", v4File ? `name is ${front.name}, and the file is agents/${input.name}.md: they must match` : `name is ${front.name}, and the folder is saved as ${input.name}: they must match`, AGENT_FILE, ["name"]);
490
560
  else
491
561
  name = front.name;
492
562
  if (typeof front.description !== "string" || front.description.trim() === "")
493
563
  error("description_missing", "description is required: what the agent does, in a sentence", AGENT_FILE, front.description === undefined ? undefined : ["description"]);
494
564
  else
495
565
  description = front.description.trim();
496
- if (!scope && isFolderV3(front.format)) {
566
+ if (!scope && (isFolderV3(front.format) || isFolderV4(front.format))) {
497
567
  v3 = true;
498
568
  format = 2;
499
569
  }
@@ -501,7 +571,7 @@ export function compileAgentFolder(input, scope) {
501
571
  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"]);
502
572
  else if (!scope)
503
573
  format = folderFormatOf(front.format);
504
- // agent-folder/3 (ADR-106): the plugins stand for agent-folder/2's declarations.
574
+ // agent-folder/3: the plugins stand for agent-folder/2's declarations.
505
575
  if (v3 && scope?.role !== "plugin") {
506
576
  const role = scope?.role === "subagent" ? "subagent" : "root";
507
577
  v3Plugins = v3Declarations(front, {
@@ -510,6 +580,9 @@ export function compileAgentFolder(input, scope) {
510
580
  role,
511
581
  ...(scope?.engineFacts?.plugins === undefined ? {} : { parent: scope.engineFacts.plugins }),
512
582
  });
583
+ // A format 4 root that narrows itself: its library, as it was before, is what subagents inherit.
584
+ if (libraryFront)
585
+ libraryPlugins = v3Declarations(libraryFront, { error: () => { }, computer: earlyComputer(), role: "root" })?.plugins;
513
586
  delete front.memory;
514
587
  delete front.loop;
515
588
  if (isObject(front.mcpServers)) {
@@ -519,7 +592,8 @@ export function compileAgentFolder(input, scope) {
519
592
  else
520
593
  delete front.mcpServers;
521
594
  }
522
- if (v3Plugins) {
595
+ // A flow has no model loop, so nothing to declare: its stages declare their own.
596
+ if (v3Plugins && ![...kinds.values()].includes("flow")) {
523
597
  if (v3Plugins.memory)
524
598
  front.memory = v3Plugins.memory;
525
599
  if (v3Plugins.loop)
@@ -571,7 +645,7 @@ export function compileAgentFolder(input, scope) {
571
645
  else
572
646
  error("value_invalid", `model is <provider>/<model>, such as anthropic/claude-sonnet-4-5: the provider's id (letters, digits, '.', '_' or '-'), a '/', then the model's id, at most ${AGENT_MODEL_MAX_CHARS} characters and no spaces${typeof front.model === "string" ? `, not ${JSON.stringify(front.model)}` : ""}`, AGENT_FILE, ["model"]);
573
647
  }
574
- // The model of each role a session may be opened with (Host feature `model-roles`, ADR-154).
648
+ // The model of each role a session may be opened with (Host feature `model-roles`).
575
649
  if (front.roles !== undefined) {
576
650
  if (!isObject(front.roles))
577
651
  error("value_invalid", "roles is a map from a role's name to its model, such as builder: anthropic/claude-sonnet-4-5", AGENT_FILE, ["roles"]);
@@ -619,6 +693,15 @@ export function compileAgentFolder(input, scope) {
619
693
  // A flow has no instructions of its own: its stages do.
620
694
  else if (agent?.hasFrontmatter && ![...kinds.values()].includes("flow"))
621
695
  warn("instructions_empty", `The agent has no instructions: ${AGENT_FILE}'s body is empty and instructions/ holds none, so the model gets the harness's own instructions only. Write them below the frontmatter`, AGENT_FILE, undefined, { at: { line: agent.bodyLine, column: 1 } });
696
+ // A subagent file outside agent-folder/4.
697
+ if (!v4Root && !v4File)
698
+ for (const [path, kind] of kinds)
699
+ if (kind === "subagent_file" || kind === "subagent_flow") {
700
+ const id = path.slice("agents/".length).replace(/(\.flow\.json|\.md)$/, "");
701
+ error("subagent_file", kind === "subagent_file"
702
+ ? `agents/${id}.md is a subagent file, which agent-folder/4 reads. Fix: add format: agent-folder/4 to AGENT.md (nylorun migrate folder <dir> --to 4 moves every subagent folder to a file), or write it as agents/${id}/AGENT.md`
703
+ : `${path} is a subagent's flow file, which agent-folder/4 reads. Fix: add format: agent-folder/4 to AGENT.md, or write it as agents/${id}/flow.json`, path);
704
+ }
622
705
  // --- runtime.json ----------------------------------------------------------------------
623
706
  let runtime;
624
707
  if (byPath.has(RUNTIME_FILE)) {
@@ -639,7 +722,7 @@ export function compileAgentFolder(input, scope) {
639
722
  checkSchedule(RUNTIME_FILE, ["triggers", id], trigger);
640
723
  }
641
724
  }
642
- // --- engine: (agent-folder/2, ADR-100; folder/engine.ts) -------------------------------
725
+ // --- engine: (agent-folder/2; folder/engine.ts) -------------------------------
643
726
  /** Whether the session's Agent has a computer: the uploaded folder's runtime kind. */
644
727
  const runtimeKind = isObject(runtime) && typeof runtime.kind === "string" ? runtime.kind : "none";
645
728
  const computer = scope?.engineFacts ? scope.engineFacts.computer : runtimeKind === "virtual" || runtimeKind === "pod";
@@ -704,7 +787,8 @@ export function compileAgentFolder(input, scope) {
704
787
  format,
705
788
  computer,
706
789
  ...(format === 2 && declared ? { engine: declared.engine } : {}),
707
- ...(v3 ? { v3: true, plugins: v3Plugins?.plugins ?? [] } : {}),
790
+ ...(v3 ? { v3: true, plugins: libraryPlugins ?? v3Plugins?.plugins ?? [] } : {}),
791
+ ...(v4Root ? { v4: rootSecrets ?? { skills: [], servers: [] } } : {}),
708
792
  memory: isObject(front.memory),
709
793
  selfWake: isObject(runtime) && runtime.selfWake === true,
710
794
  };
@@ -975,6 +1059,11 @@ export function compileAgentFolder(input, scope) {
975
1059
  error("skill_invalid", "description is required, at most 1024 characters", entryPath, data.description === undefined ? undefined : ["description"]);
976
1060
  valid = false;
977
1061
  }
1062
+ const personOnly = data["disable-model-invocation"];
1063
+ if (personOnly !== undefined && typeof personOnly !== "boolean") {
1064
+ error("skill_invalid", "disable-model-invocation is true or false: true keeps the skill from the model until a person starts it", entryPath, ["disable-model-invocation"]);
1065
+ valid = false;
1066
+ }
978
1067
  const files = {};
979
1068
  for (const path of paths.sort(compare)) {
980
1069
  const relative = path.slice(`skills/${folder}/`.length);
@@ -988,7 +1077,7 @@ export function compileAgentFolder(input, scope) {
988
1077
  }
989
1078
  if (!valid)
990
1079
  continue;
991
- skills[skillName] = { name: skillName, description: skillDescription, files };
1080
+ skills[skillName] = { name: skillName, description: skillDescription, files, ...(personOnly === true ? { disableModelInvocation: true } : {}) };
992
1081
  origins.push([["harness", "skills", skillName], { file: entryPath, path: [] }]);
993
1082
  }
994
1083
  parts.mergeSkills(skills);
@@ -1077,6 +1166,13 @@ export function compileAgentFolder(input, scope) {
1077
1166
  }
1078
1167
  if (tools.length > 0)
1079
1168
  harness.tools = tools;
1169
+ // agent-folder/4: what a subagent file, or the root, keeps of the library.
1170
+ if (narrowing)
1171
+ narrowParts(harness, narrowing, {
1172
+ role: v4File ? "subagent" : "root",
1173
+ secrets: scope?.engineFacts?.v4 ?? { skills: [], servers: [] },
1174
+ error: (code, message, path, options) => error(code, message, AGENT_FILE, path, options),
1175
+ });
1080
1176
  // --- triggers/ -------------------------------------------------------------------------
1081
1177
  const triggers = {};
1082
1178
  /** Where each trigger's body (its prompt) starts. */
@@ -1500,7 +1596,7 @@ function trimBlankLines(text) {
1500
1596
  return lines.join("\n");
1501
1597
  }
1502
1598
  /**
1503
- * Checks `loop.compaction` (ADR-157): a map of `threshold` and `keepTokens`, positive whole numbers
1599
+ * Checks `loop.compaction`: a map of `threshold` and `keepTokens`, positive whole numbers
1504
1600
  * of tokens, and `roles`, a map from a role's name to the same two. The harness also ignores a
1505
1601
  * value it cannot use, so a folder that passes here never changes how its sessions compact by
1506
1602
  * accident.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The agent folder of a manifest (track T7, D80): `folderOfManifest` is `compileAgentFolder` run
2
+ * The agent folder of a manifest: `folderOfManifest` is `compileAgentFolder` run
3
3
  * backwards. It writes the folder that compiles back to the same agent manifest v8, for an agent
4
4
  * saved as JSON or from TypeScript (`nylorun export --folder`) and for the three-file format
5
5
  * (`nylorun migrate folder`). Like the compiler it is pure: no file system, clock or network.
@@ -14,8 +14,8 @@
14
14
  * `instructions/NN-<slug>.md`, zero-padded so path order and natural order agree.
15
15
  * - HTTP tools: `tools/<name>.json`, their schemas inline.
16
16
  * - Subagents (a tool with `agent`): `agents/<name>/`, an agent folder of the embedded agent
17
- * manifest v7 (or a flow, workflow manifest v3), as the compiler reads one (design §3.3).
18
- * - Flows (`kind: "workflow"`, design §3.8): `AGENT.md` with no body and `inputSchema`
17
+ * manifest v7 (or a flow, workflow manifest v3), as the compiler reads one.
18
+ * - Flows (`kind: "workflow"`): `AGENT.md` with no body and `inputSchema`
19
19
  * (`input.schema.json`), `flow.json` with v3's node tree naming agents by id and tools by file
20
20
  * name, and one flat `agents/<id>/` namespace at the flow root for every agent of the flow and
21
21
  * of its sub-flows. A sub-flow is an `agents/<id>/` with its own `flow.json` over the same
@@ -32,7 +32,7 @@
32
32
  * (`options.files`), a last `/workspace` entry becomes `files/`.
33
33
  * - Skills: the manifest has their files by hash only. Given the bytes (`options.files`, by
34
34
  * `sha256:<hex>`), each skill is written as its folder; a `SKILL.md` that still says `secrets`
35
- * loses that key, which `AGENT.md`'s `skills` block holds now (D80), so its hash changes.
35
+ * loses that key, which `AGENT.md`'s `skills` block holds now, so its hash changes.
36
36
  * Without them, a placeholder `SKILL.md` stands in and a note lists the files to copy in.
37
37
  *
38
38
  * What a folder cannot say is left out or written another way, with a note: an embedded agent's
@@ -250,7 +250,7 @@ function writeAgent(writer, place, identity, harness) {
250
250
  else {
251
251
  files.set(file, moved);
252
252
  note(root
253
- ? `skills/${key}/SKILL.md: secrets moved to AGENT.md's skills block (D80), so the file and its hash change.`
253
+ ? `skills/${key}/SKILL.md: secrets moved to AGENT.md's skills block, so the file and its hash change.`
254
254
  : `skills/${key}/SKILL.md: its secrets are left out, as only the root agent's skills get secrets, so the file and its hash change.`);
255
255
  }
256
256
  }
@@ -276,7 +276,7 @@ function writeAgent(writer, place, identity, harness) {
276
276
  else
277
277
  note("harness.loop is not a map, which AGENT.md needs: it is left out.");
278
278
  }
279
- // agent-folder/2 (ADR-100): the declarations, each replaced wording a file under engine/. The
279
+ // agent-folder/2: the declarations, each replaced wording a file under engine/. The
280
280
  // blocks are the compiler's to list again.
281
281
  if (harness.engine !== undefined && !root && !writer.declares)
282
282
  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.");
@@ -397,7 +397,7 @@ function writeEmbedded(writer, place, id, agent, namespace) {
397
397
  if (agent.id !== id)
398
398
  note(`The embedded agent's id is ${agent.id}, and in a folder it is its folder's name, ${id}.`);
399
399
  if (agent.name !== undefined)
400
- note(`The agent's display name "${agent.name}" is left out: in a folder an agent's name is its id (design §3.2).`);
400
+ note(`The agent's display name "${agent.name}" is left out: in a folder an agent's name is its id.`);
401
401
  const identity = { name: id, description: agent.description, metadata: agent.metadata };
402
402
  // Its `id` is the agent's, not the harness's: `AGENT.md`'s name holds it.
403
403
  if (isWorkflow(agent)) {
@@ -18,13 +18,19 @@ 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). */
21
+ /** The uploaded folder is `agent-folder/3`. */
22
22
  readonly v3?: boolean;
23
23
  /** Its plugins, under format 3: a subagent's are a subset. */
24
24
  readonly plugins?: readonly {
25
25
  readonly name: import("../plugins/index.js").PluginName;
26
26
  readonly tools: readonly string[];
27
27
  }[];
28
+ /**
29
+ * The uploaded folder is `agent-folder/4`: its folders under `agents/` are subagent
30
+ * files, expanded with the library. What they may not inherit unnamed: the root's skills with
31
+ * secrets and servers it gives a credential.
32
+ */
33
+ readonly v4?: import("./subagent-files.js").RootSecrets;
28
34
  }
29
35
  type Fail = (code: string, message: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
30
36
  /**
@@ -70,7 +76,7 @@ export declare function engineBlocksOf(agent: {
70
76
  };
71
77
  readonly plan: boolean;
72
78
  readonly connections: boolean;
73
- /** The root agent declares `engine.triggers` (D83). */
79
+ /** The root agent declares `engine.triggers`. */
74
80
  readonly triggers?: boolean;
75
81
  /** The root agent has `ask` (`agent-folder/3`, `harness.loop.ask`). */
76
82
  readonly ask?: boolean;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `agent-folder/2` (ADR-100): a folder declares every engine feature it uses, and our engine adds
2
+ * `agent-folder/2`: a folder declares every engine feature it uses, and our engine adds
3
3
  * nothing else. `AGENT.md` names the format (`format: agent-folder/2`, or `2`) and, in its
4
4
  * `engine:` block, the features no other key declares:
5
5
  *
@@ -11,7 +11,7 @@
11
11
  * artifacts: { read: true, save: false } # save needs a computer
12
12
  * outputs: true # save /workspace/outputs when a turn ends; needs a computer
13
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
14
+ * triggers: true # the triggers tool and its text; the root agent's only
15
15
  * instructions: # a block's wording, replaced by a file under engine/
16
16
  * memory: engine/memory.md
17
17
  * ```
@@ -146,7 +146,7 @@ export function engineDeclarations(value, options) {
146
146
  engine.toolSearch = value.toolSearch;
147
147
  }
148
148
  }
149
- // triggers: the root agent's (D83). A subagent whose parent declares them is refused in
149
+ // triggers: the root agent's. A subagent whose parent declares them is refused in
150
150
  // `nested.ts`; one whose parent does not, here.
151
151
  if (value.triggers !== undefined) {
152
152
  const at = ["engine", "triggers"];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The compiler's fix-its, applied to text (`nylorun check --fix`, track T7): each diagnostic's
2
+ * The compiler's fix-its, applied to text (`nylorun check --fix`): each diagnostic's
3
3
  * `fix` (`AgentFolderFix`) is one edit, and this makes it, touching nothing else. Like the
4
4
  * compiler it is pure: it is given the text of each file a fix names, and answers the new text
5
5
  * of each it changed.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `flow.json` (track T7, design §3.8): workflow manifest v3's node tree, as a folder writes it.
2
+ * `flow.json`: workflow manifest v3's node tree, as a folder writes it.
3
3
  * The node names are v3's (`agent`, `tool`, `chain`, `switch`, `parallel`, `map`, `loop`, and
4
4
  * `id` on any node), so a v3 tree pastes in. Two leaves differ, because a folder names things
5
5
  * instead of embedding them:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `flow.json` (track T7, design §3.8): workflow manifest v3's node tree, as a folder writes it.
2
+ * `flow.json`: workflow manifest v3's node tree, as a folder writes it.
3
3
  * The node names are v3's (`agent`, `tool`, `chain`, `switch`, `parallel`, `map`, `loop`, and
4
4
  * `id` on any node), so a v3 tree pastes in. Two leaves differ, because a folder names things
5
5
  * instead of embedding them: