@nylorun/core 0.53.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 (81) hide show
  1. package/CHANGELOG.md +114 -99
  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 +1 -1
  42. package/dist/folder/compile.js +23 -14
  43. package/dist/folder/decompile.js +7 -7
  44. package/dist/folder/engine.d.ts +3 -3
  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 +2 -2
  50. package/dist/folder/index.js +2 -2
  51. package/dist/folder/migrate-v3.js +2 -2
  52. package/dist/folder/migrate-v4.js +1 -1
  53. package/dist/folder/nested.js +9 -6
  54. package/dist/folder/plugins.d.ts +13 -1
  55. package/dist/folder/plugins.js +49 -12
  56. package/dist/folder/schemas.js +7 -7
  57. package/dist/folder/subagent-files.d.ts +9 -5
  58. package/dist/folder/subagent-files.js +96 -22
  59. package/dist/folder/v3.d.ts +2 -2
  60. package/dist/folder/v3.js +2 -2
  61. package/dist/harness-api/artifacts.d.ts +1 -1
  62. package/dist/harness-api/json-schema.js +6 -6
  63. package/dist/harness-api/messages.d.ts +1 -1
  64. package/dist/harness-api/messages.js +1 -1
  65. package/dist/harness-api/schema.d.ts +2 -2
  66. package/dist/harness-api/schema.js +8 -8
  67. package/dist/manifest-schemas.js +9 -6
  68. package/dist/plugins/index.js +1 -1
  69. package/dist/schemas/agent-manifest.schema.json +65 -2
  70. package/dist/schemas/harness-manifest.schema.json +55 -2
  71. package/dist/types/manifest.d.ts +32 -7
  72. package/dist/types/model.d.ts +3 -3
  73. package/dist/types/observe.d.ts +1 -1
  74. package/dist/types/part.d.ts +5 -3
  75. package/dist/types/transcript.d.ts +1 -1
  76. package/dist/utils/definition-files.d.ts +23 -0
  77. package/dist/utils/definition-files.js +50 -4
  78. package/dist/utils/memory.js +1 -1
  79. package/dist/utils/runtime-limits.d.ts +2 -2
  80. package/dist/utils/runtime-limits.js +3 -3
  81. package/package.json +1 -1
@@ -8,7 +8,7 @@ const AUTHOR_KEYS = ["name", "email", "url"];
8
8
  const READ = new Set([PLUGIN_FILE, "mcp.json", ".mcp.json", "skills"]);
9
9
  /** Parts of plugins for other tools, which Nylorun does not run. */
10
10
  const NOT_RUN = {
11
- agents: "Claude Code's subagents (agents/*.md) are not run by Nylorun: write an agent as agents/<id>/ in the agent folder",
11
+ agents: "A plugin's subagents (agents/*.md) run in agent-folder/4: nylorun migrate folder <dir> --to 4",
12
12
  hooks: "Hooks are not run by Nylorun",
13
13
  commands: "Slash commands are not run by Nylorun",
14
14
  "output-styles": "Output styles are not run by Nylorun",
@@ -19,13 +19,34 @@ const NOT_RUN = {
19
19
  /** The agent the compiler wraps a plugin's skills and servers in, to read them as an agent's. */
20
20
  const WRAPPER = new TextEncoder().encode("---\nname: plugin\ndescription: An Agent Plugin's skills and MCP servers.\n---\n");
21
21
  const isSecretShaped = (base) => base === ".env" || base.startsWith(".env.") || base.endsWith(".pem") || base.endsWith(".key");
22
+ /** A plugin file the manifest already carries: its plugin.json, servers, skills and subagent files. */
23
+ const carried = (path) => path === PLUGIN_FILE || path === "mcp.json" || path === ".mcp.json" || path.startsWith("skills/") || pluginSubagentFile(path) !== undefined;
22
24
  /** The files of `plugins/<name>/` the compiler reads, relative to the plugin's folder. */
23
25
  export function pluginTextPaths(paths) {
24
- return paths.filter((path) => path === PLUGIN_FILE || path === "mcp.json" || path === ".mcp.json" || /^skills\/[^/]+\/SKILL\.md$/.test(path));
26
+ return paths.filter((path) => path === PLUGIN_FILE ||
27
+ path === "mcp.json" ||
28
+ path === ".mcp.json" ||
29
+ /^skills\/[^/]+\/SKILL\.md$/.test(path) ||
30
+ pluginSubagentFile(path) !== undefined ||
31
+ pluginSubagentFlow(path));
32
+ }
33
+ /** A plugin's subagent file, relative to the plugin's folder (`agents/<file>.md`): its file name, or undefined. */
34
+ export function pluginSubagentFile(path) {
35
+ return /^agents\/([^/]+)\.md$/.exec(path)?.[1];
36
+ }
37
+ /** A JSON file beside a plugin's subagent files, such as the flow file a subagent's `flow:` names. */
38
+ export function pluginSubagentFlow(path) {
39
+ return /^agents\/[^/]+\.json$/.test(path);
40
+ }
41
+ /** A plugin's label as its `plugin.json` gives it, read quietly: undefined when it names none. */
42
+ export function pluginLabelOf(manifest) {
43
+ if (!isObject(manifest) || !isPluginName(manifest.name))
44
+ return undefined;
45
+ return { name: manifest.name, ...(typeof manifest.version === "string" ? { version: manifest.version } : {}) };
25
46
  }
26
47
  /** Folds every plugin under `plugins/`. */
27
48
  export function foldPlugins(ctx) {
28
- const folded = { servers: new Map(), skills: new Map() };
49
+ const folded = { servers: new Map(), skills: new Map(), mounted: new Map() };
29
50
  for (const [folder, paths] of foldersUnder("plugins", ctx.entries.keys()))
30
51
  foldPlugin(ctx, folder, paths, folded);
31
52
  return folded;
@@ -36,16 +57,18 @@ function foldPlugin(ctx, folder, paths, folded) {
36
57
  const error = (code, message, at, path, key = false) => ctx.report("error", code, message, at, path, { key });
37
58
  // What it holds that Nylorun does not read: one note per top-level part.
38
59
  const noted = new Set();
60
+ // In agent-folder/4 a plugin's agents/*.md are subagents, read by the format 4 expansion.
61
+ const v4 = ctx.engineFacts().v4 !== undefined;
39
62
  for (const path of paths) {
40
63
  const top = path.split("/")[0];
41
- if (READ.has(top) || isSecretShaped(path.split("/").at(-1)) || noted.has(top))
64
+ if (READ.has(top) || isSecretShaped(path.split("/").at(-1)) || noted.has(top) || (v4 && top === "agents"))
42
65
  continue;
43
66
  noted.add(top);
44
67
  const isFolder = path.includes("/");
45
68
  ctx.report("note", "plugin_part_ignored", `${NOT_RUN[top] ?? "Kept with the source: Nylorun reads a plugin's plugin.json, mcp.json and skills/"}`, `${prefix}${top}${isFolder ? "/" : ""}`);
46
69
  }
47
70
  if (!paths.includes(PLUGIN_FILE)) {
48
- error("plugin_invalid", `${prefix} has no plugin.json: an Agent Plugin names itself there, with the Agent Plugins $schema and its name`, file);
71
+ error("plugin_invalid", `${prefix} has no plugin.json: an Agent Plugin names itself there, with its name`, file);
49
72
  return;
50
73
  }
51
74
  const manifest = ctx.readJson(file);
@@ -61,8 +84,9 @@ function foldPlugin(ctx, folder, paths, folded) {
61
84
  const close = ctx.suggest(key, PLUGIN_KEYS);
62
85
  ctx.report("warning", "plugin_unknown_key", `plugin.json has no field '${key}' in Agent Plugins 1.0.0: it is not read.${close ? ` Did you mean '${close}'?` : ""}`, file, [key], { key: true });
63
86
  }
64
- if (manifest.$schema !== AGENT_PLUGINS_PLUGIN_SCHEMA)
65
- invalid(`plugin.json names the Agent Plugins 1.0.0 plugin schema in $schema (${AGENT_PLUGINS_PLUGIN_SCHEMA})`, manifest.$schema === undefined ? [] : ["$schema"]);
87
+ // No $schema reads as Agent Plugins 1.0.0, as other hosts read it; another format is refused.
88
+ if (manifest.$schema !== undefined && manifest.$schema !== AGENT_PLUGINS_PLUGIN_SCHEMA)
89
+ invalid(`plugin.json's $schema names another format: Nylorun reads Agent Plugins 1.0.0 (${AGENT_PLUGINS_PLUGIN_SCHEMA}), or no $schema`, ["$schema"]);
66
90
  if (!isPluginName(manifest.name))
67
91
  invalid("name is required: 1-64 lowercase letters, digits, hyphens and periods, starting and ending with a letter or digit", manifest.name === undefined ? [] : ["name"]);
68
92
  for (const field of ["version", "description", "homepage", "repository", "license"])
@@ -87,16 +111,29 @@ function foldPlugin(ctx, folder, paths, folded) {
87
111
  }
88
112
  if (!valid)
89
113
  return;
90
- const label = { name: manifest.name, ...(typeof manifest.version === "string" ? { version: manifest.version } : {}) };
91
- // mcp.json, as Agent Plugins writes it: with its $schema. Claude Code's .mcp.json when there is none.
114
+ const label = pluginLabelOf(manifest);
115
+ // Its own files, mounted whole in the sandbox when it holds any the manifest doesn't carry, as
116
+ // other hosts give a plugin's root: every file but secret-shaped ones.
117
+ const kept = paths.filter((path) => !isSecretShaped(path.split("/").at(-1))).sort();
118
+ if (kept.some((path) => !carried(path))) {
119
+ const files = {};
120
+ for (const path of kept) {
121
+ const entry = ctx.entries.get(prefix + path);
122
+ if (entry)
123
+ files[path] = `sha256:${entry.sha256}`;
124
+ }
125
+ folded.mounted.set(label.name, { ...label, files });
126
+ }
127
+ // mcp.json, as Agent Plugins writes it: no $schema reads as 1.0.0, and one naming another format is
128
+ // refused. Claude Code's .mcp.json when there is none.
92
129
  const mcpFile = paths.includes("mcp.json") ? "mcp.json" : paths.includes(".mcp.json") ? ".mcp.json" : undefined;
93
130
  if (mcpFile === "mcp.json" && paths.includes(".mcp.json"))
94
131
  ctx.report("note", "plugin_part_ignored", "Claude Code's server file is not read: the plugin's mcp.json is", `${prefix}.mcp.json`);
95
132
  if (mcpFile === "mcp.json") {
96
133
  const value = quietJson(ctx, prefix + "mcp.json");
97
- if (value && value.$schema === undefined)
98
- ctx.report("error", "plugin_invalid", `A plugin's mcp.json names the Agent Plugins MCP schema in $schema (${AGENT_PLUGINS_MCP_SCHEMA}), as Agent Plugins requires`, prefix + "mcp.json", [], {
99
- at: jsonPosition(ctx, prefix + "mcp.json", []),
134
+ if (value && value.$schema !== undefined && value.$schema !== AGENT_PLUGINS_MCP_SCHEMA)
135
+ ctx.report("error", "plugin_invalid", `A plugin's mcp.json $schema names another format: Nylorun reads Agent Plugins 1.0.0 (${AGENT_PLUGINS_MCP_SCHEMA}), or no $schema`, prefix + "mcp.json", ["$schema"], {
136
+ at: jsonPosition(ctx, prefix + "mcp.json", ["$schema"]),
100
137
  });
101
138
  }
102
139
  // Its skills and servers, read as an agent's own by the compiler itself, inside a wrapper.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The JSON Schema document of each kind of file in an agent folder (track T7, design §3.10), so
2
+ * The JSON Schema document of each kind of file in an agent folder, so
3
3
  * an editor checks and completes a folder's files as it is written, from the `json.schemas`
4
4
  * mapping `nylorun init` writes. Each `$id` is `https://docs.nylorun.com/schemas/agent-folder/v1/
5
5
  * <kind>.json`; the build writes them to `dist/schemas/agent-folder/`, exported as
@@ -53,12 +53,12 @@ function fromZod(schema, defs, description) {
53
53
  /**
54
54
  * A kind's revision within format 1, when its document gained an optional key (a published `$id`
55
55
  * names one document for good): `AGENT.md` took `model` (Host feature `agent-model`), published
56
- * as `agent-md.1.json`, then `format: agent-folder/2` and `engine` (ADR-100), as `agent-md.2.json`,
57
- * then `engine.triggers` (D83), as `agent-md.3.json`, then `format: agent-folder/3` and
58
- * `plugins` (ADR-106), as `agent-md.4.json`, then `roles` (ADR-154), as `agent-md.5.json`, then
59
- * `format: agent-folder/4` and a subagent file's keys (ADR-164), as `agent-md.6.json`;
56
+ * as `agent-md.1.json`, then `format: agent-folder/2` and `engine`, as `agent-md.2.json`,
57
+ * then `engine.triggers`, as `agent-md.3.json`, then `format: agent-folder/3` and
58
+ * `plugins`, as `agent-md.4.json`, then `roles`, as `agent-md.5.json`, then
59
+ * `format: agent-folder/4` and a subagent file's keys, as `agent-md.6.json`;
60
60
  * `runtime.json` took a secret slot's `toolPrefix` (Host feature `secret-routing`), published as
61
- * `runtime.1.json`, then `limits.triggers` (D83), as `runtime.2.json`.
61
+ * `runtime.1.json`, then `limits.triggers`, as `runtime.2.json`.
62
62
  */
63
63
  const REVISIONS = { "agent-md": 6, runtime: 2 };
64
64
  /** One document: its `$id` from its kind, then the body, then the `$defs` its parts named. */
@@ -169,7 +169,7 @@ function agentMd() {
169
169
  },
170
170
  metadata: { type: "object", description: "The manifest's metadata, as it is" },
171
171
  };
172
- // agent-folder/4 (ADR-164): the narrowing keys a subagent file (agents/<id>.md) and the root take.
172
+ // agent-folder/4: the narrowing keys a subagent file (agents/<id>.md) and the root take.
173
173
  const toolNames = {
174
174
  anyOf: [{ type: "array", items: { type: "string" } }, { type: "string" }],
175
175
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `agent-folder/4` (ADR-164, D97): a subagent is one file, `agents/<id>.md`, and the manifest's
2
+ * `agent-folder/4`: a subagent is one file, `agents/<id>.md`, and the manifest's
3
3
  * `tools/`, `skills/`, `mcp.json`, `plugins/` and Runtime plugins are its **library**, which every
4
4
  * model loop in it draws on: the root's own, and each subagent's, which inherits it and narrows it
5
5
  * with `tools`, `disallowedTools`, `skills` and `mcpServers`.
@@ -13,8 +13,12 @@
13
13
  * You find earlier work for a bot…
14
14
  * ```
15
15
  *
16
+ * A subagent is named by its frontmatter `name`, whatever its file is called, as Claude Code and
17
+ * Cursor name theirs. An Agent Plugin's `agents/*.md` under `plugins/<name>/` are subagents too, read
18
+ * by the same rules and labelled with the plugin; no subagent inherits another.
19
+ *
16
20
  * The compiler keeps every check it has by **expanding** format 4 into the layout format 3 already
17
- * compiles: each `agents/<id>.md` becomes a virtual `agents/<id>/` holding the file's bytes as its
21
+ * compiles: each subagent file becomes a virtual `agents/<name>/` holding the file's bytes as its
18
22
  * `AGENT.md` and a copy of the library (the same bytes and hashes), or, for a file with `flow:`,
19
23
  * its flow file and the library tools the flow names. The subagent's compile then narrows what it
20
24
  * inherited (`narrowFront`, `narrowParts`), and every diagnostic is moved back to the file people
@@ -35,7 +39,7 @@ export declare const ROOT_V4_KEYS: readonly ["tools", "disallowedTools"];
35
39
  * Keys Claude Code and Cursor write that mean nothing here: noted and ignored, so their files drop
36
40
  * in. `memory` is one only as a string (Claude Code's `user`, `project` or `local`).
37
41
  */
38
- export declare const HOST_KEYS: readonly ["model", "color", "permissionMode", "hooks", "maxTurns", "background", "isolation", "effort", "initialPrompt", "omitClaudeMd", "autoCompactWindow", "experimental", "is_background"];
42
+ export declare const HOST_KEYS: readonly ["model", "color", "permissionMode", "hooks", "maxTurns", "background", "isolation", "effort", "initialPrompt", "omitClaudeMd", "autoCompactWindow", "experimental", "is_background", "license"];
39
43
  /** Claude Code's tool names that are ours under another spelling. */
40
44
  export declare const CLAUDE_TOOL_ALIASES: Readonly<Record<string, string>>;
41
45
  /** The Runtime plugins only the root agent uses: a subagent never inherits them, and names their tools only with an error. */
@@ -44,8 +48,8 @@ export declare const ROOT_ONLY_PLUGINS: readonly PluginName[];
44
48
  export declare function folderIsV4(input: CompileAgentFolderInput): boolean;
45
49
  /** A subagent file's id from its path, or undefined: `agents/<id>.md`. */
46
50
  export declare function subagentFileId(path: string): string | undefined;
47
- /** The path `flow:` names, from the file at `agents/<id>.md`: `./x` and `x` from `agents/`, `/x` from the root. */
48
- export declare function flowPathOf(value: unknown): string | undefined;
51
+ /** The path `flow:` names, from a subagent file in `dir`: `./x` and `x` from `dir`, `/x` from the root. */
52
+ export declare function flowPathOf(value: unknown, dir?: string): string | undefined;
49
53
  /**
50
54
  * Compiles a format 4 folder: expands its subagent files, compiles the result as `compile` does a
51
55
  * format 3 folder, and moves each diagnostic back to the file people wrote.
@@ -1,6 +1,7 @@
1
1
  import { parseMarkdown } from "./frontmatter.js";
2
2
  import { PLUGIN_NAMES, pluginOfTool, pluginTools, RUNTIME_SERVER } from "../plugins/index.js";
3
3
  import { suggestion } from "./suggest.js";
4
+ import { pluginLabelOf, pluginSubagentFile, pluginSubagentFlow } from "./plugins.js";
4
5
  /** The format name a v4 folder writes. */
5
6
  export const AGENT_FOLDER_V4 = "agent-folder/4";
6
7
  /** Whether `value` names the v4 format: `agent-folder/4` or `4`. */
@@ -29,6 +30,7 @@ export const HOST_KEYS = [
29
30
  "autoCompactWindow",
30
31
  "experimental",
31
32
  "is_background",
33
+ "license",
32
34
  ];
33
35
  /** Claude Code's tool names that are ours under another spelling. */
34
36
  export const CLAUDE_TOOL_ALIASES = { Read: "read", Grep: "grep", Glob: "glob", Write: "write", Edit: "edit", Bash: "bash" };
@@ -81,11 +83,11 @@ export function subagentFileId(path) {
81
83
  const match = /^agents\/([^/]+)\.md$/.exec(path);
82
84
  return match?.[1];
83
85
  }
84
- /** The path `flow:` names, from the file at `agents/<id>.md`: `./x` and `x` from `agents/`, `/x` from the root. */
85
- export function flowPathOf(value) {
86
+ /** The path `flow:` names, from a subagent file in `dir`: `./x` and `x` from `dir`, `/x` from the root. */
87
+ export function flowPathOf(value, dir = "agents") {
86
88
  if (typeof value !== "string" || value === "")
87
89
  return undefined;
88
- const target = value.startsWith("/") ? value.slice(1) : `agents/${value.replace(/^\.\//, "")}`;
90
+ const target = value.startsWith("/") ? value.slice(1) : `${dir}/${value.replace(/^\.\//, "")}`;
89
91
  return target.split("/").some((segment) => segment === "" || segment === "." || segment === "..") ? undefined : target;
90
92
  }
91
93
  /** The ids a flow's nodes name as `agent` and the names they name as `tool`. */
@@ -106,7 +108,15 @@ function flowNames(tree) {
106
108
  walk(tree);
107
109
  return { agents, tools };
108
110
  }
111
+ /**
112
+ * A plugin's subagent folder: `plugins/<name>/agents/`, with what it holds. Its files stay in the
113
+ * library as the plugin's files (mounted with the plugin), but a subagent's compile never reads them
114
+ * as subagents: no subagent inherits another.
115
+ */
116
+ const PLUGIN_AGENTS = /^plugins\/([^/]+)\/agents\/(.+)$/;
109
117
  const isLibrary = (path) => path === "mcp.json" || /^(tools|skills|plugins)\//.test(path);
118
+ /** A name a subagent can go by: the tool the model calls. */
119
+ const SUBAGENT_NAME = /^[A-Za-z0-9_-]{1,64}$/;
110
120
  /**
111
121
  * Compiles a format 4 folder: expands its subagent files, compiles the result as `compile` does a
112
122
  * format 3 folder, and moves each diagnostic back to the file people wrote.
@@ -114,15 +124,65 @@ const isLibrary = (path) => path === "mcp.json" || /^(tools|skills|plugins)\//.t
114
124
  export function compileFormat4(input, compile) {
115
125
  const byPath = new Map(input.entries.map((entry) => [entry.path, entry]));
116
126
  const library = input.entries.filter((entry) => isLibrary(entry.path));
117
- const ids = input.entries.map((entry) => subagentFileId(entry.path)).filter((id) => id !== undefined).sort(compare);
118
- const fronts = new Map(ids.map((id) => [id, frontOf(input.files.get(`agents/${id}.md`)) ?? {}]));
119
127
  const flowRoot = byPath.has(FLOW_FILE);
120
128
  const entries = [];
121
129
  const files = new Map(input.files);
122
130
  const extra = [];
123
- /** Where each subagent's flow file is, by id. */
131
+ /** Where each subagent's flow file is, by name. */
124
132
  const flows = new Map();
125
- // A folder under agents/ is format 3's: refused, and left out of the expansion.
133
+ // Every subagent file, the folder's own and its plugins', by the name it goes by.
134
+ const sources = new Map();
135
+ const fronts = new Map();
136
+ const labels = new Map();
137
+ const nameOf = (front, fallback) => (typeof front.name === "string" && SUBAGENT_NAME.test(front.name) ? front.name : fallback);
138
+ const take = (source, front) => {
139
+ const other = sources.get(source.name);
140
+ const tool = byPath.has(`tools/${source.name}.json`) ? `tools/${source.name}.json` : undefined;
141
+ if (other || (tool && source.plugin)) {
142
+ const where = other?.path ?? tool;
143
+ extra.push(source.plugin || other?.plugin
144
+ ? { severity: "error", code: "plugin_duplicate", message: `${source.name} is also ${where}: an agent has one subagent or tool of a name`, file: source.path }
145
+ : { severity: "error", code: "tool_twice", message: `${other.path} and ${source.path} both name the subagent ${source.name}: rename one`, file: source.path });
146
+ return;
147
+ }
148
+ sources.set(source.name, source);
149
+ fronts.set(source.name, front);
150
+ if (source.plugin)
151
+ labels.set(source.name, source.plugin);
152
+ };
153
+ for (const entry of [...input.entries].sort((a, b) => compare(a.path, b.path))) {
154
+ const id = subagentFileId(entry.path);
155
+ if (id === undefined)
156
+ continue;
157
+ const front = frontOf(input.files.get(entry.path)) ?? {};
158
+ take({ name: nameOf(front, id), path: entry.path }, front);
159
+ }
160
+ const pluginLabels = new Map();
161
+ for (const entry of [...input.entries].sort((a, b) => compare(a.path, b.path))) {
162
+ const match = PLUGIN_AGENTS.exec(entry.path);
163
+ if (!match)
164
+ continue;
165
+ const [, plugin, rest] = match;
166
+ const file = pluginSubagentFile(`agents/${rest}`);
167
+ // A flow file a subagent's `flow:` names is read from where it is when it is named.
168
+ if (file === undefined && pluginSubagentFlow(`agents/${rest}`))
169
+ continue;
170
+ if (file === undefined) {
171
+ extra.push({ severity: "note", code: "plugin_part_ignored", message: "Kept with the source: a plugin's subagents are its agents/*.md files", file: entry.path });
172
+ continue;
173
+ }
174
+ if (!pluginLabels.has(plugin))
175
+ pluginLabels.set(plugin, pluginLabelOf(jsonOf(input.files.get(`plugins/${plugin}/plugin.json`))));
176
+ // A plugin whose plugin.json names it nothing is refused by the plugin's own checks.
177
+ const label = pluginLabels.get(plugin);
178
+ if (!label)
179
+ continue;
180
+ const front = frontOf(input.files.get(entry.path)) ?? {};
181
+ take({ name: nameOf(front, file), path: entry.path, plugin: label }, front);
182
+ }
183
+ const names = [...sources.keys()].sort(compare);
184
+ // A folder under agents/ is format 3's: refused, and left out of the expansion. A plugin's
185
+ // subagent files are read above as subagents, and stay in the entries as the plugin's files.
126
186
  const folders = new Set();
127
187
  for (const entry of input.entries) {
128
188
  const segments = entry.path.split("/");
@@ -147,23 +207,24 @@ export function compileFormat4(input, compile) {
147
207
  if (bytes)
148
208
  files.set(path, bytes);
149
209
  };
150
- /** Expands one subagent file at `prefix` (`agents/<id>/`); `nested` is a flow subagent's own agents/ under a root driven by a model loop. */
151
- const expand = (prefix, id, namespace) => {
152
- const source = byPath.get(`agents/${id}.md`);
153
- if (!source)
210
+ /** Expands one subagent file at `prefix` (`agents/<name>/`); `namespace` is a flow subagent's own agents/ under a root driven by a model loop. */
211
+ const expand = (prefix, name, namespace) => {
212
+ const written = sources.get(name);
213
+ const source = written && byPath.get(written.path);
214
+ if (!written || !source)
154
215
  return;
155
216
  add(`${prefix}${AGENT_FILE}`, source);
156
- const front = fronts.get(id) ?? {};
217
+ const front = fronts.get(name) ?? {};
157
218
  if (front.flow === undefined) {
158
219
  for (const entry of library)
159
220
  add(prefix + entry.path, entry);
160
221
  return;
161
222
  }
162
- const flowPath = flowPathOf(front.flow);
223
+ const flowPath = flowPathOf(front.flow, written.path.slice(0, written.path.lastIndexOf("/")));
163
224
  const flowEntry = flowPath === undefined ? undefined : byPath.get(flowPath);
164
225
  if (!flowEntry || !flowPath)
165
226
  return;
166
- flows.set(id, flowPath);
227
+ flows.set(name, flowPath);
167
228
  add(`${prefix}${FLOW_FILE}`, flowEntry);
168
229
  const names = flowNames(jsonOf(input.files.get(flowPath)));
169
230
  for (const tool of names.tools) {
@@ -178,12 +239,14 @@ export function compileFormat4(input, compile) {
178
239
  if (fronts.has(stage) && !entries.some((entry) => entry.path === `${namespace}${stage}/${AGENT_FILE}`))
179
240
  expand(`${namespace}${stage}/`, stage, namespace);
180
241
  };
181
- for (const id of ids) {
182
- const front = fronts.get(id) ?? {};
183
- const prefix = `agents/${id}/`;
184
- expand(prefix, id, front.flow !== undefined && !flowRoot ? `${prefix}agents/` : undefined);
242
+ for (const name of names) {
243
+ const front = fronts.get(name) ?? {};
244
+ const prefix = `agents/${name}/`;
245
+ expand(prefix, name, front.flow !== undefined && !flowRoot ? `${prefix}agents/` : undefined);
185
246
  }
186
247
  const compiled = compile({ ...input, entries, files });
248
+ /** Where a subagent's file was written, by name. */
249
+ const writtenAt = (name) => sources.get(name)?.path ?? `agents/${name}.md`;
187
250
  /** A path of the expansion, as the folder people wrote names it. */
188
251
  const real = (path) => {
189
252
  let rest = path;
@@ -197,12 +260,12 @@ export function compileFormat4(input, compile) {
197
260
  }
198
261
  if (id === undefined) {
199
262
  const bare = /^agents\/([^/]+)$/.exec(path)?.[1];
200
- return bare !== undefined && fronts.has(bare) ? `agents/${bare}.md` : path;
263
+ return bare !== undefined && fronts.has(bare) ? writtenAt(bare) : path;
201
264
  }
202
265
  if (rest === AGENT_FILE || rest === "")
203
- return `agents/${id}.md`;
266
+ return writtenAt(id);
204
267
  if (rest === FLOW_FILE)
205
- return flows.get(id) ?? `agents/${id}.md`;
268
+ return flows.get(id) ?? writtenAt(id);
206
269
  return rest;
207
270
  };
208
271
  const seen = new Set();
@@ -222,7 +285,18 @@ export function compileFormat4(input, compile) {
222
285
  const order = { error: 0, warning: 1, info: 2, note: 3 };
223
286
  diagnostics.sort((a, b) => order[a.severity] - order[b.severity] || compare(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0));
224
287
  const failed = diagnostics.some((item) => item.severity === "error");
225
- return { ...(failed || !compiled.manifest ? {} : { manifest: compiled.manifest }), diagnostics, compiler: AGENT_FOLDER_V4 };
288
+ return { ...(failed || !compiled.manifest ? {} : { manifest: labelled(compiled.manifest, labels) }), diagnostics, compiler: AGENT_FOLDER_V4 };
289
+ }
290
+ /** The manifest with each plugin subagent's tool labelled with its plugin, as a plugin's skills and servers are. */
291
+ function labelled(manifest, labels) {
292
+ const harness = manifest?.harness;
293
+ if (labels.size === 0 || !harness || !Array.isArray(harness.tools))
294
+ return manifest;
295
+ const tools = harness.tools.map((tool) => {
296
+ const label = typeof tool.name === "string" && tool.agent !== undefined ? labels.get(tool.name) : undefined;
297
+ return label ? { ...tool, plugin: label } : tool;
298
+ });
299
+ return { ...manifest, harness: { ...harness, tools } };
226
300
  }
227
301
  /** A tool list as written: a YAML list, or a comma-separated string as Claude Code writes it. */
228
302
  function namesOf(value) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `agent-folder/3` (ADR-106): a folder declares the Runtime's features as plugins, by name, and
2
+ * `agent-folder/3`: a folder declares the Runtime's features as plugins, by name, and
3
3
  * narrows their tools with the settings any MCP server takes:
4
4
  *
5
5
  * ```yaml
@@ -26,7 +26,7 @@ export declare const AGENT_FOLDER_V3 = "agent-folder/3";
26
26
  export declare const V3_REFUSED_KEYS: readonly ["memory"];
27
27
  /**
28
28
  * The `loop` keys a v3 folder declares as plugins instead. `loop` itself stays the harness's own
29
- * settings, such as `compaction` (ADR-157).
29
+ * settings, such as `compaction`.
30
30
  */
31
31
  export declare const V3_REFUSED_LOOP_KEYS: readonly ["plan", "connections", "ask"];
32
32
  /** The keys of `engine:` a v3 folder declares as plugins instead. */
package/dist/folder/v3.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `agent-folder/3` (ADR-106): a folder declares the Runtime's features as plugins, by name, and
2
+ * `agent-folder/3`: a folder declares the Runtime's features as plugins, by name, and
3
3
  * narrows their tools with the settings any MCP server takes:
4
4
  *
5
5
  * ```yaml
@@ -26,7 +26,7 @@ export const AGENT_FOLDER_V3 = "agent-folder/3";
26
26
  export const V3_REFUSED_KEYS = ["memory"];
27
27
  /**
28
28
  * The `loop` keys a v3 folder declares as plugins instead. `loop` itself stays the harness's own
29
- * settings, such as `compaction` (ADR-157).
29
+ * settings, such as `compaction`.
30
30
  */
31
31
  export const V3_REFUSED_LOOP_KEYS = ["plan", "connections", "ask"];
32
32
  /** The keys of `engine:` a v3 folder declares as plugins instead. */
@@ -44,7 +44,7 @@ export interface ArtifactWriteOptions {
44
44
  readonly effectId?: string;
45
45
  /** The body's size when known: core refuses one past its limits before a byte is sent. */
46
46
  readonly size?: number;
47
- /** `model`: a new artifact stored only for the model to see, never an output (ADR-139). */
47
+ /** `model`: a new artifact stored only for the model to see, never an output. */
48
48
  readonly audience?: "model";
49
49
  /** The most bytes one chunk carries: the run's `turn.start.limits.chunkBytes`. */
50
50
  readonly chunkBytes: number;
@@ -52,16 +52,16 @@ export function harnessApiSchemas() {
52
52
  * The revision of v5's document: the claims a harness may make grew within v5 (`plan.updated`,
53
53
  * additive: core accepts more, and a v5 harness that claims none of it is unchanged), and a
54
54
  * published `$id` names one document for good. Revision 2: `engine.diagnostic` among the claims,
55
- * `turn.start.memory.index` absent for a version that pins none (ADR-100), and
55
+ * `turn.start.memory.index` absent for a version that pins none, and
56
56
  * `turn.start.memory.refresh` (an optional field a v5 harness may ignore, keeping the index it
57
- * pinned). Revision 3: `turn.start.agent.triggers` and the `runtime` operation `triggers` (D83),
57
+ * pinned). Revision 3: `turn.start.agent.triggers` and the `runtime` operation `triggers`,
58
58
  * which a v5 harness that offers no `triggers` tool never sees. Revision 4: the effect kind `inputs`
59
- (D85): the messages steered into the running turn, which core answers at once and a v5 harness
59
+ : the messages steered into the running turn, which core answers at once and a v5 harness
60
60
  that never asks for it never sees. Revision 5: `artifact.write` `begin` may carry
61
- `audience: "model"` (ADR-139), which core accepts and only our own engine sends. Revision 6:
62
- `routing.sandbox.computer` and the request `computer.open` (ADR-149), which a v5 harness never
61
+ `audience: "model"`, which core accepts and only our own engine sends. Revision 6:
62
+ `routing.sandbox.computer` and the request `computer.open`, which a v5 harness never
63
63
  sees unless the Tenant's pod Agents are computers. Revision 7: the request `computer.current`,
64
- which only a harness that drives computers sends. Revision 8: `turn.start.role` (ADR-157), the
64
+ which only a harness that drives computers sends. Revision 8: `turn.start.role`, the
65
65
  session's role, which the Runtime sends only to our own harness.
66
66
  */
67
67
  const SCHEMA_REVISION = 8;
@@ -24,7 +24,7 @@ export type ReleaseReason = z.infer<typeof ReleaseReasonSchema>;
24
24
  * outputs folder stores nothing (protocol 15), and `plan.updated` when the agent calls its
25
25
  * built-in `update_plan` tool, and `engine.diagnostic` when an agent's declarations leave it
26
26
  * something to say instead of choose, such as MCP tools past the deferral threshold of an agent
27
- * that does not declare tool search (ADR-100; both additive within v5).
27
+ * that does not declare tool search (both additive within v5).
28
28
  */
29
29
  export declare const HARNESS_CLAIMS: readonly ["environment.state", "environment.exec", "artifact.export.skipped", "artifact.export.failed", "plan.updated", "engine.diagnostic"];
30
30
  export type HarnessClaim = (typeof HARNESS_CLAIMS)[number];
@@ -8,7 +8,7 @@ export const ABORT_REASONS = ["cancel", "shutdown", "deadline", "ownership.lost"
8
8
  * outputs folder stores nothing (protocol 15), and `plan.updated` when the agent calls its
9
9
  * built-in `update_plan` tool, and `engine.diagnostic` when an agent's declarations leave it
10
10
  * something to say instead of choose, such as MCP tools past the deferral threshold of an agent
11
- * that does not declare tool search (ADR-100; both additive within v5).
11
+ * that does not declare tool search (both additive within v5).
12
12
  */
13
13
  export const HARNESS_CLAIMS = [
14
14
  "environment.state",
@@ -131,7 +131,7 @@ export declare const EffectTargetSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
131
131
  * A model effect that writes a compaction's summary says so (`purpose: "summary"`): it is no
132
132
  * assistant message, and the compaction edit that follows names it (`CompactionFactsSchema`).
133
133
  *
134
- * An `inputs` effect (D85, revision 4) asks core for the messages steered into the running turn
134
+ * An `inputs` effect (revision 4) asks core for the messages steered into the running turn
135
135
  * (`delivery: "steer"`), before a step: core takes them in the transaction that journals the
136
136
  * effect and answers `{value: {events}}` at once, the messages' input events in order (none when
137
137
  * nothing waits). The journal keeps the answer, so a replay takes the same messages at that step.
@@ -1009,7 +1009,7 @@ export declare const harnessRequests: {
1009
1009
  }, z.core.$strict>;
1010
1010
  };
1011
1011
  /**
1012
- * Opens the computer of the run's session (ADR-149, Harness API 5.6): `environmentId` must be
1012
+ * Opens the computer of the run's session (Harness API 5.6): `environmentId` must be
1013
1013
  * the run's `routing.sandbox.environmentId` with `computer: true`. Core wakes it, waits until it
1014
1014
  * is ready, writes a seed onto a new disk and runs the disk's setup when needed, and answers the
1015
1015
  * sandbox gateway's URL for it, a ticket the gateway and the computer check, and when the ticket
@@ -86,7 +86,7 @@ export const EffectTargetSchema = z.discriminatedUnion("kind", [
86
86
  * the effect id: `schedule_wake` books the session's next turn; `memory` is a
87
87
  * call of the `memory` tool, with Anthropic's memory tool parameters as its input,
88
88
  * on the Agent's memories; `triggers` lists, creates and deletes the triggers the session made
89
- * (D83, `TriggerToolInputSchema`). Answered at once, unless the Tenant's tool policy holds it
89
+ * (`TriggerToolInputSchema`). Answered at once, unless the Tenant's tool policy holds it
90
90
  * for a person; the harness never executes it.
91
91
  */
92
92
  z.object({ kind: z.literal("runtime"), operation: z.enum(["schedule_wake", "memory", "triggers"]) }).strict(),
@@ -101,7 +101,7 @@ export const EffectTargetSchema = z.discriminatedUnion("kind", [
101
101
  * A model effect that writes a compaction's summary says so (`purpose: "summary"`): it is no
102
102
  * assistant message, and the compaction edit that follows names it (`CompactionFactsSchema`).
103
103
  *
104
- * An `inputs` effect (D85, revision 4) asks core for the messages steered into the running turn
104
+ * An `inputs` effect (revision 4) asks core for the messages steered into the running turn
105
105
  * (`delivery: "steer"`), before a step: core takes them in the transaction that journals the
106
106
  * effect and answers `{value: {events}}` at once, the messages' input events in order (none when
107
107
  * nothing waits). The journal keeps the answer, so a replay takes the same messages at that step.
@@ -266,7 +266,7 @@ export const RunRoutingSchema = z
266
266
  */
267
267
  environment: z.record(z.string(), z.string()).optional(),
268
268
  /**
269
- * The sandbox is a computer (ADR-149, Harness API 5.6): an Agent Substrate actor whose
269
+ * The sandbox is a computer (Harness API 5.6): an Agent Substrate actor whose
270
270
  * engine runs no loop. A harness opens it with `computer.open` and sends its sandbox
271
271
  * calls to it through the sandbox gateway.
272
272
  */
@@ -339,7 +339,7 @@ export const TurnAgentSchema = z
339
339
  */
340
340
  selfWake: z.boolean().optional(),
341
341
  /**
342
- * The version the session runs declares `harness.engine.triggers` (D83): our engine offers
342
+ * The version the session runs declares `harness.engine.triggers`: our engine offers
343
343
  * the root agent the `triggers` tool, a `runtime` effect.
344
344
  */
345
345
  triggers: z.literal(true).optional(),
@@ -358,7 +358,7 @@ export const TurnMemorySchema = z
358
358
  .object({
359
359
  access: z.enum(["read_write", "read_only"]),
360
360
  instructions: z.string().optional(),
361
- /** Absent when the version sets `harness.memory.index: false` (ADR-100): nothing is pinned. */
361
+ /** Absent when the version sets `harness.memory.index: false`: nothing is pinned. */
362
362
  index: z.string().optional(),
363
363
  truncated: z.boolean(),
364
364
  /**
@@ -392,7 +392,7 @@ export const TurnStartSchema = z
392
392
  */
393
393
  loop: document.optional(),
394
394
  /**
395
- * The role the session was opened with (`PUT /v1/sessions/{id}` `role`, ADR-157), so a harness
395
+ * The role the session was opened with (`PUT /v1/sessions/{id}` `role`), so a harness
396
396
  * can use its settings for that role. Absent for a session opened without one.
397
397
  */
398
398
  role: z.string().min(1).max(64).optional(),
@@ -589,7 +589,7 @@ export const harnessRequests = {
589
589
  result: z.object({ base64: z.string() }).strict(),
590
590
  },
591
591
  /**
592
- * Opens the computer of the run's session (ADR-149, Harness API 5.6): `environmentId` must be
592
+ * Opens the computer of the run's session (Harness API 5.6): `environmentId` must be
593
593
  * the run's `routing.sandbox.environmentId` with `computer: true`. Core wakes it, waits until it
594
594
  * is ready, writes a seed onto a new disk and runs the disk's setup when needed, and answers the
595
595
  * sandbox gateway's URL for it, a ticket the gateway and the computer check, and when the ticket
@@ -675,7 +675,7 @@ export const harnessRequests = {
675
675
  effectId: id.optional(),
676
676
  base64: z.string().optional(),
677
677
  /**
678
- * `model` (ADR-139, revision 5): a file stored only for the model to see, never an
678
+ * `model` (revision 5): a file stored only for the model to see, never an
679
679
  * output. Only our own engine sends it; core accepts it within v5.
680
680
  */
681
681
  audience: ArtifactAudienceSchema.optional(),
@@ -15,15 +15,18 @@ import { AGENT_MANIFEST_V8_SCHEMA_VERSION, AgentManifestFileSchema, HARNESS_MANI
15
15
  * The revision of a document whose version kept its number while it gained an optional field (a
16
16
  * published `$id` names one document for good): agent manifest v8 and the harness file v1 took
17
17
  * `harness.model` (Host feature `agent-model`), published as `v8.1` and `v1.1`, then
18
- * `harness.engine` and `harness.memory.index` (ADR-100) and a secret slot's `toolPrefix` (Host
18
+ * `harness.engine` and `harness.memory.index` and a secret slot's `toolPrefix` (Host
19
19
  * feature `secret-routing`), published as agent manifest `v8.2`, harness file `v1.2` and runtime
20
- * file `v1.1`, then `harness.engine.triggers` and `runtime.limits.triggers` (D83), published as
20
+ * file `v1.1`, then `harness.engine.triggers` and `runtime.limits.triggers`, published as
21
21
  * agent manifest `v8.3`, harness file `v1.3` and runtime file `v1.2`, then `harness.engine.plugins`
22
- * (ADR-106), published as agent manifest `v8.4` and harness file `v1.4`, then `harness.roles`
23
- * (ADR-154), published as agent manifest `v8.5` and harness file `v1.5`.
22
+ *, published as agent manifest `v8.4` and harness file `v1.4`, then `harness.roles`
23
+ *, published as agent manifest `v8.5` and harness file `v1.5`, then a tool's `plugin` label (Host
24
+ * feature `plugin-subagents`), published as agent manifest `v8.6` and harness file `v1.6`, then a
25
+ * plugin's mounted `files` (Host feature `plugin-files`) and a skill's `disableModelInvocation`
26
+ * (Host feature `person-started-skills`), published as agent manifest `v8.7` and harness file `v1.7`.
24
27
  */
25
- const AGENT_MANIFEST_REVISION = 5;
26
- const HARNESS_MANIFEST_FILE_REVISION = 5;
28
+ const AGENT_MANIFEST_REVISION = 7;
29
+ const HARNESS_MANIFEST_FILE_REVISION = 7;
27
30
  const RUNTIME_MANIFEST_FILE_REVISION = 2;
28
31
  function document(schema, id, title) {
29
32
  const { $schema: _, ...definition } = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The Runtime's own Agent Plugins (ADR-106, D84): six plugins, one per Runtime primitive, which an
2
+ * The Runtime's own Agent Plugins: six plugins, one per Runtime primitive, which an
3
3
  * `agent-folder/3` folder declares by name (`plugins:`) and which share one reserved server,
4
4
  * `nylorun`. Their files are in `core/plugins/`; `bundle.generated.ts` holds them as data, so the
5
5
  * compiler, the engine's projection, the harness and the Runtime read the same bytes offline.