@nylorun/core 0.27.0-beta → 0.28.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 (43) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +3 -1
  3. package/dist/contracts.d.ts +153 -1
  4. package/dist/contracts.js +62 -7
  5. package/dist/define.d.ts +2 -1
  6. package/dist/define.js +2 -1
  7. package/dist/definition/cron.d.ts +15 -0
  8. package/dist/definition/cron.js +155 -0
  9. package/dist/definition/sections.d.ts +11 -0
  10. package/dist/definition/sections.js +29 -20
  11. package/dist/folder/compile.d.ts +43 -5
  12. package/dist/folder/compile.js +499 -88
  13. package/dist/folder/context.d.ts +97 -0
  14. package/dist/folder/context.js +79 -0
  15. package/dist/folder/decompile.d.ts +18 -0
  16. package/dist/folder/decompile.js +660 -0
  17. package/dist/folder/fix.d.ts +22 -0
  18. package/dist/folder/fix.js +191 -0
  19. package/dist/folder/flow.d.ts +42 -0
  20. package/dist/folder/flow.js +215 -0
  21. package/dist/folder/frontmatter.d.ts +5 -2
  22. package/dist/folder/frontmatter.js +8 -4
  23. package/dist/folder/index.d.ts +7 -2
  24. package/dist/folder/index.js +6 -1
  25. package/dist/folder/json-schema.d.ts +15 -0
  26. package/dist/folder/json-schema.js +212 -0
  27. package/dist/folder/nested.d.ts +24 -0
  28. package/dist/folder/nested.js +378 -0
  29. package/dist/folder/plugins.d.ts +23 -0
  30. package/dist/folder/plugins.js +155 -0
  31. package/dist/folder/schemas.d.ts +8 -0
  32. package/dist/folder/schemas.js +238 -0
  33. package/dist/folder/suggest.d.ts +13 -0
  34. package/dist/folder/suggest.js +63 -0
  35. package/dist/schemas/agent-folder/agent-md.schema.json +143 -0
  36. package/dist/schemas/agent-folder/flow.schema.json +466 -0
  37. package/dist/schemas/agent-folder/mcp.schema.json +59 -0
  38. package/dist/schemas/agent-folder/runtime.schema.json +447 -0
  39. package/dist/schemas/agent-folder/tool.schema.json +77 -0
  40. package/dist/schemas/agent-folder/trigger-md.schema.json +65 -0
  41. package/dist/utils/runtime-limits.d.ts +8 -0
  42. package/dist/utils/runtime-limits.js +19 -0
  43. package/package.json +8 -2
@@ -41,6 +41,17 @@ export declare function runtimeOf(manifest: Pick<AgentManifestV8, "runtime">): R
41
41
  * 3. The runtime's kind gives the harness the sandbox it needs (`sandboxNeedOf`).
42
42
  */
43
43
  export declare function sectionGaps(manifest: Pick<AgentManifestV8, "harness" | "runtime">): string[];
44
+ /** One gap of `sectionGapsAt`: the manifest field it is about, and why. */
45
+ export interface SectionGap {
46
+ /** The field in the manifest, such as `["harness", "tools", 0, "http", "credential"]`. */
47
+ readonly path: readonly (string | number)[];
48
+ readonly message: string;
49
+ }
50
+ /**
51
+ * `sectionGaps`, each with the manifest field it is about, so a caller that knows where each
52
+ * field came from (the agent folder compiler) can point at the file that wrote it.
53
+ */
54
+ export declare function sectionGapsAt(manifest: Pick<AgentManifestV8, "harness" | "runtime">): SectionGap[];
44
55
  /**
45
56
  * The loop manifest the harness runs for a version of an agent manifest: the harness section
46
57
  * with the manifest's name as its id, in the shape the engine reads (agent manifest v7, workflow
@@ -76,76 +76,85 @@ export function runtimeOf(manifest) {
76
76
  * 3. The runtime's kind gives the harness the sandbox it needs (`sandboxNeedOf`).
77
77
  */
78
78
  export function sectionGaps(manifest) {
79
+ return sectionGapsAt(manifest).map((gap) => gap.message);
80
+ }
81
+ /**
82
+ * `sectionGaps`, each with the manifest field it is about, so a caller that knows where each
83
+ * field came from (the agent folder compiler) can point at the file that wrote it.
84
+ */
85
+ export function sectionGapsAt(manifest) {
79
86
  const { harness } = manifest;
80
87
  const runtime = runtimeOf(manifest);
81
88
  const gaps = [];
89
+ const gap = (path, message) => gaps.push({ path, message });
82
90
  const kindText = manifest.runtime === undefined ? "the manifest has no runtime section" : `the runtime is ${quoted(runtime.kind)}`;
83
91
  // 1. A custom harness runs from its pod's image.
84
92
  const harnessId = harnessIdOf(harness);
85
93
  if (harnessId !== DEFAULT_HARNESS) {
86
94
  if (runtime.kind !== "pod")
87
- gaps.push(`harness.id ${quoted(harnessId)} needs runtime.kind "pod"; ${kindText}`);
95
+ gap(["harness", "id"], `harness.id ${quoted(harnessId)} needs runtime.kind "pod"; ${kindText}`);
88
96
  else if (runtime.image === undefined)
89
- gaps.push(`harness.id ${quoted(harnessId)} needs runtime.image: a custom harness runs from its pod's image`);
97
+ gap(["harness", "id"], `harness.id ${quoted(harnessId)} needs runtime.image: a custom harness runs from its pod's image`);
90
98
  }
91
99
  // 2. Credentials name declared slots of the right type.
92
100
  const slots = runtime.secrets ?? {};
93
- const urlSlot = (where, name, url, what) => {
101
+ const urlSlot = (where, path, name, url, what) => {
94
102
  const slot = slots[name];
95
103
  if (slot === undefined) {
96
- gaps.push(`${where} ${quoted(name)} is not a secret slot in runtime.secrets`);
104
+ gap(path, `${where} ${quoted(name)} is not a secret slot in runtime.secrets`);
97
105
  return;
98
106
  }
99
107
  if (slot.type !== "bearer" && slot.type !== "headers") {
100
- gaps.push(`${where} ${quoted(name)} is a slot of type ${slot.type}; ${what} needs a bearer or headers slot`);
108
+ gap(path, `${where} ${quoted(name)} is a slot of type ${slot.type}; ${what} needs a bearer or headers slot`);
101
109
  return;
102
110
  }
103
111
  const want = normalizeCredentialUrl(url);
104
112
  if (want === undefined || normalizeCredentialUrl(slot.url) !== want)
105
- gaps.push(`${where} ${quoted(name)} is bound to ${slot.url}, not to ${what}'s URL ${url}`);
113
+ gap(path, `${where} ${quoted(name)} is bound to ${slot.url}, not to ${what}'s URL ${url}`);
106
114
  };
107
115
  // The Tool Gate sends an HTTP target's `credential` from the vault by that name, wherever the
108
116
  // target sits: an agent's HTTP tool, a flow's HTTP stage or HTTP verifier, or one of an
109
117
  // embedded agent's.
110
- const agentTools = (tools, at) => {
111
- for (const tool of tools ?? []) {
118
+ const agentTools = (tools, at, path) => {
119
+ for (const [index, tool] of (tools ?? []).entries()) {
112
120
  if (tool.http?.credential !== undefined)
113
- urlSlot(`${at}.tools.${tool.name}.http.credential`, tool.http.credential, tool.http.url, "an HTTP tool");
121
+ urlSlot(`${at}.tools.${tool.name}.http.credential`, [...path, "tools", index, "http", "credential"], tool.http.credential, tool.http.url, "an HTTP tool");
114
122
  if (tool.agent !== undefined)
115
- embedded(tool.agent, `${at}.tools.${tool.name}.agent`);
123
+ embedded(tool.agent, `${at}.tools.${tool.name}.agent`, [...path, "tools", index, "agent"]);
116
124
  }
117
125
  };
118
- const flowStages = (flow, at) => {
126
+ const flowStages = (flow, at, path) => {
119
127
  forEachFlowNode(flow.root, ({ node, key, role }) => {
120
128
  const http = "http" in node ? node.http : "tool" in node ? node.tool.http : undefined;
121
129
  if (http?.credential !== undefined)
122
- urlSlot(`${at}.root stage ${quoted(key)} http.credential`, http.credential, http.url, role === "verify" ? "an HTTP verifier" : "an HTTP stage");
130
+ urlSlot(`${at}.root stage ${quoted(key)} http.credential`, [...path, "root"], http.credential, http.url, role === "verify" ? "an HTTP verifier" : "an HTTP stage");
123
131
  });
124
132
  for (const [id, agent] of Object.entries(flow.agents))
125
- embedded(agent, `${at}.agents.${id}`);
133
+ embedded(agent, `${at}.agents.${id}`, [...path, "agents", id]);
126
134
  };
127
- const embedded = (agent, at) => "kind" in agent ? flowStages(agent, at) : agentTools(agent.tools, at);
135
+ const embedded = (agent, at, path) => "kind" in agent ? flowStages(agent, at, path) : agentTools(agent.tools, at, path);
128
136
  if (isWorkflowHarness(harness))
129
- flowStages(harness, "harness");
137
+ flowStages(harness, "harness", ["harness"]);
130
138
  else {
131
139
  for (const [key, server] of Object.entries(harness.mcpServers ?? {}))
132
140
  if (server.credential !== undefined)
133
- urlSlot(`harness.mcpServers.${key}.credential`, server.credential, server.url, "an MCP server");
134
- agentTools(harness.tools, "harness");
141
+ urlSlot(`harness.mcpServers.${key}.credential`, ["harness", "mcpServers", key, "credential"], server.credential, server.url, "an MCP server");
142
+ agentTools(harness.tools, "harness", ["harness"]);
135
143
  for (const [key, skill] of Object.entries(harness.skills ?? {}))
136
144
  for (const name of skill.secrets ?? []) {
137
145
  const slot = slots[name];
146
+ const path = ["harness", "skills", key, "secrets"];
138
147
  if (slot === undefined)
139
- gaps.push(`harness.skills.${key}.secrets ${quoted(name)} is not a secret slot in runtime.secrets`);
148
+ gap(path, `harness.skills.${key}.secrets ${quoted(name)} is not a secret slot in runtime.secrets`);
140
149
  else if (slot.type !== "environment_secret" && slot.type !== "environment_variable")
141
- gaps.push(`harness.skills.${key}.secrets ${quoted(name)} is a slot of type ${slot.type}; a skill reads environment_secret or environment_variable slots`);
150
+ gap(path, `harness.skills.${key}.secrets ${quoted(name)} is a slot of type ${slot.type}; a skill reads environment_secret or environment_variable slots`);
142
151
  }
143
152
  }
144
153
  // 3. The sandbox the loop needs. A custom harness's pod is gap 1.
145
154
  const need = sandboxNeedOf(harness);
146
155
  if (need === "sandbox" && !kindMeets(runtime.kind, need)) {
147
156
  const what = isWorkflowHarness(harness) ? "harness.agents carry skills, which need" : "harness.skills needs";
148
- gaps.push(manifest.runtime === undefined
157
+ gap(["harness", isWorkflowHarness(harness) ? "agents" : "skills"], manifest.runtime === undefined
149
158
  ? `${what} a sandbox; the manifest has no runtime section, so an Agent made from it has none`
150
159
  : `${what} a sandbox; runtime.kind ${quoted(runtime.kind)} has none`);
151
160
  }
@@ -1,7 +1,11 @@
1
- import { type AgentManifestV8 } from "../contracts.js";
1
+ import { type AgentFolderFix, type AgentManifestV8 } from "../contracts.js";
2
+ import { type FolderScope } from "./nested.js";
2
3
  /** The compiler format this version builds: a folder with no `format`, or `format: 1`. */
3
4
  export declare const AGENT_FOLDER_COMPILER = "agent-folder/1";
4
- /** What a folder may hold. Fixed in this version; Tenant settings come later. */
5
+ /**
6
+ * What a folder may hold, unless `compileAgentFolder` is given other limits (a Tenant's Runtime
7
+ * limits `folderFiles`, `folderBytes` and `folderTextFileBytes`, which default to these).
8
+ */
5
9
  export declare const AGENT_FOLDER_LIMITS: Readonly<{
6
10
  /** Files in one folder. */
7
11
  files: 2000;
@@ -16,10 +20,13 @@ export interface AgentFolderEntry {
16
20
  readonly size: number;
17
21
  readonly sha256: string;
18
22
  }
23
+ export type { AgentFolderFix };
19
24
  /**
20
25
  * One problem or remark: an `error` keeps the folder from compiling; `warning`, `info` and
21
26
  * `note` do not. `file` is the folder path it is about, with the line and column when known,
22
- * and `pointer` the field in the manifest when it is about one.
27
+ * and `pointer` the field in the manifest when it is about one. `fix` is the edit that fixes it
28
+ * (`nylorun check --fix`), only where one edit can: an unknown key with one did-you-mean, CRLF
29
+ * line ends, and a `SKILL.md`'s `secrets`. It changes no manifest.
23
30
  */
24
31
  export interface AgentFolderDiagnostic {
25
32
  readonly severity: "error" | "warning" | "info" | "note";
@@ -29,6 +36,7 @@ export interface AgentFolderDiagnostic {
29
36
  readonly line?: number;
30
37
  readonly column?: number;
31
38
  readonly pointer?: string;
39
+ readonly fix?: AgentFolderFix;
32
40
  }
33
41
  export interface CompileAgentFolderInput {
34
42
  readonly entries: readonly AgentFolderEntry[];
@@ -36,6 +44,14 @@ export interface CompileAgentFolderInput {
36
44
  readonly files: ReadonlyMap<string, Uint8Array>;
37
45
  /** The name the manifest must have: the path's, or the folder's. */
38
46
  readonly name?: string;
47
+ /** What the folder may hold; each left out is `AGENT_FOLDER_LIMITS`'. */
48
+ readonly limits?: Partial<AgentFolderLimits>;
49
+ }
50
+ /** What a folder may hold: its files, their bytes together, and one Markdown or JSON file. */
51
+ export interface AgentFolderLimits {
52
+ readonly files: number;
53
+ readonly totalBytes: number;
54
+ readonly textFileBytes: number;
39
55
  }
40
56
  export interface CompiledAgentFolder {
41
57
  /** The manifest, when nothing is an error. */
@@ -43,7 +59,29 @@ export interface CompiledAgentFolder {
43
59
  readonly diagnostics: readonly AgentFolderDiagnostic[];
44
60
  readonly compiler: typeof AGENT_FOLDER_COMPILER;
45
61
  }
62
+ /**
63
+ * The schemas a JSON file of a folder may name in `$schema`, by the kind of file: ours first,
64
+ * whose documents `schemas.ts` builds from the key lists below.
65
+ */
66
+ export declare const FOLDER_SCHEMAS = "https://docs.nylorun.com/schemas/agent-folder/v1/";
67
+ export declare const SCHEMA_URLS: {
68
+ readonly runtime: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/runtime.json", "https://docs.nylorun.com/schemas/runtime-manifest/v1.json"];
69
+ readonly tool: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/tool.json"];
70
+ readonly mcp: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/mcp.json", "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json"];
71
+ readonly flow: readonly ["https://docs.nylorun.com/schemas/agent-folder/v1/flow.json"];
72
+ };
73
+ export declare const AGENT_KEYS: readonly ["name", "description", "format", "harness", "inputSchema", "outputSchema", "mcpServers", "skills", "memory", "loop", "metadata"];
74
+ export declare const TRIGGER_KEYS: readonly ["schedule", "timezone", "at", "webhook", "session"];
75
+ export declare const MCP_KEYS: readonly ["$schema", "mcpServers"];
76
+ export declare const SERVER_KEYS: readonly ["type", "url", "headers"];
77
+ export declare const SERVER_SETTING_KEYS: readonly ["deferred", "tools"];
78
+ /** What `AGENT.md` may also set for a plugin's server, which cannot know the agent's slot names. */
79
+ export declare const PLUGIN_SERVER_SETTING_KEYS: readonly ["deferred", "tools", "credential"];
80
+ export declare const TOOL_KEYS: readonly ["description", "inputSchema", "outputSchema", "http"];
46
81
  /** The files the compiler reads: the Runtime and the CLI pass their bytes in. */
47
82
  export declare function folderTextPaths(entries: readonly AgentFolderEntry[]): string[];
48
- /** Compiles an agent folder into agent manifest v8, with every diagnostic. */
49
- export declare function compileAgentFolder(input: CompileAgentFolderInput): CompiledAgentFolder;
83
+ /**
84
+ * Compiles an agent folder into agent manifest v8, with every diagnostic. `scope` is internal: the
85
+ * compiler sets it when it compiles a folder inside another (`agents/<id>/`, a plugin's parts).
86
+ */
87
+ export declare function compileAgentFolder(input: CompileAgentFolderInput, scope?: FolderScope): CompiledAgentFolder;