@nylorun/core 0.22.0-beta → 0.23.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 (73) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +32 -16
  4. package/dist/compatibility.js +33 -17
  5. package/dist/contracts.d.ts +531 -88
  6. package/dist/contracts.js +297 -199
  7. package/dist/define.d.ts +8 -12
  8. package/dist/define.js +7 -11
  9. package/dist/definition/assemble.d.ts +1 -3
  10. package/dist/definition/assemble.js +4 -8
  11. package/dist/definition/bound.d.ts +1 -1
  12. package/dist/definition/delegate.d.ts +5 -0
  13. package/dist/definition/delegate.js +6 -1
  14. package/dist/definition/from.d.ts +4 -2
  15. package/dist/definition/from.js +11 -29
  16. package/dist/definition/http-tool.d.ts +5 -3
  17. package/dist/definition/http-tool.js +8 -5
  18. package/dist/definition/manifest.d.ts +7 -6
  19. package/dist/definition/manifest.js +7 -6
  20. package/dist/definition/mcp.d.ts +1 -1
  21. package/dist/definition/media-reference.d.ts +2 -11
  22. package/dist/definition/media-reference.js +0 -12
  23. package/dist/definition/model-failure.js +1 -0
  24. package/dist/definition/removed.js +1 -0
  25. package/dist/definition/trace.d.ts +0 -7
  26. package/dist/definition/trace.js +0 -34
  27. package/dist/definition/variant.d.ts +1 -1
  28. package/dist/definition/variant.js +1 -3
  29. package/dist/harness-api/artifacts.d.ts +84 -0
  30. package/dist/harness-api/artifacts.js +128 -0
  31. package/dist/harness-api/gates.d.ts +0 -4
  32. package/dist/harness-api/gates.js +0 -4
  33. package/dist/harness-api/harness-api.schema.json +2422 -924
  34. package/dist/harness-api/index.d.ts +9 -6
  35. package/dist/harness-api/index.js +9 -6
  36. package/dist/harness-api/json-schema.js +5 -2
  37. package/dist/harness-api/mcp.d.ts +77 -30
  38. package/dist/harness-api/mcp.js +42 -25
  39. package/dist/harness-api/messages.d.ts +45 -17
  40. package/dist/harness-api/messages.js +20 -5
  41. package/dist/harness-api/schema.d.ts +538 -198
  42. package/dist/harness-api/schema.js +298 -59
  43. package/dist/harness-api/transcript.d.ts +8 -10
  44. package/dist/harness-api/transcript.js +27 -11
  45. package/dist/harness-api/transport.d.ts +7 -1
  46. package/dist/harness-api/transport.js +10 -7
  47. package/dist/schemas/agent-manifest.schema.json +5 -146
  48. package/dist/schemas/environment-manifest.schema.json +56 -16
  49. package/dist/types/manifest.d.ts +3 -13
  50. package/dist/types/model.d.ts +10 -5
  51. package/dist/utils/definition-files.d.ts +20 -6
  52. package/dist/utils/definition-files.js +31 -17
  53. package/dist/utils/file-systems.d.ts +20 -0
  54. package/dist/utils/file-systems.js +20 -0
  55. package/dist/utils/harness-id.d.ts +4 -1
  56. package/dist/utils/harness-id.js +4 -1
  57. package/dist/utils/media-types.d.ts +30 -0
  58. package/dist/utils/media-types.js +128 -0
  59. package/dist/utils/runtime-limits.d.ts +229 -0
  60. package/dist/utils/runtime-limits.js +482 -0
  61. package/dist/utils/runtime-tools.d.ts +8 -16
  62. package/dist/utils/runtime-tools.js +8 -27
  63. package/dist/utils/sandbox.d.ts +4 -1
  64. package/dist/utils/sandbox.js +4 -1
  65. package/package.json +1 -1
  66. package/dist/definition/deferred-tools.d.ts +0 -27
  67. package/dist/definition/deferred-tools.js +0 -82
  68. package/dist/definition/runtime-manifest.d.ts +0 -30
  69. package/dist/definition/runtime-manifest.js +0 -132
  70. package/dist/definition/sandbox-tools.d.ts +0 -5
  71. package/dist/definition/sandbox-tools.js +0 -109
  72. package/dist/definition/skill-tools.d.ts +0 -23
  73. package/dist/definition/skill-tools.js +0 -76
@@ -0,0 +1,482 @@
1
+ /**
2
+ * Runtime limits (harness boundary S0, B15): the sizes, counts and deadlines the Runtime holds
3
+ * what crosses it to, one Tenant setting (`limits.config`, `GET`/`PUT /v1/tenant/limits`) with a
4
+ * default each. A harness learns the ones it must respect from `turn.start.limits`
5
+ * (`HarnessLimitsSchema`, a part of them).
6
+ *
7
+ * A limit is configuration; what the Runtime depends on is not. Each limit has a ceiling taken
8
+ * from a dependency (S2's largest record, the Harness API's largest WebSocket frame, the longest
9
+ * string the JavaScript engine makes, the longest timer it sets, the largest integer a JavaScript
10
+ * number holds exactly), and a setting above its ceiling is refused when it is put
11
+ * (`runtimeLimitIssues`).
12
+ */
13
+ import { z } from "zod";
14
+ import { HARNESS_MAX_PAYLOAD } from "../harness-api/transport.js";
15
+ /**
16
+ * S2's largest record: 1 MiB, metered as 8 bytes, plus its headers, plus its body. The stream
17
+ * relay writes each event's JSON as one record's body, with no headers.
18
+ */
19
+ export const S2_RECORD_MAX_BYTES = 1024 * 1024;
20
+ /**
21
+ * Room an event's envelope takes beside its payload: ids, cursor, time, writer and principal
22
+ * come to about 1 KiB; 64 KiB leaves them ample room under `S2_RECORD_MAX_BYTES`.
23
+ */
24
+ export const RECORD_ENVELOPE_RESERVE_BYTES = 64 * 1024;
25
+ /**
26
+ * The longest string V8 makes on 64-bit (`String::kMaxLength`, 2^29 - 24 code units): a JSON
27
+ * body the Runtime reads whole, or a file it sends a provider in base64, is one such string.
28
+ */
29
+ export const JS_STRING_MAX_LENGTH = 2 ** 29 - 24;
30
+ /**
31
+ * The longest delay a JavaScript timer takes (`setTimeout`, `setInterval`, `AbortSignal.timeout`):
32
+ * a signed 32-bit count of milliseconds, about 24.8 days. A longer one fires at once.
33
+ */
34
+ export const TIMER_MAX_MS = 2 ** 31 - 1;
35
+ /**
36
+ * The longest single argument Linux passes to a program (`MAX_ARG_STRLEN`, 32 pages of 4 KiB),
37
+ * its terminating NUL included: a setup command is one argument of `/bin/sh -c`.
38
+ */
39
+ export const LINUX_ARG_MAX_BYTES = 32 * 4096;
40
+ /** The longest setup command that fits it: UTF-8 takes at most 3 bytes for one UTF-16 code unit. */
41
+ const SETUP_COMMAND_MAX_CHARS = Math.floor((LINUX_ARG_MAX_BYTES - 1) / 3);
42
+ /** The most bytes base64 of `length` characters decodes to: groups of 4 characters, 3 bytes each. */
43
+ const base64Bytes = (length) => Math.floor(length / 4) * 3;
44
+ /** The fewest characters one item of a JSON list or map takes: its JSON and the comma after it. */
45
+ const minChars = (item) => JSON.stringify(item).length + 1;
46
+ /**
47
+ * The fewest characters one entry of a folder's manifest takes as JSON: an entry with a
48
+ * one-character path and type. A folder's manifest is read as one string, so it holds at most
49
+ * `JS_STRING_MAX_LENGTH` of them.
50
+ */
51
+ const FOLDER_ENTRY_MIN_CHARS = minChars({ path: "a", size: 0, sha256: "0".repeat(64), contentType: "a" });
52
+ /** The fewest characters one entry of a disk listing takes as JSON (`DiskOp` `list`). */
53
+ const DISK_ENTRY_MIN_CHARS = minChars({ path: "a", type: "dir", mode: 0 });
54
+ /** The most bytes JSON escapes one character of a quoted text to: a control character, `\u0000`. */
55
+ const JSON_ESCAPE_MAX_BYTES = 6;
56
+ /**
57
+ * The limits a harness must respect, sent in `turn.start.limits`:
58
+ *
59
+ * - `recordEntryBytes`: the most JSON one entry of the record may hold: an event's payload (a
60
+ * harness's claimed event, a transcript update, core's own), and an effect outcome a harness
61
+ * reports. Past it the write is refused with `limit_exceeded`. A transcript edit fills events up
62
+ * to it (`transcriptUpdates`).
63
+ * - `modelCallBytes`: the largest model call body the Model Gate reads.
64
+ * - `modelFileBytes`: the largest file (an image, a text file) the Model Gate sends a model.
65
+ * - `toolAnswerBytes`: the largest answer the Tool Gate keeps of an MCP or HTTP tool
66
+ * (`mcp.too-large`, `http.too-large` past it), and the largest tool call body it reads.
67
+ * - `harnessStateBytes`: the most state a custom harness may keep per session, as JSON.
68
+ * - `chunkBytes`: the most bytes one chunked Harness API answer carries (`definition.file` and
69
+ * `artifact.read` with a range, a disk read).
70
+ * - `folderEntries`: the most files one folder artifact a harness writes may hold
71
+ * (`artifact.write` with `kind: "folder"`, such as our engine's outputs folder).
72
+ */
73
+ const harnessLimits = {
74
+ recordEntryBytes: z.number().int().positive(),
75
+ modelCallBytes: z.number().int().positive(),
76
+ modelFileBytes: z.number().int().positive(),
77
+ toolAnswerBytes: z.number().int().positive(),
78
+ harnessStateBytes: z.number().int().positive(),
79
+ chunkBytes: z.number().int().positive(),
80
+ folderEntries: z.number().int().positive(),
81
+ };
82
+ /**
83
+ * The Runtime limits: the harness's (above), and the ones only the Runtime checks (B15), by area.
84
+ *
85
+ * Requests and uploads:
86
+ * - `requestBodyBytes`: the largest JSON body a Runtime or Management API route reads.
87
+ * - `messageParts`: the most parts one user message carries (text and files).
88
+ * - `pageItems`: the most items one page of a listing holds (`limit`), and `exportPageItems` one
89
+ * page of the model call export (`GET /v1/tenant/calls/model`). A page asked for with no
90
+ * `limit` holds the route's default, or this limit when it is lower; one asking more holds this
91
+ * many. `environmentEventItems`: the most events one read of an Environment's events returns.
92
+ * - `inlineFileBytes`: the largest file a message carries inline, decoded (AG-UI, A2A). Such an
93
+ * endpoint reads a body of one file at this size in base64 and `requestBodyBytes` more
94
+ * (`inlineBodyBytes`).
95
+ * - `a2aWaitMs`: how long a blocking A2A `SendMessage` waits for its task to end or ask for input.
96
+ * - `errorExcerptChars`: how much of a failed MCP server's or HTTP tool's answer an error quotes.
97
+ * - `traceContentBytes`: the most UTF-8 bytes of one content attribute of an exported span.
98
+ *
99
+ * Labels (an Environment's and an artifact's, checked whenever they are set):
100
+ * - `environmentLabels`, `artifactLabels`: the most labels one Environment, and one artifact,
101
+ * carries.
102
+ * - `labelKeyChars`, `labelValueChars`: the longest label key, and value.
103
+ *
104
+ * Environments (checked when one is made):
105
+ * - `environmentSetupCommands`, `environmentFiles`: the most setup commands, and input file
106
+ * entries, one manifest holds.
107
+ * - `environmentFilesPerEntry`: the most files one input file entry by hash names.
108
+ * - `environmentSecretSlots`: the most secret slots one manifest declares.
109
+ * - `setupCommandChars`: the longest setup command.
110
+ * - `setupCommandMs`: the longest `timeout` one setup command may ask for (a command's default is
111
+ * 10 minutes).
112
+ * - `setupOutputChars`: how much of a failed setup command's output its event keeps.
113
+ * - `setupReasonChars`, `setupCommandExcerptChars`: how much of the end of that output, and of
114
+ * the start of the command, a failed pod's reason quotes.
115
+ * - `manifestDescriptionChars`, `secretDescriptionChars`: the longest description of an
116
+ * environment manifest, and of one of its secret slots.
117
+ *
118
+ * Secrets (checked when one is written, and a manifest's slots when it is put):
119
+ * - `secretValueChars`: the longest value of an `environment_secret` or `environment_variable`.
120
+ * - `secretHosts`: the most hosts one `environment_secret` may be sent to (`allowedHosts`).
121
+ *
122
+ * Disk versions:
123
+ * - `diskVersionEntries`, `diskVersionBytes`: the most entries, and bytes of files, one version
124
+ * of an Environment's disk holds (an Environment's manifest may set less: `limits.disk`).
125
+ * - `diskLeaseMs`: how long a disk copy's lease lasts unrenewed; the copy renews it every quarter
126
+ * of it, and a copy whose process died is taken over once it lapses.
127
+ * - `diskPodWaitMs`: how long a disk copy waits for a pod's engine to connect.
128
+ *
129
+ * Model calls (the Model Gate's provider calls):
130
+ * - `modelRequestMs`: the longest one provider request may take.
131
+ * - `modelIdleMs`: how long a provider's stream may go without an event before the attempt is
132
+ * abandoned and tried again.
133
+ * - `modelAttempts`: the attempts one call makes, the first included.
134
+ * - `modelRetryDelayMs`: the delay before the second attempt; it doubles each time, with jitter.
135
+ * - `modelProviderRetries`, `modelRetryDelayMaxMs`: the retries the provider's SDK makes within
136
+ * one attempt, and the longest delay it waits before one.
137
+ *
138
+ * Tools:
139
+ * - `toolAttempts`: how many times an MCP or HTTP tool call is sent, across crashes and lost
140
+ * hops, before it fails to the model as `tool.interrupted`.
141
+ * - `httpToolTimeoutMs`: the longest `timeoutMs` an HTTP tool may ask for (a tool's default is
142
+ * 60 s), checked when an agent is deployed and when the tool is called.
143
+ * - `mcpSnapshotBytes`: the most JSON a session pins of what its MCP servers said at discovery
144
+ * (tools with their schemas, instructions), which every `turn.start.mcp` carries. A server that
145
+ * does not fit is left out, with a diagnostic.
146
+ * - `mcpPreviewMs`: how long an MCP preview may take, `initialize` and every `tools/list` page.
147
+ * - `mcpMetadataBytes`: the largest protected-resource metadata document a preview reads.
148
+ * - `toolRules`: the most rules the Tenant's tool policy holds; `toolRuleFieldChars` the longest
149
+ * selector (`tool`, `server`, `agent`) or `when` path of one, and `toolRuleTextChars` the
150
+ * longest `reason` or `matches` expression.
151
+ * - `modelBudgets`: the most model budgets the Tenant sets.
152
+ *
153
+ * Flows (`workflows.md` §13):
154
+ * - `flowConcurrency`: the most effects one flow turn runs at once; the rest wait their turn.
155
+ * - `flowMapItems`: the most items one map stage may fan out to (`map.too-many-items` past it).
156
+ * - `flowLoopIterations`: the most iterations one loop stage runs (`loop.too-many-iterations`).
157
+ */
158
+ export const RuntimeLimitsSchema = z
159
+ .object({
160
+ ...harnessLimits,
161
+ requestBodyBytes: z.number().int().positive(),
162
+ messageParts: z.number().int().positive(),
163
+ pageItems: z.number().int().positive(),
164
+ exportPageItems: z.number().int().positive(),
165
+ environmentEventItems: z.number().int().positive(),
166
+ inlineFileBytes: z.number().int().positive(),
167
+ a2aWaitMs: z.number().int().positive(),
168
+ errorExcerptChars: z.number().int().positive(),
169
+ traceContentBytes: z.number().int().positive(),
170
+ environmentLabels: z.number().int().positive(),
171
+ artifactLabels: z.number().int().positive(),
172
+ labelKeyChars: z.number().int().positive(),
173
+ labelValueChars: z.number().int().positive(),
174
+ environmentSetupCommands: z.number().int().positive(),
175
+ environmentFiles: z.number().int().positive(),
176
+ environmentFilesPerEntry: z.number().int().positive(),
177
+ environmentSecretSlots: z.number().int().positive(),
178
+ setupCommandChars: z.number().int().positive(),
179
+ setupCommandMs: z.number().int().positive(),
180
+ setupOutputChars: z.number().int().positive(),
181
+ setupReasonChars: z.number().int().positive(),
182
+ setupCommandExcerptChars: z.number().int().positive(),
183
+ manifestDescriptionChars: z.number().int().positive(),
184
+ secretDescriptionChars: z.number().int().positive(),
185
+ secretValueChars: z.number().int().positive(),
186
+ secretHosts: z.number().int().positive(),
187
+ diskVersionEntries: z.number().int().positive(),
188
+ diskVersionBytes: z.number().int().positive(),
189
+ diskLeaseMs: z.number().int().positive(),
190
+ diskPodWaitMs: z.number().int().positive(),
191
+ modelRequestMs: z.number().int().positive(),
192
+ modelIdleMs: z.number().int().positive(),
193
+ modelAttempts: z.number().int().positive(),
194
+ modelRetryDelayMs: z.number().int().positive(),
195
+ modelProviderRetries: z.number().int().nonnegative(),
196
+ modelRetryDelayMaxMs: z.number().int().positive(),
197
+ toolAttempts: z.number().int().positive(),
198
+ httpToolTimeoutMs: z.number().int().positive(),
199
+ mcpSnapshotBytes: z.number().int().positive(),
200
+ mcpPreviewMs: z.number().int().positive(),
201
+ mcpMetadataBytes: z.number().int().positive(),
202
+ toolRules: z.number().int().positive(),
203
+ toolRuleFieldChars: z.number().int().positive(),
204
+ toolRuleTextChars: z.number().int().positive(),
205
+ modelBudgets: z.number().int().positive(),
206
+ flowConcurrency: z.number().int().positive(),
207
+ flowMapItems: z.number().int().positive(),
208
+ flowLoopIterations: z.number().int().positive(),
209
+ })
210
+ .strict();
211
+ /**
212
+ * The Runtime limits a harness must respect (`turn.start.limits`). A limit the Runtime adds later
213
+ * that a harness does not know is dropped when it parses them.
214
+ */
215
+ export const HarnessLimitsSchema = z.object(harnessLimits);
216
+ const HARNESS_LIMIT_NAMES = Object.keys(harnessLimits);
217
+ /** The part of `limits` a harness is sent. */
218
+ export function harnessLimitsOf(limits) {
219
+ return Object.fromEntries(HARNESS_LIMIT_NAMES.map((name) => [name, limits[name]]));
220
+ }
221
+ const recordEntryCeiling = S2_RECORD_MAX_BYTES - RECORD_ENVELOPE_RESERVE_BYTES;
222
+ /** A time a JavaScript timer waits. */
223
+ const timer = (what) => ({
224
+ value: TIMER_MAX_MS,
225
+ unit: "milliseconds",
226
+ why: `${what} with a JavaScript timer, which waits at most ${TIMER_MAX_MS} ms`,
227
+ });
228
+ /** A number the Runtime counts or adds up, with no other bound. */
229
+ const counted = (unit, what) => ({
230
+ value: Number.MAX_SAFE_INTEGER,
231
+ unit,
232
+ why: `${what} in a JavaScript number, exact up to ${Number.MAX_SAFE_INTEGER}`,
233
+ });
234
+ /** A count of items one request carries, which is read as one string. */
235
+ const inRequest = (what, item) => {
236
+ const chars = minChars(item);
237
+ return {
238
+ value: Math.floor(JS_STRING_MAX_LENGTH / chars),
239
+ unit: "entries",
240
+ why: `${what} arrive in one request body, read as one string of at most ${JS_STRING_MAX_LENGTH} characters, and each takes at least ${chars}`,
241
+ };
242
+ };
243
+ /** A count of items one answer carries, which is written as one string. */
244
+ const inAnswer = (what, item) => {
245
+ const chars = minChars(item);
246
+ return {
247
+ value: Math.floor(JS_STRING_MAX_LENGTH / chars),
248
+ unit: "entries",
249
+ why: `${what} go in one response body, written as one string of at most ${JS_STRING_MAX_LENGTH} characters, and each takes at least ${chars}`,
250
+ };
251
+ };
252
+ /** A text one request carries. */
253
+ const inRequestText = (what) => ({
254
+ value: JS_STRING_MAX_LENGTH,
255
+ unit: "characters",
256
+ why: `${what} arrives in one request body, read as one string of at most ${JS_STRING_MAX_LENGTH} characters`,
257
+ });
258
+ /** A text quoted in one record entry, as JSON. */
259
+ const quoted = (what) => ({
260
+ value: Math.floor(recordEntryCeiling / JSON_ESCAPE_MAX_BYTES),
261
+ unit: "characters",
262
+ why: `${what} is kept in one record entry (at most ${recordEntryCeiling} bytes), where JSON may escape a character to ${JSON_ESCAPE_MAX_BYTES}`,
263
+ });
264
+ /**
265
+ * Each limit's ceiling, which no setting may pass, what it counts, and the dependency it comes
266
+ * from.
267
+ */
268
+ export const RUNTIME_LIMIT_CEILINGS = {
269
+ recordEntryBytes: {
270
+ value: recordEntryCeiling,
271
+ unit: "bytes",
272
+ why: `S2 takes records of at most ${S2_RECORD_MAX_BYTES} bytes, and an event's envelope needs ${RECORD_ENVELOPE_RESERVE_BYTES} beside its payload`,
273
+ },
274
+ modelCallBytes: {
275
+ value: JS_STRING_MAX_LENGTH,
276
+ unit: "bytes",
277
+ why: `the Model Gate reads a call's body as one string, of at most ${JS_STRING_MAX_LENGTH} characters`,
278
+ },
279
+ modelFileBytes: {
280
+ value: base64Bytes(JS_STRING_MAX_LENGTH),
281
+ unit: "bytes",
282
+ why: `a file goes to the provider as one base64 string, of at most ${JS_STRING_MAX_LENGTH} characters`,
283
+ },
284
+ toolAnswerBytes: {
285
+ value: HARNESS_MAX_PAYLOAD / 2,
286
+ unit: "bytes",
287
+ why: `a harness reports the answer to core in one Harness API frame (${HARNESS_MAX_PAYLOAD} bytes), as JSON, whose escapes may double it`,
288
+ },
289
+ harnessStateBytes: {
290
+ value: HARNESS_MAX_PAYLOAD / 2,
291
+ unit: "bytes",
292
+ why: `the state crosses in one Harness API frame (${HARNESS_MAX_PAYLOAD} bytes) with the rest of its output or turn.start`,
293
+ },
294
+ chunkBytes: {
295
+ value: base64Bytes(HARNESS_MAX_PAYLOAD) - RECORD_ENVELOPE_RESERVE_BYTES,
296
+ unit: "bytes",
297
+ why: `a chunk crosses in base64 in one Harness API frame (${HARNESS_MAX_PAYLOAD} bytes), with room for the frame's own JSON`,
298
+ },
299
+ folderEntries: {
300
+ value: Math.floor(JS_STRING_MAX_LENGTH / FOLDER_ENTRY_MIN_CHARS),
301
+ unit: "entries",
302
+ why: `a folder's manifest is read as one string, of at most ${JS_STRING_MAX_LENGTH} characters, and each entry takes at least ${FOLDER_ENTRY_MIN_CHARS}`,
303
+ },
304
+ requestBodyBytes: {
305
+ value: JS_STRING_MAX_LENGTH,
306
+ unit: "bytes",
307
+ why: `a body is read as one string, of at most ${JS_STRING_MAX_LENGTH} characters`,
308
+ },
309
+ messageParts: inRequest("parts", { type: "text", text: "a" }),
310
+ pageItems: inAnswer("a page's items", {}),
311
+ exportPageItems: inAnswer("a page's calls", {}),
312
+ environmentEventItems: inAnswer("the events", {}),
313
+ inlineFileBytes: {
314
+ value: base64Bytes(JS_STRING_MAX_LENGTH),
315
+ unit: "bytes",
316
+ why: `a file sent inline arrives in base64 in a body read as one string, of at most ${JS_STRING_MAX_LENGTH} characters`,
317
+ },
318
+ a2aWaitMs: timer("the wait is timed"),
319
+ errorExcerptChars: quoted("the excerpt"),
320
+ traceContentBytes: {
321
+ value: recordEntryCeiling,
322
+ unit: "bytes",
323
+ why: `span content is cut from one record entry, which holds at most ${recordEntryCeiling} bytes`,
324
+ },
325
+ environmentLabels: inRequest("labels", { a: "" }),
326
+ artifactLabels: inRequest("labels", { a: "" }),
327
+ labelKeyChars: inRequestText("a label key"),
328
+ labelValueChars: inRequestText("a label value"),
329
+ environmentSetupCommands: inRequest("setup commands", { command: "a" }),
330
+ environmentFiles: inRequest("input file entries", { path: "/workspace", files: {} }),
331
+ environmentFilesPerEntry: inRequest("the files of an entry", { a: `sha256:${"0".repeat(64)}` }),
332
+ environmentSecretSlots: inRequest("secret slots", { A: { type: "environment_variable" } }),
333
+ setupCommandChars: {
334
+ value: SETUP_COMMAND_MAX_CHARS,
335
+ unit: "characters",
336
+ why: `a command runs as one argument of /bin/sh -c, which Linux takes up to ${LINUX_ARG_MAX_BYTES} bytes long (MAX_ARG_STRLEN, with its NUL), and UTF-8 may take 3 bytes for a character`,
337
+ },
338
+ setupCommandMs: timer("the engine times a command"),
339
+ setupOutputChars: quoted("the output"),
340
+ setupReasonChars: quoted("the reason"),
341
+ setupCommandExcerptChars: quoted("the reason"),
342
+ manifestDescriptionChars: inRequestText("a description"),
343
+ secretDescriptionChars: inRequestText("a description"),
344
+ secretValueChars: inRequestText("a value"),
345
+ secretHosts: inRequest("hosts", "a.b"),
346
+ diskVersionEntries: {
347
+ value: Math.min(Math.floor(JS_STRING_MAX_LENGTH / FOLDER_ENTRY_MIN_CHARS), Math.floor(HARNESS_MAX_PAYLOAD / DISK_ENTRY_MIN_CHARS)),
348
+ unit: "entries",
349
+ why: `a disk is listed in one Harness API frame (${HARNESS_MAX_PAYLOAD} bytes, each entry at least ${DISK_ENTRY_MIN_CHARS}), and a version's manifest is read as one string of at most ${JS_STRING_MAX_LENGTH} characters`,
350
+ },
351
+ diskVersionBytes: counted("bytes", "the files' sizes are added up"),
352
+ diskLeaseMs: timer("the lease is renewed"),
353
+ diskPodWaitMs: counted("milliseconds", "the deadline is reckoned from the clock"),
354
+ modelRequestMs: timer("the provider's SDK times the request"),
355
+ modelIdleMs: timer("the stream's silence is timed"),
356
+ modelAttempts: counted("attempts", "attempts are counted"),
357
+ modelRetryDelayMs: timer("the delay is waited"),
358
+ modelProviderRetries: counted("retries", "retries are counted"),
359
+ modelRetryDelayMaxMs: timer("the delay is waited"),
360
+ toolAttempts: counted("attempts", "sends are counted"),
361
+ httpToolTimeoutMs: timer("the call is timed"),
362
+ mcpSnapshotBytes: {
363
+ value: HARNESS_MAX_PAYLOAD / 4,
364
+ unit: "bytes",
365
+ why: `the facts cross in turn.start, one Harness API frame (${HARNESS_MAX_PAYLOAD} bytes), beside the harness's state (at most half of it) and the rest`,
366
+ },
367
+ mcpPreviewMs: timer("the preview is timed"),
368
+ mcpMetadataBytes: {
369
+ value: JS_STRING_MAX_LENGTH,
370
+ unit: "bytes",
371
+ why: `the document is read as one string, of at most ${JS_STRING_MAX_LENGTH} characters`,
372
+ },
373
+ toolRules: inRequest("rules", { effect: "allow" }),
374
+ toolRuleFieldChars: inRequestText("a selector"),
375
+ toolRuleTextChars: inRequestText("a text"),
376
+ modelBudgets: inRequest("budgets", { scope: "tenant" }),
377
+ flowConcurrency: counted("effects", "running effects are counted"),
378
+ flowMapItems: counted("entries", "items are counted"),
379
+ flowLoopIterations: counted("iterations", "iterations are counted"),
380
+ };
381
+ /**
382
+ * The limits a Tenant that sets none runs with: today's sizes and times. `recordEntryBytes` is
383
+ * its ceiling, so every event S2 took before is still taken; what keeps a step's tool results
384
+ * well inside it is the harness's shaping of them (Nylorun's engine: 256 KiB a step,
385
+ * `shapeToolOutcome` in `@nylorun/harness`), since the record refuses an entry past it.
386
+ */
387
+ export const RUNTIME_LIMIT_DEFAULTS = Object.freeze({
388
+ recordEntryBytes: RUNTIME_LIMIT_CEILINGS.recordEntryBytes.value,
389
+ modelCallBytes: 32 * 1024 * 1024,
390
+ modelFileBytes: 8 * 1024 * 1024,
391
+ toolAnswerBytes: 8 * 1024 * 1024,
392
+ harnessStateBytes: 256 * 1024,
393
+ chunkBytes: 16 * 1024 * 1024,
394
+ folderEntries: 10_000,
395
+ requestBodyBytes: 1024 * 1024,
396
+ messageParts: 32,
397
+ pageItems: 200,
398
+ exportPageItems: 1_000,
399
+ environmentEventItems: 1_000,
400
+ inlineFileBytes: 20 * 1024 * 1024,
401
+ a2aWaitMs: 5 * 60_000,
402
+ errorExcerptChars: 2_000,
403
+ traceContentBytes: 8 * 1024,
404
+ environmentLabels: 32,
405
+ artifactLabels: 32,
406
+ labelKeyChars: 63,
407
+ labelValueChars: 256,
408
+ environmentSetupCommands: 16,
409
+ environmentFiles: 16,
410
+ environmentFilesPerEntry: 1_000,
411
+ environmentSecretSlots: 64,
412
+ setupCommandChars: 4_096,
413
+ setupCommandMs: 30 * 60_000,
414
+ setupOutputChars: 4 * 1024,
415
+ setupReasonChars: 500,
416
+ setupCommandExcerptChars: 80,
417
+ manifestDescriptionChars: 1_024,
418
+ secretDescriptionChars: 500,
419
+ secretValueChars: 8_192,
420
+ secretHosts: 32,
421
+ diskVersionEntries: 200_000,
422
+ diskVersionBytes: 10 * 1024 ** 3,
423
+ diskLeaseMs: 2 * 60_000,
424
+ diskPodWaitMs: 60_000,
425
+ modelRequestMs: 600_000,
426
+ modelIdleMs: 300_000,
427
+ modelAttempts: 3,
428
+ modelRetryDelayMs: 2_000,
429
+ modelProviderRetries: 2,
430
+ modelRetryDelayMaxMs: 60_000,
431
+ toolAttempts: 3,
432
+ httpToolTimeoutMs: 300_000,
433
+ mcpSnapshotBytes: 4 * 1024 * 1024,
434
+ mcpPreviewMs: 15_000,
435
+ mcpMetadataBytes: 64 * 1024,
436
+ toolRules: 200,
437
+ toolRuleFieldChars: 200,
438
+ toolRuleTextChars: 500,
439
+ modelBudgets: 100,
440
+ flowConcurrency: 8,
441
+ flowMapItems: 1_000,
442
+ flowLoopIterations: 100,
443
+ });
444
+ /** The Runtime limits a harness gets when the Tenant sets none. */
445
+ export const HARNESS_LIMIT_DEFAULTS = Object.freeze(harnessLimitsOf(RUNTIME_LIMIT_DEFAULTS));
446
+ /** The limits in force: `set`, with the default for each it leaves out. */
447
+ export function runtimeLimitsOf(set) {
448
+ const limits = { ...RUNTIME_LIMIT_DEFAULTS };
449
+ for (const name of Object.keys(limits)) {
450
+ const value = set?.[name];
451
+ if (value !== undefined)
452
+ limits[name] = value;
453
+ }
454
+ return limits;
455
+ }
456
+ /** Why `set` cannot be put: each limit above its ceiling, naming the ceiling and its dependency. */
457
+ export function runtimeLimitIssues(set) {
458
+ const issues = [];
459
+ for (const name of Object.keys(RUNTIME_LIMIT_CEILINGS)) {
460
+ const asked = set?.[name];
461
+ const ceiling = RUNTIME_LIMIT_CEILINGS[name];
462
+ if (asked !== undefined && asked > ceiling.value)
463
+ issues.push(`limits.${name} asks for ${asked} ${ceiling.unit}; its ceiling is ${ceiling.value}: ${ceiling.why}.`);
464
+ }
465
+ return issues;
466
+ }
467
+ /**
468
+ * The message of a write refused for passing limit `name`: what was sent, the limit, and where an
469
+ * operator sets it.
470
+ */
471
+ export function limitExceededMessage(what, amount, name, limit) {
472
+ const unit = RUNTIME_LIMIT_CEILINGS[name].unit;
473
+ return `${what} is ${amount} ${unit}, over the Runtime limit ${name} (${limit} ${unit}; PUT /v1/tenant/limits).`;
474
+ }
475
+ /**
476
+ * The body an endpoint that takes files inline reads (AG-UI, A2A): one file at `inlineFileBytes`
477
+ * in base64 (a third larger), and `requestBodyBytes` for the rest of the request; never more
478
+ * than one string holds.
479
+ */
480
+ export function inlineBodyBytes(limits) {
481
+ return Math.min(JS_STRING_MAX_LENGTH, Math.ceil(limits.inlineFileBytes / 3) * 4 + limits.requestBodyBytes);
482
+ }
@@ -1,19 +1,11 @@
1
- /** Stores a sandbox file, or inline text, as a file artifact of the session (F8.1). */
1
+ /**
2
+ * Our engine's tool that stores a sandbox file, or inline text, as a file artifact of the session
3
+ * (F8.1). Since protocol 15 it runs in our harness (`@nylorun/harness`), not the Runtime.
4
+ */
2
5
  export declare const SAVE_ARTIFACT_TOOL = "save_artifact";
3
- /** Reads an artifact of the session in pages (R2b C11). */
4
- export declare const READ_ARTIFACT_TOOL = "read_artifact";
5
- /** Loads a skill's `SKILL.md`. */
6
- export declare const LOAD_SKILL_TOOL = "load_skill";
7
- /** Reads one resource file of a skill. */
8
- export declare const READ_SKILL_RESOURCE_TOOL = "read_skill_resource";
9
- /** Finds deferred tools by a query (BM25 over their names and descriptions). */
10
- export declare const TOOL_SEARCH_TOOL = "tool_search";
11
- /** Runs a deferred tool by name, as a call of that tool. */
12
- export declare const TOOL_CALL_TOOL = "tool_call";
13
6
  /**
14
- * The tools the Runtime serves: the sandbox tools, the artifact tools, the skill tools and the
15
- * deferred-tool pair. An agent's own tool may not take one of these names, so a tool's name alone
16
- * says whose it is.
7
+ * Our engine's tool that reads an artifact of the session in pages (R2b C11). Since protocol 15 it
8
+ * runs in our harness, which also names it in a spilled tool result's stub and in a file's
9
+ * reference line.
17
10
  */
18
- export declare const RUNTIME_TOOL_NAMES: ReadonlySet<string>;
19
- export declare function isRuntimeToolName(name: string): boolean;
11
+ export declare const READ_ARTIFACT_TOOL = "read_artifact";
@@ -1,30 +1,11 @@
1
- import { SANDBOX_TOOL_NAMES } from "./sandbox.js";
2
- /** Stores a sandbox file, or inline text, as a file artifact of the session (F8.1). */
1
+ /**
2
+ * Our engine's tool that stores a sandbox file, or inline text, as a file artifact of the session
3
+ * (F8.1). Since protocol 15 it runs in our harness (`@nylorun/harness`), not the Runtime.
4
+ */
3
5
  export const SAVE_ARTIFACT_TOOL = "save_artifact";
4
- /** Reads an artifact of the session in pages (R2b C11). */
5
- export const READ_ARTIFACT_TOOL = "read_artifact";
6
- /** Loads a skill's `SKILL.md`. */
7
- export const LOAD_SKILL_TOOL = "load_skill";
8
- /** Reads one resource file of a skill. */
9
- export const READ_SKILL_RESOURCE_TOOL = "read_skill_resource";
10
- /** Finds deferred tools by a query (BM25 over their names and descriptions). */
11
- export const TOOL_SEARCH_TOOL = "tool_search";
12
- /** Runs a deferred tool by name, as a call of that tool. */
13
- export const TOOL_CALL_TOOL = "tool_call";
14
6
  /**
15
- * The tools the Runtime serves: the sandbox tools, the artifact tools, the skill tools and the
16
- * deferred-tool pair. An agent's own tool may not take one of these names, so a tool's name alone
17
- * says whose it is.
7
+ * Our engine's tool that reads an artifact of the session in pages (R2b C11). Since protocol 15 it
8
+ * runs in our harness, which also names it in a spilled tool result's stub and in a file's
9
+ * reference line.
18
10
  */
19
- export const RUNTIME_TOOL_NAMES = new Set([
20
- ...SANDBOX_TOOL_NAMES,
21
- SAVE_ARTIFACT_TOOL,
22
- READ_ARTIFACT_TOOL,
23
- LOAD_SKILL_TOOL,
24
- READ_SKILL_RESOURCE_TOOL,
25
- TOOL_SEARCH_TOOL,
26
- TOOL_CALL_TOOL,
27
- ]);
28
- export function isRuntimeToolName(name) {
29
- return RUNTIME_TOOL_NAMES.has(name);
30
- }
11
+ export const READ_ARTIFACT_TOOL = "read_artifact";
@@ -1,5 +1,8 @@
1
1
  /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
- /** The sandbox tools the Runtime adds to a session with a sandbox, and runs. */
2
+ /**
3
+ * The sandbox operations a harness runs in a session's sandbox: a `sandbox` call names one as its
4
+ * tool (protocol 15). Our engine offers a tool of each name.
5
+ */
3
6
  export declare const SANDBOX_TOOL_NAMES: readonly ["bash", "read", "write", "edit", "grep", "glob"];
4
7
  export type SandboxToolName = (typeof SANDBOX_TOOL_NAMES)[number];
5
8
  export declare const SANDBOX_WORKSPACE = "/workspace";
@@ -1,5 +1,8 @@
1
1
  /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
- /** The sandbox tools the Runtime adds to a session with a sandbox, and runs. */
2
+ /**
3
+ * The sandbox operations a harness runs in a session's sandbox: a `sandbox` call names one as its
4
+ * tool (protocol 15). Our engine offers a tool of each name.
5
+ */
3
6
  export const SANDBOX_TOOL_NAMES = Object.freeze([
4
7
  "bash",
5
8
  "read",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.22.0-beta",
3
+ "version": "0.23.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",
@@ -1,27 +0,0 @@
1
- import type { ToolManifest } from "../types/manifest.js";
2
- import { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL } from "../utils/runtime-tools.js";
3
- export { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL };
4
- /** How many tools `tool_search` returns when the model sets no `limit`. */
5
- export declare const TOOL_SEARCH_DEFAULT_LIMIT = 8;
6
- /** The most tools one `tool_search` returns. */
7
- export declare const TOOL_SEARCH_MAX_LIMIT = 20;
8
- /** How much of a server's own instructions the model sees in the deferred tools' note. */
9
- export declare const SERVER_INSTRUCTIONS_MAX_CHARS = 2000;
10
- /** A server some of whose tools are deferred, as the model's note names it. */
11
- export interface DeferredServerNote {
12
- readonly serverName: string;
13
- /** How many of its tools are deferred. */
14
- readonly tools: number;
15
- /** The server's own instructions (MCP `initialize`), if it gave any. */
16
- readonly instructions?: string;
17
- }
18
- /**
19
- * `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
20
- * schemas reach the model; change them deliberately.
21
- */
22
- export declare function deferredToolsTools(): readonly ToolManifest[];
23
- /**
24
- * The note the model reads beside `tool_search`: each server with deferred tools, how many, and
25
- * its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
26
- */
27
- export declare function deferredToolsInstructions(servers: readonly DeferredServerNote[]): string;