@nylorun/core 0.19.0-beta → 0.21.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 (98) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +148 -32
  4. package/dist/compatibility.js +154 -33
  5. package/dist/contracts.d.ts +2714 -495
  6. package/dist/contracts.js +1395 -493
  7. package/dist/define.d.ts +15 -12
  8. package/dist/define.js +11 -7
  9. package/dist/definition/approval.d.ts +16 -0
  10. package/dist/definition/approval.js +33 -0
  11. package/dist/definition/assemble.d.ts +6 -10
  12. package/dist/definition/assemble.js +48 -105
  13. package/dist/definition/bind-agent.d.ts +3 -4
  14. package/dist/definition/bind-agent.js +12 -30
  15. package/dist/definition/binding.d.ts +2 -2
  16. package/dist/definition/bound.d.ts +10 -10
  17. package/dist/definition/builder.d.ts +16 -20
  18. package/dist/definition/builder.js +29 -81
  19. package/dist/definition/code-tools.d.ts +4 -4
  20. package/dist/definition/code-tools.js +7 -22
  21. package/dist/definition/declaration.d.ts +4 -7
  22. package/dist/definition/declaration.js +29 -99
  23. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  24. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  25. package/dist/definition/delegate.d.ts +2 -4
  26. package/dist/definition/delegate.js +8 -10
  27. package/dist/definition/flow/compile.js +0 -2
  28. package/dist/definition/from.d.ts +7 -4
  29. package/dist/definition/from.js +72 -117
  30. package/dist/definition/helpers.d.ts +0 -7
  31. package/dist/definition/helpers.js +0 -5
  32. package/dist/definition/http-tool.d.ts +7 -4
  33. package/dist/definition/http-tool.js +6 -10
  34. package/dist/definition/implementations.d.ts +6 -8
  35. package/dist/definition/manifest.d.ts +11 -5
  36. package/dist/definition/manifest.js +27 -26
  37. package/dist/definition/mcp.d.ts +1 -52
  38. package/dist/definition/mcp.js +11 -60
  39. package/dist/definition/media-reference.d.ts +23 -0
  40. package/dist/definition/media-reference.js +26 -0
  41. package/dist/definition/removed.d.ts +3 -10
  42. package/dist/definition/removed.js +10 -17
  43. package/dist/definition/runtime-manifest.d.ts +30 -0
  44. package/dist/definition/runtime-manifest.js +132 -0
  45. package/dist/definition/sandbox-tools.d.ts +1 -1
  46. package/dist/definition/sandbox-tools.js +1 -1
  47. package/dist/definition/skill-tools.d.ts +13 -7
  48. package/dist/definition/skill-tools.js +23 -10
  49. package/dist/definition/trace.d.ts +18 -0
  50. package/dist/definition/trace.js +42 -0
  51. package/dist/definition/variant.d.ts +5 -4
  52. package/dist/definition/variant.js +23 -55
  53. package/dist/definition/workflow/runnable.js +1 -1
  54. package/dist/errors.d.ts +1 -1
  55. package/dist/harness-api/entries.d.ts +242 -0
  56. package/dist/harness-api/entries.js +118 -0
  57. package/dist/harness-api/gates.d.ts +167 -0
  58. package/dist/harness-api/gates.js +117 -0
  59. package/dist/harness-api/harness-api.schema.json +4975 -0
  60. package/dist/harness-api/index.d.ts +19 -3
  61. package/dist/harness-api/index.js +16 -3
  62. package/dist/harness-api/json-schema.d.ts +12 -0
  63. package/dist/harness-api/json-schema.js +61 -0
  64. package/dist/harness-api/mcp.d.ts +57 -0
  65. package/dist/harness-api/mcp.js +39 -0
  66. package/dist/harness-api/messages.d.ts +11 -5
  67. package/dist/harness-api/messages.js +5 -3
  68. package/dist/harness-api/schema.d.ts +346 -36
  69. package/dist/harness-api/schema.js +143 -22
  70. package/dist/harness-api/transport.d.ts +55 -0
  71. package/dist/harness-api/transport.js +61 -0
  72. package/dist/index.d.ts +1 -1
  73. package/dist/manifest-schemas.d.ts +6 -0
  74. package/dist/manifest-schemas.js +34 -0
  75. package/dist/schemas/agent-manifest.schema.json +897 -0
  76. package/dist/schemas/environment-manifest.schema.json +329 -0
  77. package/dist/types/agent.d.ts +1 -1
  78. package/dist/types/manifest.d.ts +48 -28
  79. package/dist/types/model.d.ts +2 -2
  80. package/dist/types/observe.d.ts +8 -20
  81. package/dist/types/part.d.ts +25 -0
  82. package/dist/types/tool.d.ts +1 -1
  83. package/dist/types/transcript.d.ts +5 -0
  84. package/dist/utils/definition-files.d.ts +11 -6
  85. package/dist/utils/definition-files.js +19 -9
  86. package/dist/utils/harness-id.d.ts +9 -0
  87. package/dist/utils/harness-id.js +11 -0
  88. package/dist/utils/runtime-tools.d.ts +19 -0
  89. package/dist/utils/runtime-tools.js +30 -0
  90. package/dist/utils/sandbox.d.ts +1 -1
  91. package/dist/utils/sandbox.js +1 -1
  92. package/package.json +11 -4
  93. package/dist/definition/capability.d.ts +0 -43
  94. package/dist/definition/capability.js +0 -82
  95. package/dist/definition/sandbox-capability.d.ts +0 -44
  96. package/dist/definition/sandbox-capability.js +0 -139
  97. package/dist/types/middleware.d.ts +0 -94
  98. /package/dist/types/{middleware.js → part.js} +0 -0
@@ -9,6 +9,7 @@ import { ABORT_REASONS, HARNESS_API_VERSION, HARNESS_CLAIMS, HARNESS_ERROR_CODES
9
9
  import { HarnessApiError } from "./errors.js";
10
10
  import { EffectOutcomeSchema } from "../contracts.js";
11
11
  import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
12
+ import { McpSnapshotSchema } from "./mcp.js";
12
13
  const id = z.string().min(1).max(512);
13
14
  const runId = z.object({ runId: id });
14
15
  /** An engine document (a manifest, a checkpoint): an object here, which the engine checks. */
@@ -32,7 +33,17 @@ export const FrameSchema = z.union([
32
33
  z.object({ t: z.literal("abort"), id: z.number().int().positive() }).strict(),
33
34
  z.object({ t: z.literal("ping") }).strict(),
34
35
  ]);
35
- /** One effect the engine asks for: a `HostEffect`, by structure. Model intents carry no `input`. */
36
+ /**
37
+ * One effect the engine asks for: a `HostEffect`, by structure. Model intents carry no `input`.
38
+ * `context` carries the ids the record derives its events from: a model effect's
39
+ * `invocationId` (the step), and a tool effect's `callId` (the model's tool call id) and
40
+ * `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.
42
+ *
43
+ * `requestHash` (`effectRequestHash`) covers the whole request: for a model effect, the intent
44
+ * with `input` set to its `ModelCall`, though the intent is sent without it. A replay that asks
45
+ * for the same id with another hash is `effect_drift`.
46
+ */
36
47
  export const EffectIntentSchema = z
37
48
  .object({
38
49
  effectId: id,
@@ -42,7 +53,6 @@ export const EffectIntentSchema = z
42
53
  manifestHash: z.string(),
43
54
  kind: z.enum(["model", "tool", "delegation", "agent"]),
44
55
  agent: z.object({ id: z.string(), path: z.string(), delegationId: z.string().optional() }).strict().optional(),
45
- capabilityId: z.string().optional(),
46
56
  toolName: z.string().optional(),
47
57
  path: z.string().optional(),
48
58
  key: z.string().optional(),
@@ -60,7 +70,7 @@ export const WorkspaceRecordSchema = z
60
70
  .object({
61
71
  key: z.string().min(1).max(512),
62
72
  sessionId: id,
63
- sandboxId: id.optional(),
73
+ environmentId: id.optional(),
64
74
  backend: z.string(),
65
75
  image: z.string(),
66
76
  state: z.enum(["creating", "running", "stopped"]),
@@ -68,12 +78,12 @@ export const WorkspaceRecordSchema = z
68
78
  updatedAt: z.string(),
69
79
  })
70
80
  .strict();
71
- /** The session a workspace request acts for: the workspace's owner and its sandbox resource. */
81
+ /** The session a workspace request acts for, and the Environment whose workspace it is. */
72
82
  export const WorkspaceSessionSchema = z
73
83
  .object({
74
- /** The session that owns the workspace: its log records the workspace's events. */
84
+ /** The session the request acts for: its log records the workspace's events. */
75
85
  ownerId: id,
76
- sandboxId: id.optional(),
86
+ environmentId: id.optional(),
77
87
  activeTurnId: id.nullable(),
78
88
  })
79
89
  .strict();
@@ -111,6 +121,46 @@ export const WorkspaceListCallSchema = z
111
121
  list: z.object({ dir: z.string().min(1), maxEntries: z.number().int().positive() }).strict(),
112
122
  })
113
123
  .strict();
124
+ /**
125
+ * One operation on the disk of a workspace (R2d step 3): `list` its entries (files with mode and
126
+ * modification time, links, empty directories; paths relative to the volume, `workspace/…` and
127
+ * in a pod `harness/…`), `read` a range of one file (answered `{kind: "read", base64, eof}`),
128
+ * `clear` it (the engine's own files stay), or `put` entries back in order. A `workspace.read`
129
+ * carries `list` or `read`; a `workspace.write` `clear` or `put`.
130
+ */
131
+ export const DiskOpSchema = z.union([
132
+ z.object({ list: z.object({ maxEntries: z.number().int().positive() }).strict() }).strict(),
133
+ z
134
+ .object({
135
+ read: z
136
+ .object({
137
+ path: z.string().min(1),
138
+ offset: z.number().int().nonnegative(),
139
+ length: z.number().int().positive().max(16 * 1024 * 1024),
140
+ })
141
+ .strict(),
142
+ })
143
+ .strict(),
144
+ z.object({ clear: z.literal(true) }).strict(),
145
+ z
146
+ .object({
147
+ put: z.array(z
148
+ .object({
149
+ path: z.string().min(1),
150
+ type: z.enum(["file", "dir", "link"]),
151
+ mode: z.number().int().nonnegative().optional(),
152
+ mtimeMs: z.number().nonnegative().optional(),
153
+ base64: z.string().optional(),
154
+ append: z.boolean().optional(),
155
+ target: z.string().optional(),
156
+ })
157
+ .strict()),
158
+ })
159
+ .strict(),
160
+ ]);
161
+ export const WorkspaceDiskCallSchema = z
162
+ .object({ session: WorkspaceSessionSchema, spec: z.unknown(), disk: DiskOpSchema })
163
+ .strict();
114
164
  /** The lease on one run. `token` is the run token (F5) when the gates require one. */
115
165
  export const RunGrantSchema = z
116
166
  .object({
@@ -127,12 +177,13 @@ export const RunRoutingSchema = z
127
177
  .object({
128
178
  /** The session's pinned manifest: an effect's agent resolves against it. */
129
179
  rootManifest: document,
130
- mcpSnapshot: z.unknown().optional(),
131
- /** The session that owns the tree's sandbox, and the sandbox resource it is attached to. */
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. */
132
183
  sandbox: z
133
184
  .object({
134
185
  ownerId: id,
135
- sandboxId: id.optional(),
186
+ environmentId: id.optional(),
136
187
  spec: z.unknown().optional(),
137
188
  /**
138
189
  * Variables every sandbox command gets (R2c, D50): each `environment_secret` name set to
@@ -144,6 +195,48 @@ export const RunRoutingSchema = z
144
195
  .optional(),
145
196
  })
146
197
  .strict();
198
+ /**
199
+ * The fields of `TurnStart.checkpoint` a harness reads (R4.2); the rest are our engine's. An
200
+ * 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>:`
203
+ * (`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
205
+ * other than ours) and folds the transcript every segment, whatever the state holds. A model
206
+ * call's `executionId` is the session id.
207
+ */
208
+ export const HarnessCheckpointSchema = z.looseObject({
209
+ sessionId: id,
210
+ turnId: id,
211
+ segment: z.number().int().min(0),
212
+ manifestHash: z.string(),
213
+ input: z.unknown().optional(),
214
+ state: z.unknown().optional(),
215
+ });
216
+ /** W3C trace context: `traceparent`, and `tracestate` when the trace carries one. */
217
+ export const TraceContextSchema = z
218
+ .object({
219
+ traceparent: z.string().regex(/^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/),
220
+ tracestate: z.string().max(512).optional(),
221
+ })
222
+ .strict();
223
+ /**
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.
228
+ */
229
+ export const NativeToolSchema = z
230
+ .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()),
238
+ })
239
+ .strict();
147
240
  /** What a run starts from: `turn.start` (message, continue, resume) or `approval.answer`. */
148
241
  export const TurnStartSchema = z
149
242
  .object({
@@ -162,15 +255,31 @@ export const TurnStartSchema = z
162
255
  .object({
163
256
  yieldAfter: z.object({ steps: z.number().optional(), ms: z.number().optional() }).strict().optional(),
164
257
  flowLimits: z.unknown().optional(),
258
+ /**
259
+ * Informational: the Tenant answers model calls with the fixture model. The Model Gate
260
+ * answers them itself (R4.3), so a harness calls the gate as for any model.
261
+ */
165
262
  fixtureModel: z.boolean(),
166
263
  })
167
264
  .strict(),
168
265
  routing: RunRoutingSchema,
266
+ /**
267
+ * The turn's trace context (R4.10), when the Runtime traces: a harness may send it as
268
+ * `traceparent` on its gate calls and as `TRACEPARENT` to the processes it starts, so its own
269
+ * spans join the turn's trace. The Runtime never ingests a harness's spans.
270
+ */
271
+ trace: TraceContextSchema.optional(),
169
272
  })
170
273
  .strict();
171
274
  /**
172
- * A segment's end. `state` is the agent's engine state without its transcript; `transcript`
173
- * edits the transcript the segment started from. `thrown` reports an engine that threw.
275
+ * A segment's end. `state` is the harness's state for the next segment (our engine's has no
276
+ * transcript); `transcript` edits the transcript the segment started from. `thrown` reports an
277
+ * engine that threw. The method follows the status: `completed` is `turn.completed`, `failed`
278
+ * and `cancelled` are `turn.failed` (after a cancel, report `cancelled`), `waiting` and
279
+ * `uncertain` are `turn.waiting` (an effect is pending or uncertain), `yielded` is `checkpoint`
280
+ * (the turn goes on in a new segment), `paused` is `turn.paused` (our engine only, in v2). An
281
+ * `execute` answer with `rejoin` re-sends a call its previous owner left running at a gate,
282
+ * same key and body, to join it or collect its outcome.
174
283
  */
175
284
  export const TurnOutputSchema = z
176
285
  .object({
@@ -192,7 +301,17 @@ export const ReleaseReasonSchema = z.enum(["shutdown", "ownership.lost", "connec
192
301
  export const IntentAnswerSchema = z.union([
193
302
  z.object({ status: z.literal("completed"), outcome: EffectOutcomeSchema }).strict(),
194
303
  z.object({ status: z.enum(["pending", "uncertain"]) }).strict(),
195
- z.object({ status: z.literal("execute"), rejoin: z.literal(true).optional() }).strict(),
304
+ z
305
+ .object({
306
+ status: z.literal("execute"),
307
+ rejoin: z.literal(true).optional(),
308
+ /**
309
+ * The call's span context (R7.4), for a tool call: a harness hands it on as `TRACEPARENT`
310
+ * to the command it runs, so the command's own spans join the call's.
311
+ */
312
+ traceparent: TraceContextSchema.shape.traceparent.optional(),
313
+ })
314
+ .strict(),
196
315
  ]);
197
316
  export const OutcomeAnswerSchema = z.union([
198
317
  z.object({ status: z.literal("completed"), outcome: EffectOutcomeSchema }).strict(),
@@ -204,7 +323,7 @@ const outcomeObject = z.record(z.string(), z.unknown());
204
323
  /** Requests a harness sends to core, with their answers. */
205
324
  export const harnessRequests = {
206
325
  /**
207
- * `capabilities.workspace` declares that the harness serves the Tenant's workspaces (F6.2):
326
+ * `features.workspace` declares that the harness serves the Tenant's workspaces (F6.2):
208
327
  * core then sends it the `workspace.*` requests. The answer names the Tenant (its workspace
209
328
  * keys are scoped by it) and the sandbox backend preference the harness selects with.
210
329
  */
@@ -214,7 +333,9 @@ export const harnessRequests = {
214
333
  api: z.number().int(),
215
334
  name: z.string(),
216
335
  version: z.string(),
217
- capabilities: z.object({ workspace: z.unknown().optional() }).strict(),
336
+ features: z
337
+ .object({ workspace: z.unknown().optional(), tools: z.array(NativeToolSchema).max(64).optional() })
338
+ .strict(),
218
339
  })
219
340
  .strict(),
220
341
  result: z
@@ -264,15 +385,15 @@ export const harnessRequests = {
264
385
  turnId: id.nullable(),
265
386
  type: z.enum(HARNESS_CLAIMS),
266
387
  payload: z.unknown(),
267
- /** With `sandbox.state`: the workspace's compute record as it is now. */
388
+ /** With `environment.state`: the workspace's compute record as it is now. */
268
389
  record: WorkspaceRecordSchema.optional(),
269
390
  })
270
391
  .strict(),
271
392
  result: empty,
272
393
  },
273
394
  "session.mcp": {
274
- params: runId.extend({ snapshot: z.unknown().optional(), diagnostics: z.array(z.unknown()) }).strict(),
275
- result: z.object({ snapshot: z.unknown(), sessionTools: z.array(z.unknown()) }).strict(),
395
+ 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(),
276
397
  },
277
398
  /**
278
399
  * A definition file's bytes, base64 (track R2 M4): one the run's definition names, for the
@@ -291,16 +412,16 @@ export const harnessRequests = {
291
412
  };
292
413
  /**
293
414
  * Requests core sends to a harness that declared `workspace` (F6.2), with their answers. A
294
- * sandbox tool's answer is its `SandboxToolOutcome`; the harness claims its `sandbox.*` events
415
+ * sandbox tool's answer is its `SandboxToolOutcome`; the harness claims its `environment.*` events
295
416
  * while the request is in flight. `workspace.read` stays generic: F8.2 exports outputs
296
417
  * through it.
297
418
  */
298
419
  export const coreRequests = {
299
420
  "workspace.read": {
300
- params: z.union([WorkspaceCallSchema, WorkspaceBytesCallSchema, WorkspaceListCallSchema]),
421
+ params: z.union([WorkspaceCallSchema, WorkspaceBytesCallSchema, WorkspaceListCallSchema, WorkspaceDiskCallSchema]),
301
422
  result: outcomeObject,
302
423
  },
303
- "workspace.write": { params: WorkspaceCallSchema, result: outcomeObject },
424
+ "workspace.write": { params: z.union([WorkspaceCallSchema, WorkspaceDiskCallSchema]), result: outcomeObject },
304
425
  "workspace.exec": { params: WorkspaceCallSchema, result: outcomeObject },
305
426
  /** The harness's sandbox selection report (`GET /v1/tenant/sandbox`, Tenant status). */
306
427
  "workspace.report": { params: empty, result: outcomeObject },
@@ -309,12 +430,12 @@ export const coreRequests = {
309
430
  params: z.object({ now: z.number().optional() }).strict(),
310
431
  result: z.object({ workspaces: z.array(WorkspaceRecordSchema) }).strict(),
311
432
  },
312
- /** Deletes workspaces with their files: by key, by sandbox resource, or all of them. */
433
+ /** Deletes workspaces with their files: by key, by Environment, or all of them. */
313
434
  "workspace.remove": {
314
435
  params: z
315
436
  .object({
316
437
  keys: z.array(z.string().min(1)).optional(),
317
- sandboxIds: z.array(id).optional(),
438
+ environmentIds: z.array(id).optional(),
318
439
  all: z.literal(true).optional(),
319
440
  })
320
441
  .strict(),
@@ -0,0 +1,55 @@
1
+ /**
2
+ * How a harness reaches core (R4.5). Three version numbers apply, and each moves on its own:
3
+ *
4
+ * - the transport: path `/nylorun/harness/v1` and header `Nylorun-Harness-Api: 1`, for the
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
7
+ * checks;
8
+ * - the Runtime's protocol, which the Runtime and Management APIs carry, never this one.
9
+ *
10
+ * A harness container connects with `Authorization: Bearer <harness token>`. The harness in a
11
+ * pod sandbox holds no harness token: it exchanges the join token mounted in its pod for a host
12
+ * token (`POST .../host/join`), renews it (`POST .../host/renew`, `Authorization: Bearer <host
13
+ * token>`) every few minutes, and connects with the host token as its bearer. That connection
14
+ * serves its sandbox alone. Every refused join or renewal is the same `401`.
15
+ */
16
+ import { z } from "zod";
17
+ /** The URL path of the Harness API's WebSocket, on core's harness port (4200 by default). */
18
+ export declare const HARNESS_API_PATH = "/nylorun/harness/v1";
19
+ /** The upgrade header naming the transport version, and the only value accepted. */
20
+ export declare const HARNESS_API_HEADER = "nylorun-harness-api";
21
+ export declare const HARNESS_API_TRANSPORT = "1";
22
+ /** Largest frame either end accepts. */
23
+ export declare const HARNESS_MAX_PAYLOAD: number;
24
+ /** Where a pod's harness exchanges its join token, and renews its host token. */
25
+ export declare const HOST_JOIN_PATH = "/nylorun/harness/v1/host/join";
26
+ export declare const HOST_RENEW_PATH = "/nylorun/harness/v1/host/renew";
27
+ /**
28
+ * A pod's join: its sandbox (`NYLORUN_SANDBOX_ID`), its pod's UID, the join token read from the
29
+ * mounted join file (afresh each time: a reset writes a new one), and the id the harness keeps on
30
+ * the volume (`/harness/volume-id`), so a volume recreated empty is told apart.
31
+ */
32
+ export declare const HostJoinRequestSchema: z.ZodObject<{
33
+ sandboxId: z.ZodString;
34
+ podUid: z.ZodString;
35
+ joinToken: z.ZodString;
36
+ volumeId: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ export type HostJoinRequest = z.infer<typeof HostJoinRequestSchema>;
39
+ /**
40
+ * What `host/join` and `host/renew` answer. The host token is the WebSocket bearer; the egress
41
+ * token is the password of the egress proxy every command the harness runs must use
42
+ * (`NYLORUN_EGRESS_PROXY`); `caCertificate` is the egress CA (PEM), which the harness adds to the
43
+ * trust bundle of those commands. Both tokens expire at `expiresAt`.
44
+ */
45
+ export declare const HostJoinAnswerSchema: z.ZodObject<{
46
+ hostToken: z.ZodString;
47
+ egressToken: z.ZodString;
48
+ sandboxId: z.ZodString;
49
+ epoch: z.ZodNumber;
50
+ expiresAt: z.ZodString;
51
+ caCertificate: z.ZodString;
52
+ setup: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ seeded: z.ZodOptional<z.ZodLiteral<true>>;
54
+ }, z.core.$strict>;
55
+ export type HostJoinAnswer = z.infer<typeof HostJoinAnswerSchema>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * How a harness reaches core (R4.5). Three version numbers apply, and each moves on its own:
3
+ *
4
+ * - the transport: path `/nylorun/harness/v1` and header `Nylorun-Harness-Api: 1`, for the
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
7
+ * checks;
8
+ * - the Runtime's protocol, which the Runtime and Management APIs carry, never this one.
9
+ *
10
+ * A harness container connects with `Authorization: Bearer <harness token>`. The harness in a
11
+ * pod sandbox holds no harness token: it exchanges the join token mounted in its pod for a host
12
+ * token (`POST .../host/join`), renews it (`POST .../host/renew`, `Authorization: Bearer <host
13
+ * token>`) every few minutes, and connects with the host token as its bearer. That connection
14
+ * serves its sandbox alone. Every refused join or renewal is the same `401`.
15
+ */
16
+ import { z } from "zod";
17
+ /** The URL path of the Harness API's WebSocket, on core's harness port (4200 by default). */
18
+ export const HARNESS_API_PATH = "/nylorun/harness/v1";
19
+ /** The upgrade header naming the transport version, and the only value accepted. */
20
+ export const HARNESS_API_HEADER = "nylorun-harness-api";
21
+ export const HARNESS_API_TRANSPORT = "1";
22
+ /** Largest frame either end accepts. */
23
+ export const HARNESS_MAX_PAYLOAD = 64 * 1024 * 1024;
24
+ /** Where a pod's harness exchanges its join token, and renews its host token. */
25
+ export const HOST_JOIN_PATH = `${HARNESS_API_PATH}/host/join`;
26
+ export const HOST_RENEW_PATH = `${HARNESS_API_PATH}/host/renew`;
27
+ /**
28
+ * A pod's join: its sandbox (`NYLORUN_SANDBOX_ID`), its pod's UID, the join token read from the
29
+ * mounted join file (afresh each time: a reset writes a new one), and the id the harness keeps on
30
+ * the volume (`/harness/volume-id`), so a volume recreated empty is told apart.
31
+ */
32
+ export const HostJoinRequestSchema = z.strictObject({
33
+ sandboxId: z.string().min(1),
34
+ podUid: z.string().regex(/^[A-Za-z0-9-]{1,64}$/),
35
+ joinToken: z.string().min(1).max(512),
36
+ volumeId: z
37
+ .string()
38
+ .regex(/^[A-Za-z0-9-]{1,64}$/)
39
+ .optional(),
40
+ });
41
+ /**
42
+ * What `host/join` and `host/renew` answer. The host token is the WebSocket bearer; the egress
43
+ * token is the password of the egress proxy every command the harness runs must use
44
+ * (`NYLORUN_EGRESS_PROXY`); `caCertificate` is the egress CA (PEM), which the harness adds to the
45
+ * trust bundle of those commands. Both tokens expire at `expiresAt`.
46
+ */
47
+ export const HostJoinAnswerSchema = z.strictObject({
48
+ hostToken: z.string(),
49
+ egressToken: z.string(),
50
+ sandboxId: z.string(),
51
+ epoch: z.number().int(),
52
+ expiresAt: z.string(),
53
+ caCertificate: z.string(),
54
+ /**
55
+ * Join only: what our engine copies and runs on a new disk before it takes turns (the
56
+ * Environment's `files` and `setup`). A custom harness runs them itself, or ignores them.
57
+ */
58
+ setup: z.record(z.string(), z.unknown()).optional(),
59
+ /** Join only: the new volume starts from a disk version, so there is no setup to run. */
60
+ seeded: z.literal(true).optional(),
61
+ });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./contracts.js";
2
- export type * from "./types/middleware.js";
2
+ export type * from "./types/part.js";
3
3
  export type * from "./types/tool.js";
4
4
  export type * from "./types/agent.js";
5
5
  export type * from "./types/observe.js";
@@ -0,0 +1,6 @@
1
+ /** The agent manifest version these documents describe. */
2
+ export declare const AGENT_MANIFEST_SCHEMA_VERSION = 7;
3
+ /** The environment manifest's JSON Schema document (draft 2020-12). */
4
+ export declare function environmentManifestJsonSchema(): Record<string, unknown>;
5
+ /** The agent manifest's JSON Schema document (draft 2020-12). */
6
+ export declare function agentManifestJsonSchema(): Record<string, unknown>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The agent manifest and the environment manifest as JSON Schema documents (protocol 14, D63),
3
+ * generated from the zod schemas the Runtime validates with, so an editor checks a manifest file
4
+ * from its `$schema` and a client in another language validates what core enforces. The build
5
+ * writes them to `dist/schemas/` (`@nylorun/core/schemas/agent-manifest.json` and
6
+ * `@nylorun/core/schemas/environment-manifest.json`). Both allow a top-level `$schema`, which
7
+ * the CLI and SDK drop before they save: the Runtime's own schemas stay strict.
8
+ */
9
+ import { z } from "zod";
10
+ import { AgentManifestSchema, ENVIRONMENT_MANIFEST_SCHEMA_VERSION, EnvironmentManifestSchema, } from "./contracts.js";
11
+ /** The agent manifest version these documents describe. */
12
+ export const AGENT_MANIFEST_SCHEMA_VERSION = 7;
13
+ function document(schema, id, title) {
14
+ const { $schema: _, ...definition } = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
15
+ const properties = (definition.properties ?? {});
16
+ return {
17
+ $schema: "https://json-schema.org/draft/2020-12/schema",
18
+ $id: `https://docs.nylorun.com/schemas/${id}.json`,
19
+ title,
20
+ ...definition,
21
+ properties: {
22
+ $schema: { type: "string", description: "This document's JSON Schema, for editors; clients drop it before saving" },
23
+ ...properties,
24
+ },
25
+ };
26
+ }
27
+ /** The environment manifest's JSON Schema document (draft 2020-12). */
28
+ export function environmentManifestJsonSchema() {
29
+ return document(EnvironmentManifestSchema, `environment-manifest/v${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`, `Nylorun environment manifest ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`);
30
+ }
31
+ /** The agent manifest's JSON Schema document (draft 2020-12). */
32
+ export function agentManifestJsonSchema() {
33
+ return document(AgentManifestSchema, `agent-manifest/v${AGENT_MANIFEST_SCHEMA_VERSION}`, `Nylorun agent manifest ${AGENT_MANIFEST_SCHEMA_VERSION}`);
34
+ }