@nylorun/core 0.26.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 (47) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +6 -0
  3. package/dist/compatibility.d.ts +11 -2
  4. package/dist/compatibility.js +10 -0
  5. package/dist/contracts.d.ts +362 -0
  6. package/dist/contracts.js +131 -5
  7. package/dist/define.d.ts +2 -1
  8. package/dist/define.js +2 -1
  9. package/dist/definition/cron.d.ts +15 -0
  10. package/dist/definition/cron.js +155 -0
  11. package/dist/definition/sections.d.ts +11 -0
  12. package/dist/definition/sections.js +29 -20
  13. package/dist/folder/compile.d.ts +87 -0
  14. package/dist/folder/compile.js +1280 -0
  15. package/dist/folder/context.d.ts +97 -0
  16. package/dist/folder/context.js +79 -0
  17. package/dist/folder/decompile.d.ts +18 -0
  18. package/dist/folder/decompile.js +660 -0
  19. package/dist/folder/fix.d.ts +22 -0
  20. package/dist/folder/fix.js +191 -0
  21. package/dist/folder/flow.d.ts +42 -0
  22. package/dist/folder/flow.js +215 -0
  23. package/dist/folder/frontmatter.d.ts +21 -0
  24. package/dist/folder/frontmatter.js +91 -0
  25. package/dist/folder/index.d.ts +12 -0
  26. package/dist/folder/index.js +12 -0
  27. package/dist/folder/json-schema.d.ts +15 -0
  28. package/dist/folder/json-schema.js +212 -0
  29. package/dist/folder/json.d.ts +28 -0
  30. package/dist/folder/json.js +183 -0
  31. package/dist/folder/nested.d.ts +24 -0
  32. package/dist/folder/nested.js +378 -0
  33. package/dist/folder/plugins.d.ts +23 -0
  34. package/dist/folder/plugins.js +155 -0
  35. package/dist/folder/schemas.d.ts +8 -0
  36. package/dist/folder/schemas.js +238 -0
  37. package/dist/folder/suggest.d.ts +13 -0
  38. package/dist/folder/suggest.js +63 -0
  39. package/dist/schemas/agent-folder/agent-md.schema.json +143 -0
  40. package/dist/schemas/agent-folder/flow.schema.json +466 -0
  41. package/dist/schemas/agent-folder/mcp.schema.json +59 -0
  42. package/dist/schemas/agent-folder/runtime.schema.json +447 -0
  43. package/dist/schemas/agent-folder/tool.schema.json +77 -0
  44. package/dist/schemas/agent-folder/trigger-md.schema.json +65 -0
  45. package/dist/utils/runtime-limits.d.ts +8 -0
  46. package/dist/utils/runtime-limits.js +19 -0
  47. package/package.json +14 -3
@@ -0,0 +1,97 @@
1
+ /**
2
+ * What the agent folder compiler hands the code that compiles the folders inside a folder
3
+ * (`nested.ts`, `flow.ts`, `plugins.ts`): the folder's entries and files, what it has read so far,
4
+ * and its own ways to report, read and derive. Nothing here reads a file system: like the
5
+ * compiler, it is pure.
6
+ */
7
+ import type { AgentFolderDiagnostic, AgentFolderEntry, AgentFolderFix, CompileAgentFolderInput, CompiledAgentFolder } from "./compile.js";
8
+ import { type Position } from "./json.js";
9
+ /** A JSON Schema named by `/x` from a folder inside another: found, refused, or already reported. */
10
+ export type SchemaLookup = {
11
+ readonly schema: Record<string, unknown>;
12
+ } | {
13
+ readonly code: string;
14
+ readonly message: string;
15
+ } | undefined;
16
+ /** How the folder that holds this one sees it. Set by the compiler for each folder inside another. */
17
+ export interface FolderScope {
18
+ /** A subagent (`agents/<id>/` of an agent), a stage of a flow, or a plugin's skills and servers. */
19
+ readonly role: "subagent" | "stage" | "plugin";
20
+ /** For a stage: the flow root's `agents/`, which every `flow.json` under the root names. */
21
+ readonly namespace?: FlowNamespaceLike;
22
+ /** Derives a slot in the uploaded folder's runtime section; `file` is this folder's. */
23
+ readonly deriveSlot: (credential: string, type: "bearer" | "headers", url: string, file: string, at: Position | undefined, header?: string) => void;
24
+ /** `/x`: a JSON Schema file of the uploaded folder, by its path there. */
25
+ readonly schema: (target: string) => SchemaLookup;
26
+ }
27
+ /** What a loop manifest embeds for an agent of a flow: agent manifest v7 or workflow manifest v3. */
28
+ export type EmbeddedAgent = Record<string, unknown>;
29
+ /** A flow root's `agents/`: the stages its flows name by id. */
30
+ export interface FlowNamespaceLike {
31
+ readonly ids: readonly string[];
32
+ readonly used: Set<string>;
33
+ /** The stage's manifest, or why there is none: an unknown id, a cycle, or errors reported already. */
34
+ resolve(id: string): EmbeddedAgent | "unknown" | "cycle" | "failed";
35
+ }
36
+ type Severity = AgentFolderDiagnostic["severity"];
37
+ /**
38
+ * `fix` is the diagnostic's fix-it; `rename` the keys an unknown key at `path` may be meant as,
39
+ * from which the compiler makes a `rename_key` fix when exactly one is closest.
40
+ */
41
+ export type ReportOptions = {
42
+ key?: boolean;
43
+ at?: Position;
44
+ pointer?: string;
45
+ fix?: AgentFolderFix;
46
+ rename?: readonly string[];
47
+ };
48
+ export type Report = (severity: Severity, code: string, message: string, file?: string, path?: readonly PropertyKey[], options?: ReportOptions) => void;
49
+ export type Origins = [readonly PropertyKey[], {
50
+ readonly file: string;
51
+ readonly path: readonly PropertyKey[];
52
+ }][];
53
+ /** One folder's compile, as the parts inside it see it. */
54
+ export interface FolderContext {
55
+ readonly scope: FolderScope | undefined;
56
+ /** The folder's valid entries, by path. */
57
+ readonly entries: ReadonlyMap<string, AgentFolderEntry>;
58
+ /** The bytes of the files the compiler reads (`folderTextPaths`), by path. */
59
+ readonly files: ReadonlyMap<string, Uint8Array>;
60
+ /** What each valid path is (`classify` in compile.ts). */
61
+ readonly kinds: ReadonlyMap<string, string>;
62
+ /** `AGENT.md`'s frontmatter, and its body. */
63
+ readonly front: Record<string, unknown>;
64
+ readonly agent: {
65
+ readonly body: string;
66
+ readonly bodyLine: number;
67
+ } | undefined;
68
+ /** The harness section being built. */
69
+ readonly harness: Record<string, unknown>;
70
+ readonly origins: Origins;
71
+ readonly diagnostics: AgentFolderDiagnostic[];
72
+ readonly report: Report;
73
+ readonly readJson: (path: string) => Record<string, unknown> | undefined;
74
+ readonly schemaAt: (file: string, field: readonly PropertyKey[], value: unknown) => Record<string, unknown> | undefined;
75
+ /** A JSON file's `$schema`: accepted, and a warning when it names another kind's schema. */
76
+ readonly checkSchemaUrl: (file: string, kind: "runtime" | "tool" | "mcp" | "flow", value: unknown) => void;
77
+ readonly deriveSlot: (credential: string, type: "bearer" | "headers", url: string, file: string, path: readonly PropertyKey[], header?: string, at?: Position) => void;
78
+ readonly suggest: (name: string, known: readonly string[]) => string | undefined;
79
+ readonly compile: (input: CompileAgentFolderInput, scope?: FolderScope) => CompiledAgentFolder;
80
+ readonly folderTextPaths: (entries: readonly AgentFolderEntry[]) => string[];
81
+ }
82
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
83
+ export declare const compare: (a: string, b: string) => -1 | 0 | 1;
84
+ /** The folders directly under `top/` (`agents`, `plugins`), each with its paths inside it. */
85
+ export declare function foldersUnder(top: string, paths: Iterable<string>): Map<string, string[]>;
86
+ /**
87
+ * A diagnostic of a folder inside this one, with its path from this folder, and its fix's; the
88
+ * manifest pointer is the inner folder's, so it is left out.
89
+ */
90
+ export declare function addInner(ctx: FolderContext, prefix: string, inner: readonly AgentFolderDiagnostic[], file?: (path: string) => string): void;
91
+ /** Where `path` is in a JSON file of the folder this compile has not parsed itself (a plugin's, say). */
92
+ export declare function jsonPosition(ctx: FolderContext, file: string, path: readonly PropertyKey[], key?: boolean): Position | undefined;
93
+ /** A JSON file's top-level value, read quietly: undefined when it is not a JSON object. */
94
+ export declare function quietJson(ctx: FolderContext, file: string): Record<string, unknown> | undefined;
95
+ /** A deep copy of plain JSON data, so a manifest never shares objects with a constant. */
96
+ export declare const cloneJson: <T>(value: T) => T;
97
+ export {};
@@ -0,0 +1,79 @@
1
+ import { parseJson, pointerOf } from "./json.js";
2
+ export const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
3
+ export const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
4
+ /** The folders directly under `top/` (`agents`, `plugins`), each with its paths inside it. */
5
+ export function foldersUnder(top, paths) {
6
+ const folders = new Map();
7
+ for (const path of paths) {
8
+ const segments = path.split("/");
9
+ if (segments[0] !== top || segments.length < 3)
10
+ continue;
11
+ const name = segments[1];
12
+ folders.set(name, [...(folders.get(name) ?? []), segments.slice(2).join("/")]);
13
+ }
14
+ return new Map([...folders].sort(([a], [b]) => compare(a, b)));
15
+ }
16
+ /**
17
+ * A diagnostic of a folder inside this one, with its path from this folder, and its fix's; the
18
+ * manifest pointer is the inner folder's, so it is left out.
19
+ */
20
+ export function addInner(ctx, prefix, inner, file = (path) => prefix + path) {
21
+ for (const item of inner) {
22
+ const where = item.file === undefined ? (item.code === "agent_missing" ? `${prefix}AGENT.md` : prefix.replace(/\/$/, "")) : file(item.file);
23
+ const moved = {
24
+ severity: item.severity,
25
+ code: item.code,
26
+ message: item.message,
27
+ file: where,
28
+ ...(item.line === undefined ? {} : { line: item.line, column: item.column }),
29
+ ...(item.fix === undefined ? {} : { fix: { ...item.fix, file: file(item.fix.file) } }),
30
+ };
31
+ const key = JSON.stringify(moved);
32
+ if (!ctx.diagnostics.some((existing) => JSON.stringify(existing) === key))
33
+ ctx.diagnostics.push(moved);
34
+ }
35
+ }
36
+ const parsedJson = new WeakMap();
37
+ const decoder = new TextDecoder("utf-8", { fatal: true });
38
+ /** Where `path` is in a JSON file of the folder this compile has not parsed itself (a plugin's, say). */
39
+ export function jsonPosition(ctx, file, path, key = false) {
40
+ const bytes = ctx.files.get(file);
41
+ if (!bytes)
42
+ return undefined;
43
+ if (!parsedJson.has(bytes)) {
44
+ let positions = null;
45
+ try {
46
+ const result = parseJson(decoder.decode(bytes).replace(/^/, ""));
47
+ if (result.ok)
48
+ positions = result.positions;
49
+ }
50
+ catch {
51
+ positions = null;
52
+ }
53
+ parsedJson.set(bytes, positions);
54
+ }
55
+ const positions = parsedJson.get(bytes);
56
+ if (!positions)
57
+ return undefined;
58
+ for (let length = path.length; length >= 0; length--) {
59
+ const found = positions.get(pointerOf(path.slice(0, length)));
60
+ if (found)
61
+ return key && length === path.length ? (found.key ?? found.value) : found.value;
62
+ }
63
+ return undefined;
64
+ }
65
+ /** A JSON file's top-level value, read quietly: undefined when it is not a JSON object. */
66
+ export function quietJson(ctx, file) {
67
+ const bytes = ctx.files.get(file);
68
+ if (!bytes)
69
+ return undefined;
70
+ try {
71
+ const result = parseJson(decoder.decode(bytes).replace(/^/, ""));
72
+ return result.ok && isObject(result.value) ? result.value : undefined;
73
+ }
74
+ catch {
75
+ return undefined;
76
+ }
77
+ }
78
+ /** A deep copy of plain JSON data, so a manifest never shares objects with a constant. */
79
+ export const cloneJson = (value) => JSON.parse(JSON.stringify(value));
@@ -0,0 +1,18 @@
1
+ import type { AgentManifestV8 } from "../contracts.js";
2
+ export interface FolderOfManifestOptions {
3
+ /**
4
+ * The bytes behind the manifest's file hashes (`sha256:<hex>`): its skills' files and its
5
+ * `runtime.files`. Without them a skill is a placeholder and `runtime.files` stay by hash.
6
+ */
7
+ readonly files?: ReadonlyMap<string, Uint8Array>;
8
+ }
9
+ export interface FolderOfManifest {
10
+ /** Each file of the folder by its `/`-separated path: text, or the bytes of a skill's file. */
11
+ readonly files: Map<string, Uint8Array | string>;
12
+ /** What the folder leaves out or writes differently from the manifest, as a person reads it. */
13
+ readonly notes: string[];
14
+ /** Whether the folder compiles back to a manifest with the same hash. */
15
+ readonly exact: boolean;
16
+ }
17
+ /** Writes the agent folder of `manifest`; see the module comment for what it covers. */
18
+ export declare function folderOfManifest(manifest: AgentManifestV8, options?: FolderOfManifestOptions): FolderOfManifest;