@nylorun/core 0.16.0-beta → 0.18.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 (39) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +10 -0
  3. package/dist/compatibility.d.ts +18 -11
  4. package/dist/compatibility.js +18 -11
  5. package/dist/contracts.d.ts +176 -50
  6. package/dist/contracts.js +289 -85
  7. package/dist/define.d.ts +6 -5
  8. package/dist/define.js +3 -2
  9. package/dist/definition/assemble.d.ts +3 -1
  10. package/dist/definition/assemble.js +3 -0
  11. package/dist/definition/code-tools.d.ts +4 -4
  12. package/dist/definition/code-tools.js +3 -2
  13. package/dist/definition/from.d.ts +5 -0
  14. package/dist/definition/from.js +31 -188
  15. package/dist/definition/manifest.d.ts +3 -1
  16. package/dist/definition/manifest.js +4 -1
  17. package/dist/definition/mcp.d.ts +45 -1
  18. package/dist/definition/mcp.js +85 -2
  19. package/dist/definition/removed.d.ts +8 -3
  20. package/dist/definition/removed.js +13 -4
  21. package/dist/definition/sandbox-capability.d.ts +21 -4
  22. package/dist/definition/sandbox-capability.js +56 -19
  23. package/dist/definition/tools-capability.d.ts +37 -0
  24. package/dist/definition/tools-capability.js +98 -0
  25. package/dist/definition/variant.d.ts +2 -1
  26. package/dist/definition/variant.js +40 -4
  27. package/dist/harness-api/messages.d.ts +30 -352
  28. package/dist/harness-api/messages.js +2 -6
  29. package/dist/harness-api/schema.d.ts +701 -13
  30. package/dist/harness-api/schema.js +129 -53
  31. package/dist/harness-api/transcript.d.ts +8 -6
  32. package/dist/harness-api/transcript.js +4 -5
  33. package/dist/project.d.ts +67 -0
  34. package/dist/project.js +210 -0
  35. package/dist/transport.d.ts +52 -0
  36. package/dist/transport.js +73 -0
  37. package/dist/types/manifest.d.ts +42 -14
  38. package/dist/types/tool.d.ts +22 -0
  39. package/package.json +9 -1
@@ -15,19 +15,69 @@ export const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
15
15
  */
16
16
  export const ARTIFACTS_CAPABILITY_ID = "nylorun.artifacts";
17
17
  export const SAVE_ARTIFACT_TOOL = "save_artifact";
18
+ /**
19
+ * The tool that reads an artifact of the session in pages (R2b C11, Q24): how the model reads a
20
+ * tool result the Runtime stored because it was too large to show. With or without a sandbox.
21
+ */
22
+ export const READ_ARTIFACT_TOOL = "read_artifact";
23
+ /** The most `read_artifact` returns per call (R2b C11): 32 KiB, the inline cap of a tool result. */
24
+ export const READ_ARTIFACT_MAX_BYTES = 32 * 1024;
18
25
  const ARTIFACTS_INSTRUCTIONS = "Use save_artifact to hand the user a file you made: a path in the sandbox, or text you pass as content. " +
19
26
  "The user sees it as an artifact of this session and can download it; reply with its name, not its bytes. " +
20
27
  "Files you write under /workspace/outputs reach the user too: when your turn ends, they become the session's outputs folder.";
28
+ const READ_ARTIFACT_INSTRUCTIONS = "A tool result too large to show is saved as an artifact of this session: the result says truncated: true, with its artifactId, its size in bytes and a preview of its start and end. " +
29
+ "Images and other files a tool returns are saved as artifacts too. Use read_artifact to read more of one, a page at a time, only when the preview is not enough.";
21
30
  async function artifactsRuntimeOnly() {
22
- throw new ToolError("artifacts.runtime-only", "save_artifact runs in the Nylorun Runtime. Connect the agent to a Runtime to use it.");
31
+ throw new ToolError("artifacts.runtime-only", "The artifact tools run in the Nylorun Runtime. Connect the agent to a Runtime to use them.");
23
32
  }
24
33
  /**
25
- * The capability manifest that gives a session `save_artifact`: one tool that stores a sandbox
26
- * file, or inline text, as a file artifact of the session. Its schema is part of the hashed
27
- * manifest; change it deliberately.
34
+ * The capability manifest that gives a session `save_artifact`, which stores a sandbox file, or
35
+ * inline text, as a file artifact of the session, and `read_artifact`, which reads one in pages.
36
+ * Its schemas are part of the hashed manifest; change them deliberately.
28
37
  */
29
- export function artifactsCapabilityManifest() {
30
- const saveArtifact = tool({
38
+ export function artifactsCapabilityManifest(options = {}) {
39
+ const save = options.save ?? true;
40
+ const read = options.read ?? false;
41
+ const tools = [...(save ? [saveArtifactTool()] : []), ...(read ? [readArtifactTool()] : [])];
42
+ return {
43
+ id: ARTIFACTS_CAPABILITY_ID,
44
+ type: "agent",
45
+ instructions: [
46
+ ...(save ? [ARTIFACTS_INSTRUCTIONS] : []),
47
+ ...(read ? [READ_ARTIFACT_INSTRUCTIONS] : []),
48
+ ],
49
+ tools: tools.map((item) => {
50
+ const schemas = normalizedSchemasFor(item);
51
+ return {
52
+ name: item.name,
53
+ ...(item.description === undefined ? {} : { description: item.description }),
54
+ inputSchema: schemas.inputSchema.jsonSchema,
55
+ };
56
+ }),
57
+ };
58
+ }
59
+ function readArtifactTool() {
60
+ return tool({
61
+ name: READ_ARTIFACT_TOOL,
62
+ description: `Read a text artifact of this session, such as a tool result marked truncated: up to ${READ_ARTIFACT_MAX_BYTES} bytes from offset. ` +
63
+ "Returns content, and nextOffset while more remains: pass it as offset to read on. An image is shown to you when you can see images.",
64
+ inputSchema: z.object({
65
+ artifactId: z.string().min(1).describe("The artifact to read, e.g. a truncated result's artifactId."),
66
+ offset: z.number().int().min(0).optional().describe("The byte to start at. Default 0."),
67
+ length: z
68
+ .number()
69
+ .int()
70
+ .min(1)
71
+ .max(READ_ARTIFACT_MAX_BYTES)
72
+ .optional()
73
+ .describe(`How many bytes to read. Default and most: ${READ_ARTIFACT_MAX_BYTES}.`),
74
+ }),
75
+ effects: "read",
76
+ execute: artifactsRuntimeOnly,
77
+ });
78
+ }
79
+ function saveArtifactTool() {
80
+ return tool({
31
81
  name: SAVE_ARTIFACT_TOOL,
32
82
  description: `Save a file as an artifact of this session, for the user to download. Give path (a file in the sandbox; relative paths resolve under ${SANDBOX_WORKSPACE}) or content (text), not both. ` +
33
83
  "Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.",
@@ -50,19 +100,6 @@ export function artifactsCapabilityManifest() {
50
100
  effects: "write",
51
101
  execute: artifactsRuntimeOnly,
52
102
  });
53
- const schemas = normalizedSchemasFor(saveArtifact);
54
- return {
55
- id: ARTIFACTS_CAPABILITY_ID,
56
- type: "agent",
57
- instructions: [ARTIFACTS_INSTRUCTIONS],
58
- tools: [
59
- {
60
- name: saveArtifact.name,
61
- ...(saveArtifact.description === undefined ? {} : { description: saveArtifact.description }),
62
- inputSchema: schemas.inputSchema.jsonSchema,
63
- },
64
- ],
65
- };
66
103
  }
67
104
  /**
68
105
  * The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
@@ -0,0 +1,37 @@
1
+ import type { CapabilityManifest, ToolManifest } from "../types/manifest.js";
2
+ /**
3
+ * Id of the capability that holds `tool_search` and `tool_call` (R2b C10): the Runtime adds it at
4
+ * session open to each agent with a remote MCP server, empty. When some of the agent's MCP tools
5
+ * are deferred, the session's tools put `tool_search` and `tool_call` in it.
6
+ */
7
+ export declare const TOOLS_CAPABILITY_ID = "nylorun.tools";
8
+ /** Finds deferred tools by a query (BM25 over their names and descriptions). */
9
+ export declare const TOOL_SEARCH_TOOL = "tool_search";
10
+ /** Runs a deferred tool by name, as a call of that tool. */
11
+ export declare const TOOL_CALL_TOOL = "tool_call";
12
+ /** How many tools `tool_search` returns when the model sets no `limit`. */
13
+ export declare const TOOL_SEARCH_DEFAULT_LIMIT = 8;
14
+ /** The most tools one `tool_search` returns. */
15
+ export declare const TOOL_SEARCH_MAX_LIMIT = 20;
16
+ /** How much of a server's own instructions the model sees in the deferred tools' note. */
17
+ export declare const SERVER_INSTRUCTIONS_MAX_CHARS = 2000;
18
+ /** A server some of whose tools are deferred, as the model's note names it. */
19
+ export interface DeferredServerNote {
20
+ readonly serverName: string;
21
+ /** How many of its tools are deferred. */
22
+ readonly tools: number;
23
+ /** The server's own instructions (MCP `initialize`), if it gave any. */
24
+ readonly instructions?: string;
25
+ }
26
+ /** The capability the Runtime adds to an agent with a remote MCP server: empty, until tools are deferred. */
27
+ export declare function toolsCapabilityManifest(): CapabilityManifest;
28
+ /**
29
+ * `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
30
+ * schemas reach the model; change them deliberately.
31
+ */
32
+ export declare function deferredToolsTools(): readonly ToolManifest[];
33
+ /**
34
+ * The note the model reads beside `tool_search`: each server with deferred tools, how many, and
35
+ * its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
36
+ */
37
+ export declare function deferredToolsInstructions(servers: readonly DeferredServerNote[]): string;
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ import { tool } from "./helpers.js";
3
+ import { ToolError } from "./tool-error.js";
4
+ import { normalizedSchemasFor } from "./schema.js";
5
+ /**
6
+ * Id of the capability that holds `tool_search` and `tool_call` (R2b C10): the Runtime adds it at
7
+ * session open to each agent with a remote MCP server, empty. When some of the agent's MCP tools
8
+ * are deferred, the session's tools put `tool_search` and `tool_call` in it.
9
+ */
10
+ export const TOOLS_CAPABILITY_ID = "nylorun.tools";
11
+ /** Finds deferred tools by a query (BM25 over their names and descriptions). */
12
+ export const TOOL_SEARCH_TOOL = "tool_search";
13
+ /** Runs a deferred tool by name, as a call of that tool. */
14
+ export const TOOL_CALL_TOOL = "tool_call";
15
+ /** How many tools `tool_search` returns when the model sets no `limit`. */
16
+ export const TOOL_SEARCH_DEFAULT_LIMIT = 8;
17
+ /** The most tools one `tool_search` returns. */
18
+ export const TOOL_SEARCH_MAX_LIMIT = 20;
19
+ /** How much of a server's own instructions the model sees in the deferred tools' note. */
20
+ export const SERVER_INSTRUCTIONS_MAX_CHARS = 2_000;
21
+ async function toolsRuntimeOnly() {
22
+ throw new ToolError("tools.runtime-only", "tool_search and tool_call run in the Nylorun Runtime. Connect the agent to a Runtime to use them.");
23
+ }
24
+ /** The capability the Runtime adds to an agent with a remote MCP server: empty, until tools are deferred. */
25
+ export function toolsCapabilityManifest() {
26
+ return {
27
+ id: TOOLS_CAPABILITY_ID,
28
+ type: "agent",
29
+ description: "Deferred MCP tools: tool_search finds them and tool_call runs them.",
30
+ };
31
+ }
32
+ /**
33
+ * `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
34
+ * schemas reach the model; change them deliberately.
35
+ */
36
+ export function deferredToolsTools() {
37
+ return [searchTool(), callTool()].map((item) => {
38
+ const schemas = normalizedSchemasFor(item);
39
+ return {
40
+ name: item.name,
41
+ ...(item.description === undefined ? {} : { description: item.description }),
42
+ inputSchema: schemas.inputSchema.jsonSchema,
43
+ };
44
+ });
45
+ }
46
+ /**
47
+ * The note the model reads beside `tool_search`: each server with deferred tools, how many, and
48
+ * its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
49
+ */
50
+ export function deferredToolsInstructions(servers) {
51
+ const lines = servers.map((server) => {
52
+ const head = `- ${server.serverName}: ${server.tools} tool${server.tools === 1 ? "" : "s"}`;
53
+ const text = server.instructions?.trim();
54
+ if (!text)
55
+ return head;
56
+ const cut = text.length > SERVER_INSTRUCTIONS_MAX_CHARS
57
+ ? `${text.slice(0, SERVER_INSTRUCTIONS_MAX_CHARS)}…`
58
+ : text;
59
+ return `${head}. The server says: ${cut}`;
60
+ });
61
+ return [
62
+ "Some tools of these MCP servers are not in your tool list. Find them with tool_search (a few words of what you need), then run one with tool_call, passing its name and arguments that match its inputSchema.",
63
+ ...lines,
64
+ ].join("\n");
65
+ }
66
+ function searchTool() {
67
+ return tool({
68
+ name: TOOL_SEARCH_TOOL,
69
+ description: "Search the tools not in your tool list by name and description. Returns the best matches, each with its name, description and inputSchema. Run one with tool_call.",
70
+ inputSchema: z.object({
71
+ query: z.string().min(1).describe("Words of what the tool does, or of its name."),
72
+ limit: z
73
+ .number()
74
+ .int()
75
+ .min(1)
76
+ .max(TOOL_SEARCH_MAX_LIMIT)
77
+ .optional()
78
+ .describe(`How many tools to return. Default ${TOOL_SEARCH_DEFAULT_LIMIT}.`),
79
+ }),
80
+ effects: "read",
81
+ execute: toolsRuntimeOnly,
82
+ });
83
+ }
84
+ function callTool() {
85
+ return tool({
86
+ name: TOOL_CALL_TOOL,
87
+ description: "Run a tool tool_search found, by its name. arguments must match that tool's inputSchema; the result is the tool's own.",
88
+ inputSchema: z.object({
89
+ name: z.string().min(1).describe("The tool's name, as tool_search returned it."),
90
+ arguments: z
91
+ .record(z.string(), z.unknown())
92
+ .optional()
93
+ .describe("The tool's arguments, matching its inputSchema. Default {}."),
94
+ }),
95
+ effects: "write",
96
+ execute: toolsRuntimeOnly,
97
+ });
98
+ }
@@ -1,7 +1,8 @@
1
1
  import type { AgentManifest } from "../types/manifest.js";
2
2
  /**
3
3
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned
4
- * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed;
4
+ * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
5
+ * server's tools or require their approval (R2b C9, Q18);
5
6
  * code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
6
7
  */
7
8
  export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
@@ -27,15 +27,51 @@ function removeOnlySkills(pinned, candidate) {
27
27
  }
28
28
  return true;
29
29
  }
30
+ /**
31
+ * One tool setting, or the `"*"` entry, only tightened (R2b C9, Q18): `enabled` kept or set to
32
+ * `false`, `approval` kept or set to `always`, `deferred` kept. Each level of a tool's resolution
33
+ * (its entry, then `"*"`) either keeps its value or tightens it, so the tool does too.
34
+ */
35
+ function tightensSettings(prior, next) {
36
+ return ((next.enabled === prior?.enabled || next.enabled === false) &&
37
+ (next.approval === prior?.approval || next.approval === "always") &&
38
+ next.deferred === prior?.deferred);
39
+ }
40
+ /**
41
+ * The servers of a turn variant: the pinned ones, the same but for their `tools` maps, where a
42
+ * variant may only disable a tool or require its approval (R2b C9, Q18). An entry the pin has
43
+ * stays, since dropping one could widen.
44
+ */
45
+ function tightensServers(pinned, candidate) {
46
+ if (pinned === undefined || candidate === undefined)
47
+ return same(candidate, pinned);
48
+ const names = Object.keys(pinned);
49
+ if (!same(Object.keys(candidate).sort(), [...names].sort()))
50
+ return false;
51
+ return names.every((name) => {
52
+ const { tools: priorTools, ...prior } = pinned[name];
53
+ const { tools: nextTools, ...next } = candidate[name];
54
+ if (!same(next, prior))
55
+ return false;
56
+ if (nextTools === undefined)
57
+ return priorTools === undefined;
58
+ for (const key of Object.keys(priorTools ?? {}))
59
+ if (!Object.hasOwn(nextTools, key))
60
+ return false;
61
+ return Object.entries(nextTools).every(([key, settings]) => tightensSettings(Object.hasOwn(priorTools ?? {}, key) ? priorTools[key] : undefined, settings));
62
+ });
63
+ }
30
64
  /**
31
65
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned
32
- * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed;
66
+ * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
67
+ * server's tools or require their approval (R2b C9, Q18);
33
68
  * code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
34
69
  */
35
70
  export function isVariantOf(candidate, pinned) {
36
71
  if (candidate.id !== pinned.id)
37
72
  return false;
38
- if (candidate.manifestSchemaVersion !== pinned.manifestSchemaVersion)
73
+ // A variant of a v5 pin may be v6, to set an MCP server's tools; never older than its pin.
74
+ if (candidate.manifestSchemaVersion < pinned.manifestSchemaVersion)
39
75
  return false;
40
76
  if (!same(candidate.runtime ?? {}, pinned.runtime ?? {}))
41
77
  return false;
@@ -45,7 +81,7 @@ export function isVariantOf(candidate, pinned) {
45
81
  const next = candidateById.get(prior.id);
46
82
  // Setup — and any capability that declares it — must not change or be removed.
47
83
  if (prior.mcpServers !== undefined) {
48
- if (!next || !same(next.mcpServers, prior.mcpServers))
84
+ if (!next || !tightensServers(prior.mcpServers, next.mcpServers))
49
85
  return false;
50
86
  }
51
87
  if (prior.sandbox !== undefined) {
@@ -64,7 +100,7 @@ export function isVariantOf(candidate, pinned) {
64
100
  if (!removeOnlySkills(prior.skills, next.skills))
65
101
  return false;
66
102
  // Free: name, description, metadata, instructions (and model once it exists).
67
- if (!same(next.mcpServers, prior.mcpServers))
103
+ if (!tightensServers(prior.mcpServers, next.mcpServers))
68
104
  return false;
69
105
  if (!same(next.sandbox, prior.sandbox))
70
106
  return false;