@nylorun/harness 0.23.1-beta → 0.24.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - 18f9a2f: **Model-safe MCP tool names, coded MCP tool errors and credential scrubbing** (R2b C6, C7, C8). MIGRATION.md (protocol 10, "Tool and MCP server names" and "Tool errors the model sees") has the details.
8
+
9
+ - `@nylorun/core`: a declared tool's name and an MCP server's name must match `^[A-Za-z0-9_-]{1,64}$` (`AgentManifestSchema`, so `PUT /v1/agents/{id}` refuses others). `mcp.discovered`'s server outcomes gain `renamed: [{ serverToolName, name }]`; `tool.completed` gains `redacted` and its `error` gains `retryable`. A failed `ToolOutcome` and `ToolResult` may carry `retryable`.
10
+ - `@nylorun/harness`: a failed tool result keeps the outcome's `retryable`, and the model sees it beside `code` and `message`.
11
+ - `@nylorun/runtime`: the model knows an MCP tool by `server__tool` with characters outside `[A-Za-z0-9_-]` replaced by `_`, shortened to 64 with an 8-hex SHA-256 suffix (also given to a renamed tool that collides); the server is still called by its own name. A failed MCP tool call is a failed tool result the model sees, with code `mcp.unreachable` (never sent; retryable), `credential_rejected` (`401`), `mcp.forbidden` (`403`), `mcp.error` (a JSON-RPC error) or `mcp.status` (another HTTP status); a call whose answer was lost after it was sent is `mcp.lost` for a `readOnlyHint` or `idempotentHint` tool and stays `uncertain` otherwise, as does a call lost with a gateway restart. A pooled connection whose server ended its session (`404` to its `Mcp-Session-Id`) or whose credential's `via` moved is dropped, opened again, and the call sent once more, since the tool never saw it. The credential values sent on a call (at least 8 characters, and a `Bearer` value's token) are replaced with `[redacted]` in MCP and HTTP tool results and errors before the gate records or returns them; no other field is touched.
12
+
13
+ - 90a817d: **MCP and HTTP tool results that fit** (R2b C11). MIGRATION.md (protocol 10, "Tool results that fit") has the details.
14
+
15
+ - `@nylorun/core`: a completed `ToolOutcome` may carry `files` (`ToolResultFile`: a media type and the host's reference) and `truncated`; a completed `ToolResult` carries the `files`. `artifactsCapabilityManifest({ save, read })` adds the built-in `read_artifact` (`READ_ARTIFACT_TOOL`, `READ_ARTIFACT_MAX_BYTES`), and `codeToolsOf` leaves it alone. `SessionView` gains `definitionHash`, the definition the session was opened from. Transcript edits are split at 48 KiB, down from 256 KiB, so each `transcript.updated` event stays under 64 KiB when no entry is larger.
16
+ - `@nylorun/harness`: a tool result's files go to the model after its output, as media parts; an outcome marked `truncated` is not checked against the tool's output schema.
17
+ - `@nylorun/runtime`: an agent's remote MCP or HTTP tool result past 32 KiB is stored as a file artifact of the session, and the model gets `{ truncated: true, artifactId, size, preview }` (the first 4 KiB and the last 1 KiB). Image, audio and blob resource parts become artifacts too, an image also shown to a model that reads images (a note for one that does not); each part of a mixed result is shaped alone, and a `resource_link` stays a link. One step's results share a 256 KiB budget, so many parallel results never make an event near S2's 1 MiB record: past it, a result is a stub naming its artifact. When an artifact cannot be stored, the preview stays and `dropped` says why. An MCP answer past 8 MiB is `mcp.too-large`. `read_artifact { artifactId, offset?, length? }` reads 32 KiB of the session's own artifact a call, with or without a sandbox: a session gets it for each agent with an MCP server or an HTTP tool. The session view names its `definitionHash`.
18
+ - `@nylorun/studio`: a session is shown as running an older manifest only when the definition it was opened from is not the registered one, not because the Runtime pinned its own tools (a sandbox's, `save_artifact`, `read_artifact`) beside it.
19
+
20
+ - b8d10cb: **Per-tool MCP settings (manifest v6) and deferred tools** (R2b C9, C10). MIGRATION.md (protocol 10, "Per-tool settings and manifest v6" and "Deferred tools") has the details.
21
+
22
+ - `@nylorun/core`: an MCP server takes `tools` (`McpToolSettings` by the server's own tool name, `"*"` for the rest: `enabled`, `approval`, `deferred`) and `deferred`, in manifest v6. `mcp()` and `Agent.mcp()` accept them, and the builder writes v6 only for a manifest that uses them, so other manifests keep their hashes; `AgentManifestSchema` accepts v5 unchanged and refuses the fields in v5. `mcpToolSettings` resolves a tool's settings, `manifestVersionFor` says which version a definition needs. `isVariantOf` lets a turn variant disable an MCP tool or require its approval, and nothing else. `TOOLS_CAPABILITY_ID`, `TOOL_SEARCH_TOOL`, `TOOL_CALL_TOOL`, `deferredToolsTools` and `deferredToolsInstructions` describe `tool_search` and `tool_call`. A session tool may carry instructions, read with its capability's. `mcp.discovered` gains `deferred`, `disabled` and `unknownTools` per server.
23
+ - `@nylorun/harness`: a session tool marked `deferred` stays out of the model's tool list; `tool_call` runs it as its own call, after checking the arguments against its `inputSchema`, and asks for approval when it needs it.
24
+ - `@nylorun/runtime`: discovery leaves out the tools a server's settings disable and names keys that match no tool. A session of an agent with a remote MCP server pins an empty `nylorun.tools` capability; when the agent's MCP tools pass a tenth of the model's context window (or settings say so), they are deferred for the session's life, and the model gets `tool_search` (BM25 over the deferred tools' names and descriptions, served by core) and `tool_call`, with a note naming each server and its instructions. Approval resolves per tool, and a turn variant's tightening applies to its turn. The gate's `mcp/connect` answers the server's instructions.
25
+
26
+ ### Patch Changes
27
+
28
+ - Pin core to the tested release.
29
+ - Updated dependencies [50e2f7e]
30
+ - Updated dependencies [e0e39ff]
31
+ - Updated dependencies [fed5e58]
32
+ - Updated dependencies [18f9a2f]
33
+ - Updated dependencies [da93711]
34
+ - Updated dependencies [90a817d]
35
+ - Updated dependencies [b8d10cb]
36
+ - @nylorun/core@0.17.0-beta
37
+
3
38
  ## 0.23.1-beta
4
39
 
5
40
  ### Patch Changes
@@ -114,7 +114,17 @@ function projectToolResult(result) {
114
114
  toolCallId: result.callId,
115
115
  toolName: result.toolName,
116
116
  status: result.kind,
117
- content: [textPart(JSON.stringify(toolResultPayload(result)))],
117
+ content: [
118
+ textPart(JSON.stringify(toolResultPayload(result))),
119
+ // Images the tool returned, stored by the host (R2b C11): the model call resolves them.
120
+ ...(result.kind === "completed" && result.files
121
+ ? result.files.map((file) => Object.freeze({
122
+ type: "media",
123
+ mediaType: file.mediaType,
124
+ reference: copyJson(file.reference),
125
+ }))
126
+ : []),
127
+ ],
118
128
  });
119
129
  }
120
130
  function toolResultPayload(result) {
@@ -126,6 +136,7 @@ function toolResultPayload(result) {
126
136
  kind: result.kind,
127
137
  code: result.code,
128
138
  message: result.message,
139
+ ...(result.retryable === undefined ? {} : { retryable: result.retryable }),
129
140
  ...(result.details === undefined ? {} : { details: result.details }),
130
141
  };
131
142
  }
@@ -25,7 +25,14 @@ const interaction = z
25
25
  const outcome = z.discriminatedUnion("kind", [
26
26
  z.object({ kind: z.literal("completed"), output: json }).strict(),
27
27
  z.object({ kind: z.literal("denied"), reason: z.string() }).strict(),
28
- z.object({ kind: z.literal("failed"), code: id, message: z.string() }).strict(),
28
+ z
29
+ .object({
30
+ kind: z.literal("failed"),
31
+ code: id,
32
+ message: z.string(),
33
+ retryable: z.boolean().optional(),
34
+ })
35
+ .strict(),
29
36
  ]);
30
37
  const reference = z
31
38
  .object({
@@ -3,7 +3,8 @@ import { copyJson } from "@nylorun/core/define";
3
3
  export function toolResult(call, definition, outcome) {
4
4
  const identity = { callId: call.callId, toolName: call.toolName };
5
5
  if (outcome.kind === "completed") {
6
- const checked = definition.outputSchema?.validate(outcome.output);
6
+ // A preview the Runtime made of a result too large to show is not the tool's output (R2b C11).
7
+ const checked = outcome.truncated === true ? undefined : definition.outputSchema?.validate(outcome.output);
7
8
  if (checked && !checked.ok)
8
9
  return {
9
10
  ...identity,
@@ -16,15 +17,28 @@ export function toolResult(call, definition, outcome) {
16
17
  ...identity,
17
18
  kind: "completed",
18
19
  output: checked?.ok ? checked.value : outcome.output,
20
+ ...(outcome.files?.length ? { files: outcome.files.map(fileOf) } : {}),
19
21
  });
20
22
  }
21
23
  if (outcome.kind === "failed" &&
22
24
  typeof outcome.code === "string" &&
23
25
  typeof outcome.message === "string")
24
- return copyJson({ ...identity, kind: "failed", code: outcome.code, message: outcome.message });
26
+ return copyJson({
27
+ ...identity,
28
+ kind: "failed",
29
+ code: outcome.code,
30
+ message: outcome.message,
31
+ ...(typeof outcome.retryable === "boolean" ? { retryable: outcome.retryable } : {}),
32
+ });
25
33
  if (outcome.kind === "denied" && typeof outcome.reason !== "string")
26
34
  throw new HarnessError("tool.invalid-tool-result", "Tool denial reason must be a string");
27
35
  if (outcome.kind === "denied" && typeof outcome.reason === "string")
28
36
  return copyJson({ ...identity, kind: "denied", reason: outcome.reason });
29
37
  throw new HarnessError("tool.invalid-tool-result", "Expected a completed, failed, or denied tool result");
30
38
  }
39
+ /** A file the model sees beside a tool's output (R2b C11): a media type and the host's reference. */
40
+ function fileOf(file) {
41
+ if (typeof file?.mediaType !== "string" || file.mediaType === "" || file.reference === undefined)
42
+ throw new HarnessError("tool.invalid-tool-result", "A tool result file needs a mediaType and a reference");
43
+ return { mediaType: file.mediaType, reference: file.reference };
44
+ }
@@ -180,23 +180,31 @@ function toolResult(value, index) {
180
180
  const base = { callId: result.callId, toolName: result.toolName };
181
181
  switch (result.kind) {
182
182
  case "completed":
183
- exactKeys(result, ["callId", "toolName", "kind", "output"], `Tool result ${index}`);
183
+ exactKeys(result, ["callId", "toolName", "kind", "output", "files"], `Tool result ${index}`);
184
184
  assertJson(result.output, `tool result ${index} output`);
185
- return Object.freeze({ ...base, kind: "completed", output: copyJson(result.output) });
185
+ return Object.freeze({
186
+ ...base,
187
+ kind: "completed",
188
+ output: copyJson(result.output),
189
+ ...(result.files === undefined ? {} : { files: resultFiles(result.files, index) }),
190
+ });
186
191
  case "denied":
187
192
  exactKeys(result, ["callId", "toolName", "kind", "reason"], `Tool result ${index}`);
188
193
  if (typeof result.reason !== "string")
189
194
  fail(`Tool result ${index} reason must be a string`);
190
195
  return Object.freeze({ ...base, kind: "denied", reason: result.reason });
191
196
  case "failed":
192
- exactKeys(result, ["callId", "toolName", "kind", "code", "message", "details"], `Tool result ${index}`);
197
+ exactKeys(result, ["callId", "toolName", "kind", "code", "message", "details", "retryable"], `Tool result ${index}`);
193
198
  if (typeof result.code !== "string" || typeof result.message !== "string")
194
199
  fail(`Tool result ${index} code and message must be strings`);
200
+ if (result.retryable !== undefined && typeof result.retryable !== "boolean")
201
+ fail(`Tool result ${index} retryable must be a boolean`);
195
202
  return Object.freeze({
196
203
  ...base,
197
204
  kind: "failed",
198
205
  code: result.code,
199
206
  message: result.message,
207
+ ...(result.retryable === undefined ? {} : { retryable: result.retryable }),
200
208
  ...(result.details === undefined
201
209
  ? {}
202
210
  : { details: validationDetails(result.details, index) }),
@@ -205,6 +213,21 @@ function toolResult(value, index) {
205
213
  fail(`Tool result ${index} has unknown kind '${String(result.kind)}'`);
206
214
  }
207
215
  }
216
+ /** A completed result's files (R2b C11): a media type and the host's reference each. */
217
+ function resultFiles(value, index) {
218
+ if (!Array.isArray(value))
219
+ fail(`Tool result ${index} files must be an array`);
220
+ return Object.freeze(value.map((file, fileIndex) => {
221
+ if (!file || typeof file !== "object" || Array.isArray(file))
222
+ fail(`Tool result ${index} file ${fileIndex} must be an object`);
223
+ const item = file;
224
+ exactKeys(item, ["mediaType", "reference"], `Tool result ${index} file ${fileIndex}`);
225
+ if (typeof item.mediaType !== "string" || item.mediaType === "")
226
+ fail(`Tool result ${index} file ${fileIndex} must contain mediaType`);
227
+ assertJson(item.reference, `tool result ${index} file ${fileIndex} reference`);
228
+ return Object.freeze({ mediaType: item.mediaType, reference: copyJson(item.reference) });
229
+ }));
230
+ }
208
231
  function validationDetails(value, index) {
209
232
  if (!value || typeof value !== "object" || Array.isArray(value))
210
233
  fail(`Tool result ${index} details must be an object`);
@@ -72,8 +72,15 @@ export interface DurableSessionTool {
72
72
  readonly description?: string;
73
73
  readonly inputSchema: JsonObject;
74
74
  readonly outputSchema?: JsonObject;
75
- /** `always`: each call waits for approval (a remote MCP server's `approval`). */
75
+ /** `always`: each call waits for approval (a remote MCP server's, or its tool's, `approval`). */
76
76
  readonly approval?: ApprovalMode;
77
+ /**
78
+ * Not in the model's tool list (R2b C10): the model finds it with `tool_search` and runs it
79
+ * with `tool_call`, which makes the call as this tool's own.
80
+ */
81
+ readonly deferred?: boolean;
82
+ /** Text the model reads with the capability's instructions while this tool is advertised. */
83
+ readonly instructions?: readonly string[];
77
84
  }
78
85
  export declare function createDurableCheckpoint(input: {
79
86
  manifest: AgentManifest;
@@ -1,6 +1,6 @@
1
1
  import { HarnessError } from "@nylorun/core/define";
2
2
  import { AgentManifestSchema } from "@nylorun/core/contracts";
3
- import { agentFrom, withHttpTarget } from "@nylorun/core/define";
3
+ import { TOOL_CALL_TOOL, TOOLS_CAPABILITY_ID, agentFrom, withHttpTarget, } from "@nylorun/core/define";
4
4
  import { definitionFor } from "../definition/agent-definition.js";
5
5
  import { schemaFromJSON } from "@nylorun/core/define";
6
6
  import { hashManifest } from "@nylorun/core/define";
@@ -126,7 +126,10 @@ export async function runDurable(options) {
126
126
  /** Rebuild one agent from its manifest with every tool routed through host effects. */
127
127
  const hostedDefinition = (agent, ref) => {
128
128
  const hostedTool = hostedTools(ref);
129
- const owned = sessionTools.filter((tool) => (tool.agentId ?? manifest.id) === agent.id);
129
+ const mine = sessionTools.filter((tool) => (tool.agentId ?? manifest.id) === agent.id);
130
+ // Deferred tools stay out of the model's list; `tool_call` runs them (R2b C10).
131
+ const owned = mine.filter((tool) => !tool.deferred);
132
+ const deferred = new Map(mine.filter((tool) => tool.deferred).map((tool) => [tool.name, tool]));
130
133
  const implementations = {};
131
134
  for (const capability of agent.capabilities) {
132
135
  const tools = {};
@@ -142,7 +145,10 @@ export async function runDurable(options) {
142
145
  tools[tool.name] = hostedTool(capability.id, tool);
143
146
  for (const tool of owned)
144
147
  if (tool.capabilityId === capability.id)
145
- tools[tool.name] = hostedTool(capability.id, tool);
148
+ tools[tool.name] =
149
+ capability.id === TOOLS_CAPABILITY_ID && tool.name === TOOL_CALL_TOOL
150
+ ? deferredToolCall(tool, deferred, hostedTool)
151
+ : hostedTool(capability.id, tool);
146
152
  implementations[capability.id] = { tools };
147
153
  }
148
154
  return definitionFor(agentFrom(agent, implementations, owned.length === 0
@@ -151,6 +157,7 @@ export async function runDurable(options) {
151
157
  sessionTools: owned.map((tool) => ({
152
158
  capabilityId: tool.capabilityId,
153
159
  name: tool.name,
160
+ ...(tool.instructions?.length ? { instructions: tool.instructions } : {}),
154
161
  })),
155
162
  }));
156
163
  };
@@ -208,3 +215,56 @@ export async function runDurable(options) {
208
215
  function scoped(ref, identity) {
209
216
  return ref ? `${ref.delegationId}/${identity}` : identity;
210
217
  }
218
+ /**
219
+ * `tool_call` (R2b C10): runs a deferred tool by name, as that tool's own call. It checks the
220
+ * arguments against the tool's `inputSchema` first, so a mistake comes back to the model as a
221
+ * failed result it can fix. The effect then names the tool, so the host routes it, shapes its
222
+ * result and records `tool.completed` as for a direct call; a tool with approval waits for it
223
+ * here, with the prompt a direct call would have.
224
+ */
225
+ function deferredToolCall(tool, deferred, hostedTool) {
226
+ const hosted = new Map();
227
+ const targetOf = (args) => {
228
+ const name = args?.name;
229
+ return typeof name === "string" ? deferred.get(name) : undefined;
230
+ };
231
+ const gated = [...deferred.values()].some((item) => item.approval === "always");
232
+ return {
233
+ name: tool.name,
234
+ ...(tool.description === undefined ? {} : { description: tool.description }),
235
+ inputSchema: schemaFromJSON(tool.inputSchema),
236
+ ...(gated
237
+ ? {
238
+ approval: (args) => {
239
+ const target = targetOf(args);
240
+ return target?.approval === "always" ? `Approve ${target.name}?` : undefined;
241
+ },
242
+ }
243
+ : {}),
244
+ async execute(args, ctx) {
245
+ const call = args;
246
+ const target = targetOf(call);
247
+ if (!target)
248
+ return {
249
+ kind: "failed",
250
+ code: "tool.unknown",
251
+ message: `No deferred tool is named '${call.name}'. Find one with tool_search, and pass its name as it returned it.`,
252
+ };
253
+ const checked = schemaFromJSON(target.inputSchema).validate(call.arguments ?? {});
254
+ if (!checked.ok)
255
+ return {
256
+ kind: "failed",
257
+ code: "tool.invalid-arguments",
258
+ message: `The arguments do not match the inputSchema of '${target.name}': ${checked.issues
259
+ .map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
260
+ .join("; ")}`,
261
+ };
262
+ let run = hosted.get(target.name);
263
+ if (!run) {
264
+ run = hostedTool(target.capabilityId, target);
265
+ hosted.set(target.name, run);
266
+ }
267
+ return run.execute(checked.value, ctx);
268
+ },
269
+ };
270
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/harness",
3
- "version": "0.23.1-beta",
3
+ "version": "0.24.0-beta",
4
4
  "description": "Nylorun's TypeScript agent execution engine. See github.com/nylorun/agents.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -81,7 +81,7 @@
81
81
  "zod": "^4.6.5"
82
82
  },
83
83
  "dependencies": {
84
- "@nylorun/core": "0.16.0-beta"
84
+ "@nylorun/core": "0.17.0-beta"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "zod": "^4.6.5"