@nylorun/core 0.22.0-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.
Files changed (82) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +120 -47
  4. package/dist/compatibility.js +122 -49
  5. package/dist/contracts.d.ts +2824 -907
  6. package/dist/contracts.js +1286 -585
  7. package/dist/define.d.ts +9 -12
  8. package/dist/define.js +8 -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.d.ts +7 -0
  25. package/dist/definition/removed.js +21 -0
  26. package/dist/definition/sections.d.ts +63 -0
  27. package/dist/definition/sections.js +204 -0
  28. package/dist/definition/trace.d.ts +0 -7
  29. package/dist/definition/trace.js +0 -34
  30. package/dist/definition/variant.d.ts +1 -1
  31. package/dist/definition/variant.js +1 -3
  32. package/dist/harness-api/artifacts.d.ts +84 -0
  33. package/dist/harness-api/artifacts.js +128 -0
  34. package/dist/harness-api/gates.d.ts +0 -4
  35. package/dist/harness-api/gates.js +0 -4
  36. package/dist/harness-api/harness-api.schema.json +2798 -1124
  37. package/dist/harness-api/index.d.ts +9 -6
  38. package/dist/harness-api/index.js +9 -6
  39. package/dist/harness-api/json-schema.js +5 -2
  40. package/dist/harness-api/mcp.d.ts +77 -30
  41. package/dist/harness-api/mcp.js +42 -25
  42. package/dist/harness-api/messages.d.ts +47 -17
  43. package/dist/harness-api/messages.js +20 -5
  44. package/dist/harness-api/schema.d.ts +609 -200
  45. package/dist/harness-api/schema.js +345 -62
  46. package/dist/harness-api/transcript.d.ts +8 -10
  47. package/dist/harness-api/transcript.js +27 -11
  48. package/dist/harness-api/transport.d.ts +7 -1
  49. package/dist/harness-api/transport.js +10 -7
  50. package/dist/manifest-schemas.d.ts +9 -5
  51. package/dist/manifest-schemas.js +23 -27
  52. package/dist/schemas/agent-manifest.schema.json +1508 -365
  53. package/dist/schemas/harness-manifest.schema.json +1273 -0
  54. package/dist/schemas/{environment-manifest.schema.json → runtime-manifest.schema.json} +165 -84
  55. package/dist/types/manifest.d.ts +72 -14
  56. package/dist/types/manifest.js +4 -0
  57. package/dist/types/model.d.ts +15 -5
  58. package/dist/utils/definition-files.d.ts +20 -6
  59. package/dist/utils/definition-files.js +31 -17
  60. package/dist/utils/file-systems.d.ts +20 -0
  61. package/dist/utils/file-systems.js +20 -0
  62. package/dist/utils/harness-id.d.ts +4 -1
  63. package/dist/utils/harness-id.js +4 -1
  64. package/dist/utils/media-types.d.ts +30 -0
  65. package/dist/utils/media-types.js +128 -0
  66. package/dist/utils/memory.d.ts +64 -0
  67. package/dist/utils/memory.js +139 -0
  68. package/dist/utils/runtime-limits.d.ts +280 -0
  69. package/dist/utils/runtime-limits.js +585 -0
  70. package/dist/utils/runtime-tools.d.ts +8 -16
  71. package/dist/utils/runtime-tools.js +8 -27
  72. package/dist/utils/sandbox.d.ts +4 -1
  73. package/dist/utils/sandbox.js +4 -1
  74. package/package.json +6 -5
  75. package/dist/definition/deferred-tools.d.ts +0 -27
  76. package/dist/definition/deferred-tools.js +0 -82
  77. package/dist/definition/runtime-manifest.d.ts +0 -30
  78. package/dist/definition/runtime-manifest.js +0 -132
  79. package/dist/definition/sandbox-tools.d.ts +0 -5
  80. package/dist/definition/sandbox-tools.js +0 -109
  81. package/dist/definition/skill-tools.d.ts +0 -23
  82. package/dist/definition/skill-tools.js +0 -76
@@ -7,17 +7,40 @@
7
7
  import { z } from "zod";
8
8
  import { ABORT_REASONS, HARNESS_API_VERSION, HARNESS_CLAIMS, HARNESS_ERROR_CODES, } from "./messages.js";
9
9
  import { HarnessApiError } from "./errors.js";
10
- import { EffectOutcomeSchema } from "../contracts.js";
10
+ import { ARTIFACT_NAME_MAX, ENVIRONMENT_KINDS, EffectOutcomeSchema, ModelInputSchema } from "../contracts.js";
11
+ import { HarnessLimitsSchema, RUNTIME_LIMIT_CEILINGS } from "../utils/runtime-limits.js";
11
12
  import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
12
- import { McpSnapshotSchema } from "./mcp.js";
13
+ import { McpFactsSchema, McpSnapshotSchema } from "./mcp.js";
14
+ /** An id in a Harness API frame, at most 512 characters: an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting. */
13
15
  const id = z.string().min(1).max(512);
16
+ const hex64 = z.string().regex(/^[0-9a-f]{64}$/);
14
17
  const runId = z.object({ runId: id });
15
18
  /** An engine document (a manifest, a checkpoint): an object here, which the engine checks. */
16
19
  const document = z.record(z.string(), z.unknown());
17
- /** The payload of one `transcript.updated` event. */
18
- export const TranscriptUpdateSchema = z
19
- .object({ keep: z.number().int().min(0), entries: z.array(z.unknown()), length: z.number().int().min(0) })
20
+ const edit = { keep: z.number().int().min(0), entries: z.array(z.unknown()), length: z.number().int().min(0) };
21
+ /**
22
+ * What a harness says of a compaction it made (protocol 15): why, its estimated tokens before and
23
+ * after, and the model calls of this turn that wrote the summary (`purpose: "summary"`), in
24
+ * order. Core checks them and writes one `context.compacted` from them and the last call.
25
+ */
26
+ export const CompactionFactsSchema = z
27
+ .object({
28
+ trigger: z.enum(["threshold", "overflow"]),
29
+ tokensBefore: z.number().int().min(0),
30
+ tokensAfter: z.number().int().min(0),
31
+ summaryEffectIds: z.array(id).min(1),
32
+ })
20
33
  .strict();
34
+ /**
35
+ * The payload of one `transcript.updated` event: keep the first `keep` entries, append `entries`,
36
+ * giving `length` entries. A harness that replaced older history with a summary marks the edit
37
+ * `kind: "compaction"` with its facts (the first chunk of the edit; the record never parses the
38
+ * entries to find one).
39
+ */
40
+ export const TranscriptUpdateSchema = z.union([
41
+ z.object(edit).strict(),
42
+ z.object({ kind: z.literal("compaction"), ...edit, compaction: CompactionFactsSchema }).strict(),
43
+ ]);
21
44
  export const FrameSchema = z.union([
22
45
  z.object({ t: z.literal("req"), id: z.number().int().positive(), m: z.string().min(1), p: z.unknown() }).strict(),
23
46
  z.object({ t: z.literal("res"), id: z.number().int().positive(), ok: z.literal(true), r: z.unknown() }).strict(),
@@ -33,12 +56,58 @@ export const FrameSchema = z.union([
33
56
  z.object({ t: z.literal("abort"), id: z.number().int().positive() }).strict(),
34
57
  z.object({ t: z.literal("ping") }).strict(),
35
58
  ]);
59
+ /**
60
+ * What a tool call runs (protocol 15). The record routes a call by its target, never by the
61
+ * tool's name: the name the model used (`toolName`) is for display, and no name is reserved.
62
+ *
63
+ * - `mcp`: the tool `tool` (its own name on the server) of the MCP server `server` that the call's
64
+ * agent declares (`effect.agent`, absent for the root), as the session discovered it
65
+ * (`turn.start.mcp`); the harness calls it through the Tool Gate. The record refuses one the
66
+ * session did not discover (`tool.unknown`) or the turn disables (`tool.disabled`).
67
+ * - `http`: the HTTP tool the agent declares as `tool`; the harness calls it through the Tool Gate.
68
+ * - `sandbox`: one of the sandbox operations (`bash`, `read`, `write`, `edit`, `grep`, `glob`,
69
+ * named by `toolName`) in the session's sandbox, which the harness runs. Only a session with a
70
+ * sandbox runs one.
71
+ * - `harness`: a tool the harness runs in its own process over the Harness API's seams, such as
72
+ * our engine's `load_skill`, `read_artifact` and `tool_search`. Its egress gate is its only
73
+ * control.
74
+ *
75
+ * Tool policy and approval key on the identity (`server` and `tool`, or the HTTP tool's declared
76
+ * name), never on the model's name. A tool call without a target, or with one the session lacks,
77
+ * fails to the model (`tool.unavailable`), and nothing runs.
78
+ */
79
+ export const EffectTargetSchema = z.discriminatedUnion("kind", [
80
+ z.object({ kind: z.literal("mcp"), server: z.string().min(1), tool: z.string().min(1) }).strict(),
81
+ z.object({ kind: z.literal("http"), tool: z.string().min(1) }).strict(),
82
+ z.object({ kind: z.literal("sandbox") }).strict(),
83
+ z.object({ kind: z.literal("harness") }).strict(),
84
+ /**
85
+ * An operation the Runtime itself serves, in the transaction that journals the call, keyed by
86
+ * the effect id (track T4): `schedule_wake` books the session's next turn (D77); `memory` (track
87
+ * T5, D72) is a call of the `memory` tool, with Anthropic's memory tool parameters as its input,
88
+ * on the Agent's memories. Answered at once; the harness never executes it.
89
+ */
90
+ z.object({ kind: z.literal("runtime"), operation: z.enum(["schedule_wake", "memory"]) }).strict(),
91
+ ]);
36
92
  /**
37
93
  * One effect the engine asks for: a `HostEffect`, by structure. Model intents carry no `input`.
38
94
  * `context` carries the ids the record derives its events from: a model effect's
39
95
  * `invocationId` (the step), and a tool effect's `callId` (the model's tool call id) and
40
96
  * `invocationId`; without them the call is journaled but no `tool.completed` is written. A
41
- * tool effect may name its step (`stepId`), which shares one result budget among its calls.
97
+ * tool effect may name its step (`stepId`).
98
+ *
99
+ * A model effect that writes a compaction's summary says so (`purpose: "summary"`): it is no
100
+ * assistant message, and the compaction edit that follows names it (`CompactionFactsSchema`).
101
+ *
102
+ * An agent's tool effect names its `target` (what runs it: for an MCP or HTTP tool, its
103
+ * identity) beside the name the model used (`toolName`, for display), and may name the `skill` it
104
+ * ran (a skill tool's skill, or a sandbox call in a skill's folder): the record keeps the skill,
105
+ * and the plugin that brought it, when the agent has that skill. The target is in the request
106
+ * hash, so a replay that names another tool is `effect_drift`.
107
+ *
108
+ * Each outcome the harness reports is one record entry: past `turn.start.limits.recordEntryBytes`
109
+ * it is refused (`limit_exceeded`), so a harness stores a large tool result with
110
+ * `artifact.write` and reports a preview.
42
111
  *
43
112
  * `requestHash` (`effectRequestHash`) covers the whole request: for a model effect, the intent
44
113
  * with `input` set to its `ModelCall`, though the intent is sent without it. A replay that asks
@@ -54,6 +123,10 @@ export const EffectIntentSchema = z
54
123
  kind: z.enum(["model", "tool", "delegation", "agent"]),
55
124
  agent: z.object({ id: z.string(), path: z.string(), delegationId: z.string().optional() }).strict().optional(),
56
125
  toolName: z.string().optional(),
126
+ target: EffectTargetSchema.optional(),
127
+ skill: z.string().min(1).optional(),
128
+ /** A model call that summarizes history for a compaction: the record writes no `message.assistant` for it. */
129
+ purpose: z.literal("summary").optional(),
57
130
  path: z.string().optional(),
58
131
  key: z.string().optional(),
59
132
  iterations: z.string().optional(),
@@ -65,10 +138,27 @@ export const EffectIntentSchema = z
65
138
  export const RecordedOutcomeSchema = z
66
139
  .object({ effectId: id, requestHash: z.string(), outcome: EffectOutcomeSchema })
67
140
  .strict();
141
+ /**
142
+ * An artifact as the artifact seam shows it to a harness: one version of a file (or a folder,
143
+ * whose bytes the seam does not serve). `tenantWide` marks a Tenant-wide artifact (no session),
144
+ * which the run reads only because the session's messages named it.
145
+ */
146
+ export const ArtifactMetaSchema = z
147
+ .object({
148
+ artifactId: id,
149
+ kind: z.enum(["file", "folder"]),
150
+ name: z.string(),
151
+ version: z.number().int().min(1),
152
+ contentType: z.string(),
153
+ size: z.number().int().nonnegative(),
154
+ sha256: z.string().regex(/^[0-9a-f]{64}$/),
155
+ tenantWide: z.boolean(),
156
+ })
157
+ .strict();
68
158
  /** A workspace's compute record, as the harness keeps it. */
69
159
  export const WorkspaceRecordSchema = z
70
160
  .object({
71
- key: z.string().min(1).max(512),
161
+ key: id,
72
162
  sessionId: id,
73
163
  environmentId: id.optional(),
74
164
  backend: z.string(),
@@ -97,30 +187,6 @@ export const WorkspaceCallSchema = z
97
187
  input: z.unknown(),
98
188
  })
99
189
  .strict();
100
- /**
101
- * A file of a workspace read as bytes (`save_artifact`, F8.1), at most `maxBytes`. The answer is
102
- * `{kind: "read", path, base64}`, `{kind: "missing", path}` or a failed tool outcome.
103
- */
104
- export const WorkspaceBytesCallSchema = z
105
- .object({
106
- session: WorkspaceSessionSchema,
107
- spec: z.unknown(),
108
- bytes: z.object({ path: z.string().min(1), maxBytes: z.number().int().positive() }).strict(),
109
- })
110
- .strict();
111
- /**
112
- * The regular files under a directory of a workspace, recursively, at most `maxEntries + 1`
113
- * (the turn-end export, F8.2). The answer is `{kind: "listed", path, listing: {entries,
114
- * truncated}}`, `{kind: "missing", path}` (no sandbox yet, or not a directory) or a failed tool
115
- * outcome.
116
- */
117
- export const WorkspaceListCallSchema = z
118
- .object({
119
- session: WorkspaceSessionSchema,
120
- spec: z.unknown(),
121
- list: z.object({ dir: z.string().min(1), maxEntries: z.number().int().positive() }).strict(),
122
- })
123
- .strict();
124
190
  /**
125
191
  * One operation on the disk of a workspace (R2d step 3): `list` its entries (files with mode and
126
192
  * modification time, links, empty directories; paths relative to the volume, `workspace/…` and
@@ -136,7 +202,7 @@ export const DiskOpSchema = z.union([
136
202
  .object({
137
203
  path: z.string().min(1),
138
204
  offset: z.number().int().nonnegative(),
139
- length: z.number().int().positive().max(16 * 1024 * 1024),
205
+ length: z.number().int().positive().max(RUNTIME_LIMIT_CEILINGS.chunkBytes.value),
140
206
  })
141
207
  .strict(),
142
208
  })
@@ -177,9 +243,11 @@ export const RunRoutingSchema = z
177
243
  .object({
178
244
  /** The session's pinned manifest: an effect's agent resolves against it. */
179
245
  rootManifest: document,
180
- /** The session's MCP snapshot, once its first run recorded one (`session.mcp`). */
181
- mcpSnapshot: McpSnapshotSchema.optional(),
182
- /** The session's sandbox: the session, and the Environment whose sandbox it is. */
246
+ /**
247
+ * The session's sandbox: the session, and the Environment whose sandbox it is. `spec` is the
248
+ * sandbox spec the session pinned when it opened (`SandboxManifest`); absent, the session has
249
+ * no sandbox, and a `sandbox` call fails.
250
+ */
183
251
  sandbox: z
184
252
  .object({
185
253
  ownerId: id,
@@ -187,7 +255,7 @@ export const RunRoutingSchema = z
187
255
  spec: z.unknown().optional(),
188
256
  /**
189
257
  * Variables every sandbox command gets (R2c, D50): each `environment_secret` name set to
190
- * the sentinel `nylorun-managed`, and each `environment_variable`'s value. Never a secret.
258
+ * the sentinel `nylorun_managed`, and each `environment_variable`'s value. Never a secret.
191
259
  */
192
260
  environment: z.record(z.string(), z.string()).optional(),
193
261
  })
@@ -198,10 +266,12 @@ export const RunRoutingSchema = z
198
266
  /**
199
267
  * The fields of `TurnStart.checkpoint` a harness reads (R4.2); the rest are our engine's. An
200
268
  * agent turn's `input` is the turn's message: a string, `{text, metadata?}`, `{content,
201
- * metadata?}` with user content parts, `{kind: "continue"}` for the next segment of a yielded
202
- * turn, or an approval or response event. Effect ids are prefixed `<turnId>:<segment>:`
269
+ * metadata?}` with user content parts, `{kind: "messages", messages}` for messages that waited in
270
+ * the session's queue (protocol 17: each one of the shapes before, each its own user message, in
271
+ * order), `{kind: "continue"}` for the next segment of a yielded turn, or an approval or response
272
+ * event. Effect ids are prefixed `<turnId>:<segment>:`
203
273
  * (`effectIdOf`), and every intent carries `manifestHash`. `state` is the harness's own, as its
204
- * last output left it: core stores it unread (at most `MAX_HARNESS_STATE_BYTES` for a harness
274
+ * last output left it: core stores it unread (at most `limits.harnessStateBytes` for a harness
205
275
  * other than ours) and folds the transcript every segment, whatever the state holds. A model
206
276
  * call's `executionId` is the session id.
207
277
  */
@@ -221,20 +291,56 @@ export const TraceContextSchema = z
221
291
  })
222
292
  .strict();
223
293
  /**
224
- * A tool a harness runs itself (R4.2, Q3), declared in `hello`: the model may call it, and the
225
- * harness journals each call as a `tool` effect with intent and outcome, like a sandbox tool, so
226
- * the log records what really ran. Its name may not be one the agent or the Runtime already uses. It runs in
227
- * the harness's own process or pod: the egress gate is its only control.
294
+ * The model a turn's calls use when they name none (protocol 15): the Tenant's model, as the
295
+ * Model Gate resolves it. `provider` and `id` name it (`fixture` for the fixture model); `inputs`
296
+ * is what it reads, text first, in `MODEL_INPUTS` order (its catalog's inputs and the operator's
297
+ * additions); `contextWindow` and `maxOutputTokens` are in tokens. A harness decides from it how
298
+ * each file reaches the model; the gate refuses a part the model cannot take
299
+ * (`unsupported_input`).
228
300
  */
229
- export const NativeToolSchema = z
301
+ export const ModelDescriptorSchema = z
230
302
  .object({
231
- // `__` names an MCP server's tools, which are discovered after a turn starts.
232
- name: z
233
- .string()
234
- .regex(/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/)
235
- .refine((name) => !name.includes("__"), { message: "A harness's tool name must not contain '__'" }),
236
- description: z.string().max(4096).optional(),
237
- inputSchema: z.record(z.string(), z.unknown()),
303
+ provider: z.string().min(1),
304
+ id: z.string().min(1),
305
+ inputs: z.array(ModelInputSchema).min(1),
306
+ contextWindow: z.number().int().positive(),
307
+ maxOutputTokens: z.number().int().positive(),
308
+ reasoning: z.boolean().optional(),
309
+ })
310
+ .strict();
311
+ /**
312
+ * The Agent a turn runs on (Harness API 5, protocol 16): its id and kind and, when it has a
313
+ * sandbox, the workspace its commands start in. A harness writes the model's instructions and
314
+ * defines its sandbox tools from it; the sandbox's spec is the routing's (`routing.sandbox.spec`).
315
+ * The Agent's runtime section never reaches the harness.
316
+ */
317
+ export const TurnAgentSchema = z
318
+ .object({
319
+ id,
320
+ kind: z.enum(ENVIRONMENT_KINDS),
321
+ /** Present when the session has a sandbox. */
322
+ sandbox: z.object({ workspace: z.string().regex(/^\//) }).strict().optional(),
323
+ /**
324
+ * The version the session runs sets `runtime.selfWake` (track T4, D77): our engine offers
325
+ * `schedule_wake`, a `runtime` effect.
326
+ */
327
+ selfWake: z.boolean().optional(),
328
+ })
329
+ .strict();
330
+ /**
331
+ * The Agent's memory as a turn starts (track T5, D72), present when the version its session runs
332
+ * sets `harness.memory`: its access in every turn, the agent's own `instructions`, and the index a
333
+ * harness pins in the session (one line per memory, newest first, with its description, within
334
+ * the Runtime limits `memoryIndexLines` and `memoryIndexBytes`; `truncated` when some were left
335
+ * out). A harness offers the `memory` tool (a `runtime` effect, operation `memory`), view only for
336
+ * `read_only` and for its sub-agents.
337
+ */
338
+ export const TurnMemorySchema = z
339
+ .object({
340
+ access: z.enum(["read_write", "read_only"]),
341
+ instructions: z.string().optional(),
342
+ index: z.string(),
343
+ truncated: z.boolean(),
238
344
  })
239
345
  .strict();
240
346
  /** What a run starts from: `turn.start` (message, continue, resume) or `approval.answer`. */
@@ -242,11 +348,30 @@ export const TurnStartSchema = z
242
348
  .object({
243
349
  type: z.enum(["turn.start", "approval.answer"]),
244
350
  engine: z.enum(["agent", "flow"]),
245
- /** The turn's manifest (agent) or the workflow manifest (flow). */
351
+ /**
352
+ * The turn's loop manifest: the harness section of the agent manifest version its session
353
+ * pinned, with the manifest's name as its `id` (agent manifest v7's shape), or the workflow
354
+ * manifest (flow). A flow's leaf session gets its embedded agent's.
355
+ */
246
356
  manifest: document,
357
+ /** The agent manifest version the session pinned (protocol 16), for the harness's records. */
358
+ definition: z.object({ name: z.string(), version: z.number().int().positive() }).strict().optional(),
359
+ /**
360
+ * The harness section's `loop` (protocol 16): the harness's own settings, which the Runtime
361
+ * passes on without reading. Ours reads none yet.
362
+ */
363
+ loop: document.optional(),
364
+ /** The Agent's memory (track T5), when the version its session runs sets `harness.memory`. Absent for a flow. */
365
+ memory: TurnMemorySchema.optional(),
247
366
  /** The segment's checkpoint; an agent's state has no transcript (`transcript.cursor`). */
248
367
  checkpoint: document,
249
- sessionTools: z.array(z.unknown()).readonly().optional(),
368
+ /**
369
+ * The session's MCP discovery as this turn sees it (protocol 15), once its first run recorded
370
+ * it (`session.mcp`): each server of the agent tree that connected, its instructions and its
371
+ * tools, raw, with whether the turn's manifest leaves each `enabled`. The harness names the
372
+ * tools for the model and calls one by its target `{kind: "mcp", server, tool}`.
373
+ */
374
+ mcp: McpFactsSchema.optional(),
250
375
  /** Completed outcomes of this segment, resolved without asking core. */
251
376
  outcomes: z.array(RecordedOutcomeSchema).readonly(),
252
377
  /** The record position the session's transcript was folded at. */
@@ -269,6 +394,24 @@ export const TurnStartSchema = z
269
394
  * spans join the turn's trace. The Runtime never ingests a harness's spans.
270
395
  */
271
396
  trace: TraceContextSchema.optional(),
397
+ /**
398
+ * The Runtime limits in force when the segment started (the Tenant's, `PUT
399
+ * /v1/tenant/limits`): what one record entry (an effect outcome, a claimed event, a transcript
400
+ * update), model call, model file, tool answer, custom harness state, Harness API chunk and
401
+ * folder artifact may hold. Past one, core refuses the request with `limit_exceeded`. Only
402
+ * the limits a harness must respect (`HarnessLimitsSchema`); one it does not know is dropped.
403
+ */
404
+ limits: HarnessLimitsSchema,
405
+ /**
406
+ * The model the turn's calls use when they name none (protocol 15): what it reads and its
407
+ * window, as the segment started. Absent for a flow, and when the Tenant has no model.
408
+ */
409
+ model: ModelDescriptorSchema.optional(),
410
+ /**
411
+ * The Agent the session runs on (Harness API 5; `environment` before): what our engine writes
412
+ * the sandbox notes and defines the sandbox tools from. Absent for a flow.
413
+ */
414
+ agent: TurnAgentSchema.optional(),
272
415
  })
273
416
  .strict();
274
417
  /**
@@ -333,9 +476,7 @@ export const harnessRequests = {
333
476
  api: z.number().int(),
334
477
  name: z.string(),
335
478
  version: z.string(),
336
- features: z
337
- .object({ workspace: z.unknown().optional(), tools: z.array(NativeToolSchema).max(64).optional() })
338
- .strict(),
479
+ features: z.object({ workspace: z.unknown().optional() }).strict(),
339
480
  })
340
481
  .strict(),
341
482
  result: z
@@ -393,16 +534,159 @@ export const harnessRequests = {
393
534
  },
394
535
  "session.mcp": {
395
536
  params: runId.extend({ snapshot: McpSnapshotSchema.optional(), diagnostics: z.array(z.unknown()) }).strict(),
396
- result: z.object({ snapshot: McpSnapshotSchema.optional(), sessionTools: z.array(z.unknown()) }).strict(),
537
+ result: z.object({ mcp: McpFactsSchema.optional() }).strict(),
397
538
  },
398
539
  /**
399
540
  * A definition file's bytes, base64 (track R2 M4): one the run's definition names, for the
400
- * skills its sandbox mounts.
541
+ * skills its sandbox mounts. With `offset` and `length` (at most `turn.start.limits.chunkBytes`,
542
+ * its default without `length`; more is `limit_exceeded`), only those bytes: fewer than
543
+ * `length`, none past the end, once the file ends. Without them the whole file, which must then
544
+ * fit one frame.
401
545
  */
402
546
  "definition.file": {
403
- params: runId.extend({ sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/) }).strict(),
547
+ params: runId
548
+ .extend({
549
+ sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
550
+ offset: z.number().int().nonnegative().optional(),
551
+ length: z.number().int().positive().max(RUNTIME_LIMIT_CEILINGS.chunkBytes.value).optional(),
552
+ })
553
+ .strict(),
404
554
  result: z.object({ base64: z.string() }).strict(),
405
555
  },
556
+ /**
557
+ * An artifact the run's session may read (the artifact seam, protocol 15): one of the session's
558
+ * own, or a Tenant-wide one its messages named; anything else is `not_found`, alike. The answer
559
+ * carries the version's metadata (`version`, default the latest) and its bytes from `offset`
560
+ * (default 0), base64: at most `length`, which defaults to and is held to
561
+ * `turn.start.limits.chunkBytes`; `length: 0` asks for the metadata alone. `eof` says no bytes
562
+ * are left past this chunk. A folder answers its metadata, with no bytes.
563
+ */
564
+ "artifact.read": {
565
+ params: runId
566
+ .extend({
567
+ artifactId: id,
568
+ version: z.number().int().min(1).optional(),
569
+ offset: z.number().int().nonnegative().optional(),
570
+ length: z.number().int().nonnegative().optional(),
571
+ })
572
+ .strict(),
573
+ result: z
574
+ .object({
575
+ artifact: ArtifactMetaSchema,
576
+ offset: z.number().int().nonnegative(),
577
+ base64: z.string(),
578
+ eof: z.boolean(),
579
+ })
580
+ .strict(),
581
+ },
582
+ /**
583
+ * Writes a file artifact of the run's session, or a new version of one of its own (the artifact
584
+ * seam, protocol 15), streamed in chunks of at most `turn.start.limits.chunkBytes`:
585
+ *
586
+ * - `begin` opens an upload, answered `open` with its `uploadId` and the most bytes it may hold
587
+ * now (`maxBytes`: the file limit, or the room left in a total). `key` makes the write
588
+ * idempotent within the session: a key already written answers `written` with `created:
589
+ * false` and the version it wrote. With `base64`, the whole body comes in the `begin`, which
590
+ * then commits at once. `effectId` links the artifact to a tool call of the run's turn, whose
591
+ * call id its `artifact.created` event carries.
592
+ * - `chunk` sends the bytes from `offset`, which must equal the bytes received so far; a repeat
593
+ * of the last chunk is answered as before.
594
+ * - `commit` stores the version (`written`); `abort` drops the upload. An upload the run leaves
595
+ * open ends with the run.
596
+ *
597
+ * With `kind: "folder"`, `begin` opens a folder version instead: a new version of the session's
598
+ * folder `artifactId`, or with `sameName` of its newest folder named `name` (made when there is
599
+ * none), or else a new folder. Its answer adds `maxFileBytes` (one file's limit) and
600
+ * `maxEntries` (`limits.folderEntries`); `maxBytes` is the most its files may hold together.
601
+ * Each file starts with `file` (its path in the folder, size and SHA-256, the whole body in
602
+ * `base64` when it fits one chunk), and goes on with `chunk`s naming it by `sha256`, from
603
+ * `offset` within the file. Core always takes every byte, stored or not (it holds content once,
604
+ * by hash), and refuses a file whose bytes do not match its hash (`invalid`; the upload ends).
605
+ * `commit` answers `written` with `unchanged: true` and no new version when the files are the
606
+ * folder's latest version's, and `refused` when a total would be passed.
607
+ */
608
+ "artifact.write": {
609
+ params: z.union([
610
+ runId
611
+ .extend({
612
+ op: z.literal("begin"),
613
+ key: id,
614
+ artifactId: id.optional(),
615
+ name: z.string().min(1).max(ARTIFACT_NAME_MAX).optional(),
616
+ contentType: z.string().min(1).optional(),
617
+ size: z.number().int().nonnegative().optional(),
618
+ effectId: id.optional(),
619
+ base64: z.string().optional(),
620
+ })
621
+ .strict(),
622
+ runId
623
+ .extend({
624
+ op: z.literal("begin"),
625
+ kind: z.literal("folder"),
626
+ key: id,
627
+ name: z.string().min(1).max(ARTIFACT_NAME_MAX),
628
+ artifactId: id.optional(),
629
+ sameName: z.literal(true).optional(),
630
+ })
631
+ .strict(),
632
+ runId
633
+ .extend({
634
+ op: z.literal("file"),
635
+ uploadId: id,
636
+ path: z.string().min(1),
637
+ size: z.number().int().nonnegative(),
638
+ sha256: hex64,
639
+ contentType: z.string().min(1).optional(),
640
+ base64: z.string().optional(),
641
+ })
642
+ .strict(),
643
+ runId
644
+ .extend({
645
+ op: z.literal("chunk"),
646
+ uploadId: id,
647
+ /** A folder upload's file this chunk continues. */
648
+ sha256: hex64.optional(),
649
+ offset: z.number().int().nonnegative(),
650
+ base64: z.string().min(1),
651
+ })
652
+ .strict(),
653
+ runId.extend({ op: z.literal("commit"), uploadId: id }).strict(),
654
+ runId.extend({ op: z.literal("abort"), uploadId: id }).strict(),
655
+ ]),
656
+ result: z.union([
657
+ z
658
+ .object({
659
+ status: z.literal("open"),
660
+ uploadId: id,
661
+ maxBytes: z.number().int().nonnegative(),
662
+ /** A folder upload: one file's limit, and the most files it may hold. */
663
+ maxFileBytes: z.number().int().nonnegative().optional(),
664
+ maxEntries: z.number().int().positive().optional(),
665
+ /** Bytes received: of the upload, or of a folder upload's file in progress. */
666
+ received: z.number().int().nonnegative(),
667
+ })
668
+ .strict(),
669
+ z
670
+ .object({
671
+ status: z.literal("written"),
672
+ artifact: ArtifactMetaSchema,
673
+ created: z.boolean(),
674
+ /** A folder whose files are its latest version's: no version was added. */
675
+ unchanged: z.literal(true).optional(),
676
+ })
677
+ .strict(),
678
+ z
679
+ .object({
680
+ status: z.literal("refused"),
681
+ /** The total a folder version would pass: the Tenant's, or the session's Environment's. */
682
+ reason: z.enum(["tenant_total", "environment_total"]),
683
+ message: z.string(),
684
+ limit: z.number().int().nonnegative(),
685
+ })
686
+ .strict(),
687
+ z.object({ status: z.literal("aborted") }).strict(),
688
+ ]),
689
+ },
406
690
  "turn.completed": { params: TurnOutputSchema, result: settled },
407
691
  "turn.paused": { params: TurnOutputSchema, result: settled },
408
692
  "turn.waiting": { params: TurnOutputSchema, result: settled },
@@ -413,12 +697,11 @@ export const harnessRequests = {
413
697
  /**
414
698
  * Requests core sends to a harness that declared `workspace` (F6.2), with their answers. A
415
699
  * sandbox tool's answer is its `SandboxToolOutcome`; the harness claims its `environment.*` events
416
- * while the request is in flight. `workspace.read` stays generic: F8.2 exports outputs
417
- * through it.
700
+ * while the request is in flight.
418
701
  */
419
702
  export const coreRequests = {
420
703
  "workspace.read": {
421
- params: z.union([WorkspaceCallSchema, WorkspaceBytesCallSchema, WorkspaceListCallSchema, WorkspaceDiskCallSchema]),
704
+ params: z.union([WorkspaceCallSchema, WorkspaceDiskCallSchema]),
422
705
  result: outcomeObject,
423
706
  },
424
707
  "workspace.write": { params: z.union([WorkspaceCallSchema, WorkspaceDiskCallSchema]), result: outcomeObject },
@@ -4,15 +4,9 @@
4
4
  * records and folds them, and a harness, which computes them and keeps its cache with them.
5
5
  */
6
6
  import type { z } from "zod";
7
- import type { TranscriptUpdateSchema } from "./schema.js";
7
+ import type { CompactionFactsSchema, TranscriptUpdateSchema } from "./schema.js";
8
8
  /** The payload of one `transcript.updated` event. */
9
9
  export type TranscriptUpdate = z.infer<typeof TranscriptUpdateSchema>;
10
- /**
11
- * An edit's entries are split so each event stays well under S2's 1 MiB record limit: under
12
- * 64 KiB when no entry is larger, as a step with one tool result is once the result fits its
13
- * 32 KiB cap (R2b C11). An entry larger than this is an event of its own.
14
- */
15
- export declare const CHUNK_BYTES: number;
16
10
  export declare class TranscriptFoldError extends Error {
17
11
  constructor(message: string);
18
12
  }
@@ -21,10 +15,14 @@ export declare function transcriptOf(state: unknown): unknown[];
21
15
  /** `state` with `transcript` (what the engine runs on). */
22
16
  export declare function withTranscript<T>(state: T, transcript: readonly unknown[]): T;
23
17
  /**
24
- * The edits from `before` to `after`, split into chunks of at most `CHUNK_BYTES` of entries.
25
- * Empty when nothing changed.
18
+ * The edits from `before` to `after`, each one `transcript.updated` event: an edit's entries fill
19
+ * each event up to `recordEntryBytes` (the run's `turn.start.limits`), the most one record entry
20
+ * holds, with room for the edit's own fields. An entry larger than that is an event of its own,
21
+ * which the record refuses (`limit_exceeded`). Empty when nothing changed. With `compaction`, the
22
+ * edit replaced older history with a summary: its first event says so (`kind: "compaction"`,
23
+ * with the facts).
26
24
  */
27
- export declare function transcriptUpdates(before: readonly unknown[], after: readonly unknown[], chunkBytes?: number): TranscriptUpdate[];
25
+ export declare function transcriptUpdates(before: readonly unknown[], after: readonly unknown[], recordEntryBytes: number, compaction?: z.infer<typeof CompactionFactsSchema>): TranscriptUpdate[];
28
26
  /** Applies one edit. Throws `TranscriptFoldError` when it does not fit the transcript. */
29
27
  export declare function applyUpdate(transcript: readonly unknown[], update: TranscriptUpdate): unknown[];
30
28
  /** Applies edits in order. */
@@ -1,9 +1,3 @@
1
- /**
2
- * An edit's entries are split so each event stays well under S2's 1 MiB record limit: under
3
- * 64 KiB when no entry is larger, as a step with one tool result is once the result fits its
4
- * 32 KiB cap (R2b C11). An entry larger than this is an event of its own.
5
- */
6
- export const CHUNK_BYTES = 48 * 1024;
7
1
  export class TranscriptFoldError extends Error {
8
2
  constructor(message) {
9
3
  super(message);
@@ -22,11 +16,32 @@ export function withTranscript(state, transcript) {
22
16
  return state;
23
17
  return { ...state, transcript: [...transcript] };
24
18
  }
19
+ /** The bytes of `text` as UTF-8, as the record measures an entry. */
20
+ const utf8Bytes = (text) => new TextEncoder().encode(text).length;
25
21
  /**
26
- * The edits from `before` to `after`, split into chunks of at most `CHUNK_BYTES` of entries.
27
- * Empty when nothing changed.
22
+ * The edits from `before` to `after`, each one `transcript.updated` event: an edit's entries fill
23
+ * each event up to `recordEntryBytes` (the run's `turn.start.limits`), the most one record entry
24
+ * holds, with room for the edit's own fields. An entry larger than that is an event of its own,
25
+ * which the record refuses (`limit_exceeded`). Empty when nothing changed. With `compaction`, the
26
+ * edit replaced older history with a summary: its first event says so (`kind: "compaction"`,
27
+ * with the facts).
28
28
  */
29
- export function transcriptUpdates(before, after, chunkBytes = CHUNK_BYTES) {
29
+ export function transcriptUpdates(before, after, recordEntryBytes, compaction) {
30
+ // The fields beside the entries, at their longest: the first event's, and every other's.
31
+ const fields = utf8Bytes(JSON.stringify({
32
+ kind: "compaction",
33
+ keep: Number.MAX_SAFE_INTEGER,
34
+ entries: [],
35
+ length: Number.MAX_SAFE_INTEGER,
36
+ ...(compaction === undefined ? {} : { compaction }),
37
+ }));
38
+ const updates = edits(before, after, recordEntryBytes - fields);
39
+ if (compaction === undefined || updates.length === 0)
40
+ return updates;
41
+ const [first, ...rest] = updates;
42
+ return [{ kind: "compaction", ...first, compaction }, ...rest];
43
+ }
44
+ function edits(before, after, entryBytes) {
30
45
  let keep = 0;
31
46
  while (keep < before.length && keep < after.length && same(before[keep], after[keep]))
32
47
  keep += 1;
@@ -46,8 +61,9 @@ export function transcriptUpdates(before, after, chunkBytes = CHUNK_BYTES) {
46
61
  bytes = 0;
47
62
  };
48
63
  for (const entry of added) {
49
- const size = JSON.stringify(entry).length;
50
- if (chunk.length > 0 && bytes + size > chunkBytes)
64
+ // The entry's JSON and the comma before the next.
65
+ const size = utf8Bytes(JSON.stringify(entry)) + 1;
66
+ if (chunk.length > 0 && bytes + size > entryBytes)
51
67
  flush();
52
68
  chunk.push(entry);
53
69
  bytes += size;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * - the transport: path `/nylorun/harness/v1` and header `Nylorun-Harness-Api: 1`, for the
5
5
  * WebSocket and its frames (`FrameSchema`), one JSON text message per frame;
6
- * - the messages: `HARNESS_API_VERSION` (2), which a harness names in `hello.api` and core
6
+ * - the messages: `HARNESS_API_VERSION`, which a harness names in `hello.api` and core
7
7
  * checks;
8
8
  * - the Runtime's protocol, which the Runtime and Management APIs carry, never this one.
9
9
  *
@@ -29,6 +29,12 @@ export declare const HOST_RENEW_PATH = "/nylorun/harness/v1/host/renew";
29
29
  * mounted join file (afresh each time: a reset writes a new one), and the id the harness keeps on
30
30
  * the volume (`/harness/volume-id`), so a volume recreated empty is told apart.
31
31
  */
32
+ /**
33
+ * A pod's UID or a volume id: a Kubernetes UID is an RFC 4122 UUID (36 characters); 64 leaves a
34
+ * volume id room. With the join token's 512, an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting.
35
+ */
36
+ export declare const POD_UID_PATTERN: RegExp;
37
+ export declare const JOIN_TOKEN_MAX = 512;
32
38
  export declare const HostJoinRequestSchema: z.ZodObject<{
33
39
  sandboxId: z.ZodString;
34
40
  podUid: z.ZodString;