@nylorun/core 0.33.0-beta → 0.35.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/compatibility.d.ts +25 -1
  3. package/dist/compatibility.js +24 -0
  4. package/dist/contracts.d.ts +749 -17
  5. package/dist/contracts.js +360 -22
  6. package/dist/define.d.ts +1 -1
  7. package/dist/define.js +1 -1
  8. package/dist/definition/assemble.d.ts +2 -1
  9. package/dist/definition/assemble.js +1 -0
  10. package/dist/definition/from.js +1 -0
  11. package/dist/definition/manifest.d.ts +2 -1
  12. package/dist/definition/manifest.js +1 -0
  13. package/dist/definition/sections.d.ts +1 -1
  14. package/dist/definition/sections.js +5 -1
  15. package/dist/definition/variant.d.ts +16 -1
  16. package/dist/definition/variant.js +81 -3
  17. package/dist/engine/blocks.d.ts +54 -0
  18. package/dist/engine/blocks.js +162 -0
  19. package/dist/engine/explain.d.ts +36 -0
  20. package/dist/engine/explain.js +113 -0
  21. package/dist/engine/features.d.ts +28 -0
  22. package/dist/engine/features.js +34 -0
  23. package/dist/engine/index.d.ts +14 -0
  24. package/dist/engine/index.js +14 -0
  25. package/dist/engine/mcp.d.ts +119 -0
  26. package/dist/engine/mcp.js +267 -0
  27. package/dist/engine/names.d.ts +12 -0
  28. package/dist/engine/names.js +26 -0
  29. package/dist/engine/preview.d.ts +93 -0
  30. package/dist/engine/preview.js +120 -0
  31. package/dist/engine/projection.d.ts +63 -0
  32. package/dist/engine/projection.js +109 -0
  33. package/dist/engine/tools.d.ts +118 -0
  34. package/dist/engine/tools.js +508 -0
  35. package/dist/folder/compile.d.ts +11 -4
  36. package/dist/folder/compile.js +126 -13
  37. package/dist/folder/context.d.ts +5 -0
  38. package/dist/folder/decompile.js +22 -1
  39. package/dist/folder/engine.d.ts +73 -0
  40. package/dist/folder/engine.js +224 -0
  41. package/dist/folder/nested.js +6 -0
  42. package/dist/folder/schemas.js +47 -3
  43. package/dist/harness-api/harness-api.schema.json +29 -7
  44. package/dist/harness-api/json-schema.js +6 -2
  45. package/dist/harness-api/messages.d.ts +4 -2
  46. package/dist/harness-api/messages.js +4 -1
  47. package/dist/harness-api/schema.d.ts +15 -4
  48. package/dist/harness-api/schema.js +20 -4
  49. package/dist/manifest-schemas.js +9 -4
  50. package/dist/schemas/agent-folder/agent-md.schema.json +84 -3
  51. package/dist/schemas/agent-folder/runtime.schema.json +34 -1
  52. package/dist/schemas/agent-manifest.schema.json +166 -1
  53. package/dist/schemas/harness-manifest.schema.json +130 -1
  54. package/dist/schemas/runtime-manifest.schema.json +34 -1
  55. package/dist/types/manifest.d.ts +49 -0
  56. package/package.json +5 -1
@@ -0,0 +1,63 @@
1
+ /**
2
+ * What our engine adds to each agent of a session (protocol 15, ADR-100): the model-facing text
3
+ * and tools that come with the session's Agent (its computer, `selfWake`), its memory, its loop
4
+ * settings and the agent's skills, as the agent declares them (`engine`, `features.ts`). Our
5
+ * harness offers exactly this (`@nylorun/harness`'s `engineToolsFor`), and `previewTurn` shows it.
6
+ * One order keeps the prompt's prefix stable:
7
+ *
8
+ * - text: `skills` (the usage and the catalog); `sandbox`; `skill_folder`; `artifacts_save` and
9
+ * `outputs`; `artifacts_read`; `wake`; `triggers`; `memory`, then the agent's memory
10
+ * instructions; `plan`; `connection`;
11
+ * - tools: the sandbox tools; the skill tools; `save_artifact`; `read_artifact`; `schedule_wake`;
12
+ * `triggers`; `memory`; `update_plan`; `request_connection`.
13
+ *
14
+ * They come after the agent's own and before the session's MCP tools (`mcpToolSet`), and are
15
+ * not hashed.
16
+ */
17
+ import type { AgentManifest } from "../types/manifest.js";
18
+ import type { TurnAgent, TurnMemory } from "../harness-api/messages.js";
19
+ import { type EngineBlockUse } from "./blocks.js";
20
+ import { type EngineFeatures } from "./features.js";
21
+ import { type EngineTool, type SandboxToolLimits } from "./tools.js";
22
+ /** The harness's configuration of our engine's own tools that their definitions name. */
23
+ export interface EngineToolLimits {
24
+ /** The most bytes one `read_artifact` page holds, escaped as JSON. */
25
+ readonly artifactPageBytes: number;
26
+ /** The sandbox tools' limits: their schemas' maxima and defaults. */
27
+ readonly sandboxTools: SandboxToolLimits;
28
+ /** The most bytes of one skill file the skill tools read into the model's context. */
29
+ readonly skillReadBytes: number;
30
+ }
31
+ /** The default of the harness's `artifactPageBytes` setting: one `read_artifact` page. */
32
+ export declare const DEFAULT_ARTIFACT_PAGE_BYTES: number;
33
+ /** The most bytes of one skill file the skill tools read into the model's context by default. */
34
+ export declare const DEFAULT_SKILL_READ_BYTES: number;
35
+ /** Our engine's tool limits when the harness sets none. */
36
+ export declare const DEFAULT_ENGINE_TOOL_LIMITS: EngineToolLimits;
37
+ /** The memory an agent of the session reads: the turn's, and whether the agent is the root. */
38
+ export type EngineMemory = Pick<TurnMemory, "access" | "instructions"> & {
39
+ /** False for an agent used as a tool, which may only view memory. */
40
+ readonly root: boolean;
41
+ /** False when no index is pinned (`harness.memory.index: false`): the rules do not name one. */
42
+ readonly index?: boolean;
43
+ };
44
+ /** Our engine's tools for one agent, the text the model reads with them, in order, and its blocks. */
45
+ export interface EngineProjection {
46
+ readonly tools: readonly EngineTool[];
47
+ readonly instructions: readonly string[];
48
+ /** The text blocks the agent got, in order. */
49
+ readonly blocks: readonly EngineBlockUse[];
50
+ /** The features the agent got. */
51
+ readonly features: EngineFeatures;
52
+ }
53
+ /**
54
+ * Our engine's tools and text for `agent`, in a session on Agent `runsOn` (`turn.start.agent`)
55
+ * with its memory (`turn.start.memory`). `memory.root` is false for an agent used as a tool,
56
+ * which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
57
+ * the version sets `harness.loop.plan`; `connections` offers `request_connection` alike
58
+ * (`harness.loop.connections`). An agent whose own tools name one of them keeps its own.
59
+ * `triggers` offers the `triggers` tool and its text (D83): true for the session's root agent when
60
+ * the version declares `harness.engine.triggers` (`turn.start.agent.triggers`). What the agent
61
+ * declares (`agent.engine`) decides the rest; a block it replaces is in its words.
62
+ */
63
+ export declare function engineProjection(agent: Pick<AgentManifest, "skills" | "tools" | "engine">, runsOn: Pick<TurnAgent, "sandbox" | "selfWake"> | undefined, options: Pick<EngineToolLimits, "artifactPageBytes" | "sandboxTools">, memory?: EngineMemory, plan?: boolean, connections?: boolean, triggers?: boolean): EngineProjection;
@@ -0,0 +1,109 @@
1
+ import { ARTIFACTS_READ_TEXT, ARTIFACTS_SAVE_TEXT, CONNECTION_TEXT, ENGINE_BLOCK_VERSIONS, MEMORY_DATA_RULE, MEMORY_READ_ONLY_DATA_RULE, OUTPUTS_AFTER_SAVE_TEXT, OUTPUTS_TEXT, PLAN_TEXT, SKILLS_USAGE, TRIGGERS_TEXT, WAKE_TEXT, formatSkillCatalog, memoryRules, sandboxNote, skillFolderNote, } from "./blocks.js";
2
+ import { engineFeaturesOf } from "./features.js";
3
+ import { DEFAULT_SANDBOX_TOOL_LIMITS, REQUEST_CONNECTION_TOOL, TRIGGERS_TOOL, UPDATE_PLAN_TOOL, artifactTools, connectionToolOf, memoryToolOf, planToolOf, sandboxTools, skillTools, triggersToolOf, wakeToolOf, } from "./tools.js";
4
+ /** The default of the harness's `artifactPageBytes` setting: one `read_artifact` page. */
5
+ export const DEFAULT_ARTIFACT_PAGE_BYTES = 32 * 1024;
6
+ /** The most bytes of one skill file the skill tools read into the model's context by default. */
7
+ export const DEFAULT_SKILL_READ_BYTES = 10 * 1024 * 1024;
8
+ /** Our engine's tool limits when the harness sets none. */
9
+ export const DEFAULT_ENGINE_TOOL_LIMITS = Object.freeze({
10
+ artifactPageBytes: DEFAULT_ARTIFACT_PAGE_BYTES,
11
+ sandboxTools: DEFAULT_SANDBOX_TOOL_LIMITS,
12
+ skillReadBytes: DEFAULT_SKILL_READ_BYTES,
13
+ });
14
+ /**
15
+ * Our engine's tools and text for `agent`, in a session on Agent `runsOn` (`turn.start.agent`)
16
+ * with its memory (`turn.start.memory`). `memory.root` is false for an agent used as a tool,
17
+ * which may only view memory. `plan` offers `update_plan`: true for the session's root agent when
18
+ * the version sets `harness.loop.plan`; `connections` offers `request_connection` alike
19
+ * (`harness.loop.connections`). An agent whose own tools name one of them keeps its own.
20
+ * `triggers` offers the `triggers` tool and its text (D83): true for the session's root agent when
21
+ * the version declares `harness.engine.triggers` (`turn.start.agent.triggers`). What the agent
22
+ * declares (`agent.engine`) decides the rest; a block it replaces is in its words.
23
+ */
24
+ export function engineProjection(agent, runsOn, options, memory, plan = false, connections = false, triggers = false) {
25
+ const skills = Object.values(agent.skills ?? {});
26
+ const workspace = runsOn?.sandbox?.workspace;
27
+ const features = engineFeaturesOf(agent.engine, { computer: workspace !== undefined });
28
+ const replaced = agent.engine?.instructions ?? {};
29
+ const sandboxed = features.sandbox.length > 0;
30
+ const instructions = [];
31
+ const blocks = [];
32
+ const use = (name) => blocks.push({ name, version: ENGINE_BLOCK_VERSIONS[name] });
33
+ const text = (name, engine) => replaced[name] ?? engine;
34
+ if (skills.length > 0) {
35
+ use("skills");
36
+ instructions.push(text("skills", SKILLS_USAGE), formatSkillCatalog(skills.map(({ name, description }) => ({ name, description }))));
37
+ }
38
+ if (sandboxed) {
39
+ use("sandbox");
40
+ instructions.push(text("sandbox", sandboxNote(workspace)));
41
+ if (skills.length > 0) {
42
+ use("skill_folder");
43
+ const own = replaced.skill_folder;
44
+ instructions.push(own === undefined ? skillFolderNote(skills) : `${own}\n${skillFolderNote(skills)}`);
45
+ }
46
+ }
47
+ // The artifact notes: saving, the outputs folder, and reading.
48
+ const saving = features.artifactsSave ? text("artifacts_save", ARTIFACTS_SAVE_TEXT) : undefined;
49
+ const outputs = features.outputs ? text("outputs", saving === undefined ? OUTPUTS_TEXT : OUTPUTS_AFTER_SAVE_TEXT) : undefined;
50
+ if (saving !== undefined)
51
+ use("artifacts_save");
52
+ if (outputs !== undefined)
53
+ use("outputs");
54
+ if (saving !== undefined || outputs !== undefined)
55
+ instructions.push([saving, outputs].filter((item) => item !== undefined).join(" "));
56
+ if (features.artifactsRead) {
57
+ use("artifacts_read");
58
+ instructions.push(text("artifacts_read", ARTIFACTS_READ_TEXT));
59
+ }
60
+ // A session that may book its own next turn (track T4, D77).
61
+ const wake = runsOn?.selfWake === true;
62
+ if (wake) {
63
+ use("wake");
64
+ instructions.push(text("wake", WAKE_TEXT));
65
+ }
66
+ // The triggers the agent sets up itself (D83): the root agent's, when the version declares them.
67
+ const own = (name) => (agent.tools ?? []).some((tool) => tool.name === name);
68
+ const triggering = triggers && !own(TRIGGERS_TOOL);
69
+ if (triggering) {
70
+ use("triggers");
71
+ instructions.push(text("triggers", TRIGGERS_TEXT));
72
+ }
73
+ // The Agent's memory (track T5, D72).
74
+ const writes = memory !== undefined && memory.root && memory.access === "read_write";
75
+ if (memory) {
76
+ use("memory");
77
+ const own = replaced.memory;
78
+ // The rule that text from outside is data stays, whatever the folder's wording (ADR-100).
79
+ const rules = own === undefined ? memoryRules(writes, memory.index !== false) : `${own}\n${writes ? MEMORY_DATA_RULE : MEMORY_READ_ONLY_DATA_RULE}`;
80
+ instructions.push([rules, ...(memory.instructions ? [`Memory instructions for this agent:\n${memory.instructions}`] : [])].join("\n\n"));
81
+ }
82
+ // The agent's plan (A2A profile v2, `progress/v1`).
83
+ const planning = plan && !own(UPDATE_PLAN_TOOL);
84
+ if (planning) {
85
+ use("plan");
86
+ instructions.push(text("plan", PLAN_TEXT));
87
+ }
88
+ // The apps the agent asks to have connected (A2A profile v2, `interactions/v1` kind `connection`).
89
+ const connecting = connections && !own(REQUEST_CONNECTION_TOOL);
90
+ if (connecting) {
91
+ use("connection");
92
+ instructions.push(text("connection", CONNECTION_TEXT));
93
+ }
94
+ return {
95
+ tools: [
96
+ ...(sandboxed ? sandboxTools(options.sandboxTools, workspace, features.sandbox) : []),
97
+ ...skillTools(skills),
98
+ ...artifactTools({ read: features.artifactsRead, save: features.artifactsSave, sandboxed }, { pageBytes: options.artifactPageBytes }),
99
+ ...(wake ? [wakeToolOf()] : []),
100
+ ...(triggering ? [triggersToolOf()] : []),
101
+ ...(memory ? [memoryToolOf(writes)] : []),
102
+ ...(planning ? [planToolOf()] : []),
103
+ ...(connecting ? [connectionToolOf()] : []),
104
+ ],
105
+ instructions,
106
+ blocks,
107
+ features,
108
+ };
109
+ }
@@ -0,0 +1,118 @@
1
+ import { type SandboxToolName } from "../utils/sandbox.js";
2
+ import type { JsonObject } from "../types/shared.js";
3
+ import type { SkillManifest } from "../types/manifest.js";
4
+ import type { EffectTarget } from "../harness-api/messages.js";
5
+ /**
6
+ * A tool our engine adds to an agent for one execution (one of our engine's own, a session's MCP
7
+ * tool). It is not part of the hashed manifest.
8
+ */
9
+ export interface EngineTool {
10
+ /** The agent used as a tool that owns this tool; absent for the root agent. */
11
+ readonly agentId?: string;
12
+ readonly name: string;
13
+ readonly description?: string;
14
+ readonly inputSchema: JsonObject;
15
+ readonly outputSchema?: JsonObject;
16
+ /**
17
+ * Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
18
+ * with `tool_call`, which makes the call as this tool's own.
19
+ */
20
+ readonly deferred?: boolean;
21
+ /** Text the model reads, after the engine's, while this tool is advertised. */
22
+ readonly instructions?: readonly string[];
23
+ /** What runs its calls: their effects' `target` (an MCP tool's identity, our engine's `harness`). */
24
+ readonly target?: EffectTarget;
25
+ }
26
+ /** What the sandbox tools hold a call to: the harness's configuration of them. */
27
+ export interface SandboxToolLimits {
28
+ /** The characters of `bash` stdout and stderr each keeps, its middle cut past it. */
29
+ readonly outputChars: number;
30
+ /** Seconds a `bash` command runs when it names no `timeout`. */
31
+ readonly defaultTimeoutS: number;
32
+ /** The longest `timeout` a `bash` command may name, in seconds. */
33
+ readonly maxTimeoutS: number;
34
+ /** Lines `read` returns when it names no `limit`. */
35
+ readonly readLines: number;
36
+ /** The most lines one `read` may ask for. */
37
+ readonly maxReadLines: number;
38
+ /** The characters of one line `read` and `grep` show, the rest cut. */
39
+ readonly lineChars: number;
40
+ /** Matches `grep` returns when it names no `max_results`. */
41
+ readonly grepResults: number;
42
+ /** The most matches one `grep` may ask for. */
43
+ readonly maxGrepResults: number;
44
+ /** The most paths `glob` returns. */
45
+ readonly globResults: number;
46
+ /** The most files `glob` looks through. */
47
+ readonly globScan: number;
48
+ }
49
+ /** The sandbox tools' limits when the harness sets none. */
50
+ export declare const DEFAULT_SANDBOX_TOOL_LIMITS: SandboxToolLimits;
51
+ /** The limits in force: `set`, with the default for each it leaves out. */
52
+ export declare function sandboxToolLimitsOf(set?: Partial<SandboxToolLimits>): SandboxToolLimits;
53
+ /**
54
+ * The sandbox tools, in the order the model reads them, with `workspace` named in their text
55
+ * and `limits` in their schemas: all six, or those `names` lists (ADR-100, `engine.sandbox`),
56
+ * still in our order. Each is a `sandbox` effect named by its operation.
57
+ */
58
+ export declare function sandboxTools(limits: SandboxToolLimits, workspace: string, names?: readonly SandboxToolName[]): EngineTool[];
59
+ /** `save_artifact` (with `save`) and `read_artifact` (with `read`), which takes `path` with a sandbox. */
60
+ export declare function artifactTools(offer: {
61
+ readonly read: boolean;
62
+ readonly save: boolean;
63
+ readonly sandboxed: boolean;
64
+ }, options: {
65
+ readonly pageBytes: number;
66
+ }): EngineTool[];
67
+ /** Loads a skill's `SKILL.md`. */
68
+ export declare const LOAD_SKILL_TOOL = "load_skill";
69
+ /** Reads one resource file of a skill. */
70
+ export declare const READ_SKILL_RESOURCE_TOOL = "read_skill_resource";
71
+ /**
72
+ * `load_skill` for the agent's skills, and `read_skill_resource` when a skill has files besides
73
+ * `SKILL.md`. Empty for an agent without skills. Each runs in the harness.
74
+ */
75
+ export declare function skillTools(skills: readonly SkillManifest[]): EngineTool[];
76
+ /** The memory tool's name. */
77
+ export declare const MEMORY_TOOL = "memory";
78
+ /** `memory`: view, and the writes when the agent may write. A `runtime` effect, operation `memory`. */
79
+ export declare function memoryToolOf(writes: boolean): EngineTool;
80
+ /** The self-wake tool's name. */
81
+ export declare const SCHEDULE_WAKE_TOOL = "schedule_wake";
82
+ /** `schedule_wake` (track T4): a `runtime` effect. */
83
+ export declare function wakeToolOf(): EngineTool;
84
+ /** The triggers tool's name (D83). */
85
+ export declare const TRIGGERS_TOOL = "triggers";
86
+ /** What serves a `triggers` call: the Runtime, in the call's own transaction. */
87
+ export declare const RUNTIME_TRIGGERS: EffectTarget;
88
+ /**
89
+ * `triggers` (D83): list, create and delete the triggers the calling session made, for an agent
90
+ * whose version declares `engine.triggers`; the root agent's only. A `runtime` effect, operation
91
+ * `triggers`; its input is `TriggerToolInputSchema`'s.
92
+ */
93
+ export declare function triggersToolOf(): EngineTool;
94
+ /** The plan tool's name. */
95
+ export declare const UPDATE_PLAN_TOOL = "update_plan";
96
+ /** `update_plan` (A2A profile v2, `progress/v1`): runs in the harness. */
97
+ export declare function planToolOf(): EngineTool;
98
+ /** The connection tool's name. */
99
+ export declare const REQUEST_CONNECTION_TOOL = "request_connection";
100
+ /** The most characters of the app's name and of the reason. */
101
+ export declare const CONNECTION_LIMITS: Readonly<{
102
+ appChars: 80;
103
+ reasonChars: 280;
104
+ }>;
105
+ /** `request_connection` (A2A profile v2, `interactions/v1` kind `connection`): runs in the harness. */
106
+ export declare function connectionToolOf(): EngineTool;
107
+ /** Finds deferred tools by a query (BM25 over their names and descriptions). */
108
+ export declare const TOOL_SEARCH_TOOL = "tool_search";
109
+ /** Runs a deferred tool by name, as a call of that tool. */
110
+ export declare const TOOL_CALL_TOOL = "tool_call";
111
+ /**
112
+ * `tool_search` (ours, `harness`) and `tool_call`, as our engine gives them to an agent with
113
+ * deferred tools. `tool_call` makes the effect of the tool it names; it is never one itself.
114
+ */
115
+ export declare function deferredToolsTools(config: {
116
+ readonly toolSearchDefaultLimit: number;
117
+ readonly toolSearchMaxLimit: number;
118
+ }): readonly EngineTool[];