@nylorun/core 0.48.0-beta → 0.50.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.50.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - 9f17705: The event log is for developers, telemetry for operators (ADR-159). Each event type in the catalog names its layer: `agent`, what the agent saw and did, or `runtime`, what the Runtime did to the session. `eventLayer(type)` and `EVENT_LAYERS` are exported from `@nylorun/core/contracts` and `@nylorun/agents`, with the `TurnTrace` and `OtlpSpan` types; the envelope does not change. Studio's Events tab opens on the agent's events, with Runtime and All beside them and each row's writer, and gains a Trace view: a turn's spans as a waterfall, from the per-turn trace route, with Open trace on an event and Open event on a span. Studio's proxy allows a session's tool calls and a turn's trace. `guides/OBSERVABILITY.md` is the guide for both readers.
8
+ - 2b80f71: A Tenant stream with an audit read (ADR-159, Host feature `tenant-audit`). Keys put and deleted (`key.created`, `key.revoked`), signing keys rotated and revoked (`signing_key.rotated`, `signing_key.revoked`), the tool policy and every other setting changed (`policy.changed` with the rule count, `settings.changed` with the setting's key), vault credentials written, replaced, deleted and used (`credential.created`, `.rotated`, `.deleted`, `.used`, beside the `vault_audit` rows, which are still written) and Studio sign-ins (`studio.signed_in`) are recorded in `nylorun_streams.tenant_events` (migration `0050_tenant_events`), each in the transaction of the change it records, with who acted (`principal`, from the request's credential) and what wrote it (`source`), and never a secret value: every payload is strict. The stream is not relayed to S2 and a reset keeps it. `TENANT_EVENT_TYPES`, `TENANT_EVENT_PAYLOADS`, `TenantEventSchema` and `TenantAuditPageSchema` are in `@nylorun/core/contracts`.
9
+
10
+ The Management API reads it newest first with `GET /v1/tenant/audit?since&until&types&cursor&limit`, a management key only; `POST /v1/tenant/audit/studio-sign-in` takes only Studio's key. `@nylorun/admin` adds `tenant.audit({ since, until, types, cursor, limit })` and exports the Tenant event types. Studio records each sign-in (`token`, `forwarded`, and `loopback` at most hourly) in the background, so a failure never blocks one, and adds a Tenant › Audit tab: time, type, who and a one-line summary, with a type filter and Load more. Its proxy allows the read and nothing else under the audit. `guides/OBSERVABILITY.md` has an Audit part for operators.
11
+
12
+ ## 0.49.0-beta
13
+
14
+ ### Minor Changes
15
+
16
+ - d688ce5: An Agent sets when its sessions compact (ADR-157): `harness.loop.compaction` (`loop.compaction` in `AGENT.md`) takes `threshold` and `keepTokens`, positive whole numbers of tokens, and `roles.<role>` over them for sessions opened with that role. Our harness compacts before a model call whose estimate passes the lower of `threshold` and the model's window minus the reply reserve, and keeps `keepTokens` word for word; unset, sessions compact as before. A value that is not a positive integer is ignored with an `engine.diagnostic` (`compaction_setting_ignored`), and the folder compiler refuses it. `turn.start` names the session's role (`role`) to our harness.
17
+
18
+ An `agent-folder/3` folder may now set `loop` for the harness's own settings, such as `compaction`; only `loop.plan`, `loop.connections` and `loop.ask`, which its plugins declare, are refused. `nylorun migrate folder --to 3` keeps those settings.
19
+
20
+ - d688ce5: A message's context (ADR-157, Host feature `message-context`): a message takes `context`, up to 16 items `{ type?, value }` and 16 KiB in all, facts for its own turn only. The Runtime keeps them on `command.message` and passes them to the turn as its input's `metadata.context`; our harness renders the turn's latest ones in the `<runtime-context>` block after the history on every model call of that turn, and later turns leave them out. A workflow session refuses them. `session.input(value, { context })` and `session.inputParts(parts, { context })` send them, and refuse before sending when the Runtime lacks the feature.
21
+
3
22
  ## 0.48.0-beta
4
23
 
5
24
  ### Minor Changes
@@ -251,6 +251,20 @@ export declare const OPTIONAL_HOST_FEATURES: readonly ["tenant-fixture-model", "
251
251
  * always sends it still moves to new versions.
252
252
  */
253
253
  "remove-tools",
254
+ /**
255
+ * A message's `context` (ADR-157): up to 16 items `{type?, value}` for its own turn. Our engine puts
256
+ * them in the `<runtime-context>` block of every model call of that turn, after the history, and
257
+ * later turns leave them out; `command.message` keeps them. Our harness also reads
258
+ * `harness.loop.compaction` (`threshold`, `keepTokens`, per role), with the session's role in
259
+ * `turn.start`.
260
+ */
261
+ "message-context",
262
+ /**
263
+ * The Tenant's stream (ADR-159): `GET /v1/tenant/audit` (the Management API) pages, newest first,
264
+ * the keys put and deleted, signing keys rotated and revoked, tool policy and settings changes,
265
+ * vault credentials written and used, and Studio sign-ins, each with who did it and no secret.
266
+ */
267
+ "tenant-audit",
254
268
  /**
255
269
  * The triggers capability (D83): an agent whose version declares `harness.engine.triggers` sets
256
270
  * up its own triggers with the `triggers` tool, kept by the Agent (`origin: agent` in
@@ -273,6 +273,20 @@ export const OPTIONAL_HOST_FEATURES = [
273
273
  * always sends it still moves to new versions.
274
274
  */
275
275
  "remove-tools",
276
+ /**
277
+ * A message's `context` (ADR-157): up to 16 items `{type?, value}` for its own turn. Our engine puts
278
+ * them in the `<runtime-context>` block of every model call of that turn, after the history, and
279
+ * later turns leave them out; `command.message` keeps them. Our harness also reads
280
+ * `harness.loop.compaction` (`threshold`, `keepTokens`, per role), with the session's role in
281
+ * `turn.start`.
282
+ */
283
+ "message-context",
284
+ /**
285
+ * The Tenant's stream (ADR-159): `GET /v1/tenant/audit` (the Management API) pages, newest first,
286
+ * the keys put and deleted, signing keys rotated and revoked, tool policy and settings changes,
287
+ * vault credentials written and used, and Studio sign-ins, each with who did it and no secret.
288
+ */
289
+ "tenant-audit",
276
290
  /**
277
291
  * The triggers capability (D83): an agent whose version declares `harness.engine.triggers` sets
278
292
  * up its own triggers with the `triggers` tool, kept by the Agent (`origin: agent` in
@@ -1076,6 +1076,192 @@ export declare const ListAgentEventsResponseSchema: z.ZodObject<{
1076
1076
  payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1077
1077
  }, z.core.$strict>>;
1078
1078
  }, z.core.$strict>;
1079
+ /** The schema id of the Tenant's events (its stream in the record, ADR-159). */
1080
+ export declare const TENANT_EVENT_SCHEMA = "nylorun.tenant-event/1";
1081
+ /**
1082
+ * The Tenant's stream (ADR-159, Host feature `tenant-audit`): who changed who may reach the Tenant
1083
+ * and what its sessions may do, and each use of a vault credential, read with
1084
+ * `GET /v1/tenant/audit`. Every type is the Runtime's record (layer `runtime`): the Runtime saw it
1085
+ * happen, in the change's own transaction where it could; no harness writes one. No payload carries
1086
+ * a secret value: keys, signing keys, rules and credentials are named, never shown.
1087
+ */
1088
+ export declare const TENANT_EVENT_TYPES: readonly ["key.created", "key.revoked", "signing_key.rotated", "signing_key.revoked", "policy.changed", "settings.changed", "credential.created", "credential.rotated", "credential.deleted", "credential.used", "studio.signed_in"];
1089
+ export type TenantEventType = (typeof TENANT_EVENT_TYPES)[number];
1090
+ /**
1091
+ * What wrote a Tenant event: `api`, a request to the Runtime or Management API; `operate`,
1092
+ * `nylorun-operate` on the Tenant's machine; `runtime`, the Runtime on its own (a gate using a
1093
+ * credential, a sweep deleting an Agent); `studio`, Studio's server, for a sign-in.
1094
+ */
1095
+ export declare const TENANT_EVENT_SOURCES: readonly ["api", "operate", "runtime", "studio"];
1096
+ export type TenantEventSource = (typeof TENANT_EVENT_SOURCES)[number];
1097
+ /** How a person signed in to Studio: on its loopback address, with a login token, or through a sign-in proxy. */
1098
+ export declare const STUDIO_SIGN_IN_METHODS: readonly ["loopback", "token", "forwarded"];
1099
+ export type StudioSignInMethod = (typeof STUDIO_SIGN_IN_METHODS)[number];
1100
+ /**
1101
+ * The payload of each Tenant event. Each is strict, so a write that carries anything else, a
1102
+ * secret above all, is refused.
1103
+ */
1104
+ export declare const TENANT_EVENT_PAYLOADS: {
1105
+ /** Key `keyId` was issued; `rotated` when it replaced a key of that name. */
1106
+ readonly "key.created": z.ZodObject<{
1107
+ keyId: z.ZodString;
1108
+ role: z.ZodEnum<{
1109
+ application: "application";
1110
+ management: "management";
1111
+ }>;
1112
+ rotated: z.ZodBoolean;
1113
+ }, z.core.$strict>;
1114
+ readonly "key.revoked": z.ZodObject<{
1115
+ keyId: z.ZodString;
1116
+ role: z.ZodEnum<{
1117
+ application: "application";
1118
+ management: "management";
1119
+ }>;
1120
+ }, z.core.$strict>;
1121
+ /** The standby key became `current`; the old current one `previous`, the old previous one `revoked`. */
1122
+ readonly "signing_key.rotated": z.ZodObject<{
1123
+ current: z.ZodString;
1124
+ standby: z.ZodString;
1125
+ previous: z.ZodOptional<z.ZodString>;
1126
+ revoked: z.ZodOptional<z.ZodString>;
1127
+ force: z.ZodBoolean;
1128
+ }, z.core.$strict>;
1129
+ /** Key `keyId` was revoked from `state`. */
1130
+ readonly "signing_key.revoked": z.ZodObject<{
1131
+ keyId: z.ZodString;
1132
+ state: z.ZodEnum<{
1133
+ previous: "previous";
1134
+ standby: "standby";
1135
+ }>;
1136
+ }, z.core.$strict>;
1137
+ /** The tool policy now holds `rules` rules, as of `updatedAt`; the rules are read from `GET /v1/tenant/tool-policy`. */
1138
+ readonly "policy.changed": z.ZodObject<{
1139
+ rules: z.ZodNumber;
1140
+ updatedAt: z.ZodString;
1141
+ }, z.core.$strict>;
1142
+ /**
1143
+ * Setting `key` was replaced: `limits.config`, `environments.config`, `artifacts.config`,
1144
+ * `skills.config`, `model.budgets`, `model.inputs` or `model` (the provider and model in force,
1145
+ * `provider` and `model`; `model.inputs` names the catalog model in `model`). Never its value.
1146
+ */
1147
+ readonly "settings.changed": z.ZodObject<{
1148
+ key: z.ZodString;
1149
+ provider: z.ZodOptional<z.ZodString>;
1150
+ model: z.ZodOptional<z.ZodString>;
1151
+ }, z.core.$strict>;
1152
+ readonly "credential.created": z.ZodObject<{
1153
+ vaultId: z.ZodOptional<z.ZodString>;
1154
+ credentialId: z.ZodOptional<z.ZodString>;
1155
+ sessionId: z.ZodOptional<z.ZodString>;
1156
+ target: z.ZodOptional<z.ZodString>;
1157
+ outcome: z.ZodString;
1158
+ }, z.core.$strict>;
1159
+ readonly "credential.rotated": z.ZodObject<{
1160
+ vaultId: z.ZodOptional<z.ZodString>;
1161
+ credentialId: z.ZodOptional<z.ZodString>;
1162
+ sessionId: z.ZodOptional<z.ZodString>;
1163
+ target: z.ZodOptional<z.ZodString>;
1164
+ outcome: z.ZodString;
1165
+ }, z.core.$strict>;
1166
+ readonly "credential.deleted": z.ZodObject<{
1167
+ vaultId: z.ZodOptional<z.ZodString>;
1168
+ credentialId: z.ZodOptional<z.ZodString>;
1169
+ sessionId: z.ZodOptional<z.ZodString>;
1170
+ target: z.ZodOptional<z.ZodString>;
1171
+ outcome: z.ZodString;
1172
+ }, z.core.$strict>;
1173
+ readonly "credential.used": z.ZodObject<{
1174
+ vaultId: z.ZodOptional<z.ZodString>;
1175
+ credentialId: z.ZodOptional<z.ZodString>;
1176
+ sessionId: z.ZodOptional<z.ZodString>;
1177
+ target: z.ZodOptional<z.ZodString>;
1178
+ outcome: z.ZodString;
1179
+ }, z.core.$strict>;
1180
+ /** A browser signed in to Studio, by `method`, as `subject` when it names a person. */
1181
+ readonly "studio.signed_in": z.ZodObject<{
1182
+ method: z.ZodEnum<{
1183
+ forwarded: "forwarded";
1184
+ loopback: "loopback";
1185
+ token: "token";
1186
+ }>;
1187
+ subject: z.ZodOptional<z.ZodString>;
1188
+ }, z.core.$strict>;
1189
+ };
1190
+ export type TenantEventPayload<T extends TenantEventType> = z.infer<(typeof TENANT_EVENT_PAYLOADS)[T]>;
1191
+ /**
1192
+ * One event on the Tenant's stream, numbered from 0. `principal` is who acted, from the request's
1193
+ * credential: a key's name (`bootstrap`, `studio`, an application key's), `<key>:<subject>` for a
1194
+ * key acting for a person, `<issuer>:<subject>` for a token, `operate` for `nylorun-operate`,
1195
+ * and `host` for the Runtime itself.
1196
+ */
1197
+ export declare const TenantEventSchema: z.ZodObject<{
1198
+ schema: z.ZodLiteral<"nylorun.tenant-event/1">;
1199
+ seq: z.ZodNumber;
1200
+ time: z.ZodString;
1201
+ type: z.ZodEnum<{
1202
+ "credential.created": "credential.created";
1203
+ "credential.deleted": "credential.deleted";
1204
+ "credential.rotated": "credential.rotated";
1205
+ "credential.used": "credential.used";
1206
+ "key.created": "key.created";
1207
+ "key.revoked": "key.revoked";
1208
+ "policy.changed": "policy.changed";
1209
+ "settings.changed": "settings.changed";
1210
+ "signing_key.revoked": "signing_key.revoked";
1211
+ "signing_key.rotated": "signing_key.rotated";
1212
+ "studio.signed_in": "studio.signed_in";
1213
+ }>;
1214
+ source: z.ZodEnum<{
1215
+ api: "api";
1216
+ operate: "operate";
1217
+ runtime: "runtime";
1218
+ studio: "studio";
1219
+ }>;
1220
+ principal: z.ZodString;
1221
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1222
+ }, z.core.$strict>;
1223
+ export type TenantEvent = z.infer<typeof TenantEventSchema>;
1224
+ /** A page of the Tenant's events, newest first; `nextCursor` reads older ones. */
1225
+ export declare const TenantAuditPageSchema: z.ZodObject<{
1226
+ events: z.ZodArray<z.ZodObject<{
1227
+ schema: z.ZodLiteral<"nylorun.tenant-event/1">;
1228
+ seq: z.ZodNumber;
1229
+ time: z.ZodString;
1230
+ type: z.ZodEnum<{
1231
+ "credential.created": "credential.created";
1232
+ "credential.deleted": "credential.deleted";
1233
+ "credential.rotated": "credential.rotated";
1234
+ "credential.used": "credential.used";
1235
+ "key.created": "key.created";
1236
+ "key.revoked": "key.revoked";
1237
+ "policy.changed": "policy.changed";
1238
+ "settings.changed": "settings.changed";
1239
+ "signing_key.revoked": "signing_key.revoked";
1240
+ "signing_key.rotated": "signing_key.rotated";
1241
+ "studio.signed_in": "studio.signed_in";
1242
+ }>;
1243
+ source: z.ZodEnum<{
1244
+ api: "api";
1245
+ operate: "operate";
1246
+ runtime: "runtime";
1247
+ studio: "studio";
1248
+ }>;
1249
+ principal: z.ZodString;
1250
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1251
+ }, z.core.$strict>>;
1252
+ nextCursor: z.ZodNullable<z.ZodString>;
1253
+ }, z.core.$strict>;
1254
+ export type TenantAuditPage = z.infer<typeof TenantAuditPageSchema>;
1255
+ /** `POST /v1/tenant/audit/studio-sign-in`: how a person signed in to Studio, and who when known. */
1256
+ export declare const StudioSignInRequestSchema: z.ZodObject<{
1257
+ method: z.ZodEnum<{
1258
+ forwarded: "forwarded";
1259
+ loopback: "loopback";
1260
+ token: "token";
1261
+ }>;
1262
+ subject: z.ZodOptional<z.ZodString>;
1263
+ }, z.core.$strict>;
1264
+ export type StudioSignInRequest = z.infer<typeof StudioSignInRequestSchema>;
1079
1265
  /**
1080
1266
  * A model role's name (Host feature `model-roles`, ADR-154): a lowercase letter, then up to 31
1081
1267
  * lowercase letters, digits and `-`, such as `builder`.
@@ -4322,6 +4508,21 @@ export type MessageDelivery = z.infer<typeof MessageDeliverySchema>;
4322
4508
  * only narrows.
4323
4509
  */
4324
4510
  export declare const RemoveToolsSchema: z.ZodArray<z.ZodString>;
4511
+ /** The most context items one message carries (ADR-157). */
4512
+ export declare const MESSAGE_CONTEXT_MAX_ITEMS = 16;
4513
+ /** The most bytes a message's context items take, as JSON (ADR-157). */
4514
+ export declare const MESSAGE_CONTEXT_MAX_BYTES: number;
4515
+ /**
4516
+ * A message's `context` (Host feature `message-context`, ADR-157): facts for its own turn only,
4517
+ * such as the time or who the agent is today. Our engine puts them in the `<runtime-context>` block
4518
+ * of every model call of that turn, after the history; later turns leave them out. The
4519
+ * `command.message` event keeps them.
4520
+ */
4521
+ export declare const MessageContextSchema: z.ZodArray<z.ZodObject<{
4522
+ type: z.ZodOptional<z.ZodString>;
4523
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4524
+ }, z.core.$strict>>;
4525
+ export type MessageContextItem = z.infer<typeof MessageContextSchema>[number];
4325
4526
  /**
4326
4527
  * One part of a user message (protocol 6): text, or a file by artifact id. A file part without
4327
4528
  * `version` means the artifact's latest version when the message is accepted; the Runtime pins
@@ -4351,6 +4552,10 @@ export declare const MessageEventBodySchema: z.ZodUnion<readonly [z.ZodObject<{
4351
4552
  reject: "reject";
4352
4553
  steer: "steer";
4353
4554
  }>>;
4555
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4556
+ type: z.ZodOptional<z.ZodString>;
4557
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4558
+ }, z.core.$strict>>>;
4354
4559
  content: z.ZodString;
4355
4560
  }, z.core.$strict>, z.ZodObject<{
4356
4561
  requestId: z.ZodString;
@@ -4363,6 +4568,10 @@ export declare const MessageEventBodySchema: z.ZodUnion<readonly [z.ZodObject<{
4363
4568
  reject: "reject";
4364
4569
  steer: "steer";
4365
4570
  }>>;
4571
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4572
+ type: z.ZodOptional<z.ZodString>;
4573
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4574
+ }, z.core.$strict>>>;
4366
4575
  data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4367
4576
  }, z.core.$strict>, z.ZodObject<{
4368
4577
  requestId: z.ZodString;
@@ -4375,6 +4584,10 @@ export declare const MessageEventBodySchema: z.ZodUnion<readonly [z.ZodObject<{
4375
4584
  reject: "reject";
4376
4585
  steer: "steer";
4377
4586
  }>>;
4587
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4588
+ type: z.ZodOptional<z.ZodString>;
4589
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4590
+ }, z.core.$strict>>>;
4378
4591
  parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
4379
4592
  type: z.ZodLiteral<"text">;
4380
4593
  text: z.ZodString;
@@ -4401,6 +4614,10 @@ export declare const SessionCommandSchema: z.ZodUnion<readonly [z.ZodUnion<reado
4401
4614
  reject: "reject";
4402
4615
  steer: "steer";
4403
4616
  }>>;
4617
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4618
+ type: z.ZodOptional<z.ZodString>;
4619
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4620
+ }, z.core.$strict>>>;
4404
4621
  content: z.ZodString;
4405
4622
  }, z.core.$strict>, z.ZodObject<{
4406
4623
  requestId: z.ZodString;
@@ -4413,6 +4630,10 @@ export declare const SessionCommandSchema: z.ZodUnion<readonly [z.ZodUnion<reado
4413
4630
  reject: "reject";
4414
4631
  steer: "steer";
4415
4632
  }>>;
4633
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4634
+ type: z.ZodOptional<z.ZodString>;
4635
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4636
+ }, z.core.$strict>>>;
4416
4637
  data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4417
4638
  }, z.core.$strict>, z.ZodObject<{
4418
4639
  requestId: z.ZodString;
@@ -4425,6 +4646,10 @@ export declare const SessionCommandSchema: z.ZodUnion<readonly [z.ZodUnion<reado
4425
4646
  reject: "reject";
4426
4647
  steer: "steer";
4427
4648
  }>>;
4649
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4650
+ type: z.ZodOptional<z.ZodString>;
4651
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4652
+ }, z.core.$strict>>>;
4428
4653
  parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
4429
4654
  type: z.ZodLiteral<"text">;
4430
4655
  text: z.ZodString;
@@ -4462,6 +4687,10 @@ export declare const SessionEventBodySchema: z.ZodUnion<readonly [z.ZodUnion<rea
4462
4687
  reject: "reject";
4463
4688
  steer: "steer";
4464
4689
  }>>;
4690
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4691
+ type: z.ZodOptional<z.ZodString>;
4692
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4693
+ }, z.core.$strict>>>;
4465
4694
  content: z.ZodString;
4466
4695
  }, z.core.$strict>, z.ZodObject<{
4467
4696
  requestId: z.ZodString;
@@ -4474,6 +4703,10 @@ export declare const SessionEventBodySchema: z.ZodUnion<readonly [z.ZodUnion<rea
4474
4703
  reject: "reject";
4475
4704
  steer: "steer";
4476
4705
  }>>;
4706
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4707
+ type: z.ZodOptional<z.ZodString>;
4708
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4709
+ }, z.core.$strict>>>;
4477
4710
  data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4478
4711
  }, z.core.$strict>, z.ZodObject<{
4479
4712
  requestId: z.ZodString;
@@ -4486,6 +4719,10 @@ export declare const SessionEventBodySchema: z.ZodUnion<readonly [z.ZodUnion<rea
4486
4719
  reject: "reject";
4487
4720
  steer: "steer";
4488
4721
  }>>;
4722
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
4723
+ type: z.ZodOptional<z.ZodString>;
4724
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
4725
+ }, z.core.$strict>>>;
4489
4726
  parts: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
4490
4727
  type: z.ZodLiteral<"text">;
4491
4728
  text: z.ZodString;
@@ -4543,6 +4780,12 @@ export declare const EventSourceKindSchema: z.ZodEnum<{
4543
4780
  "tool-gate": "tool-gate";
4544
4781
  }>;
4545
4782
  export type EventSourceKind = z.infer<typeof EventSourceKindSchema>;
4783
+ /**
4784
+ * Whose account an event is: the agent's or the Runtime's (ADR-159). A session's events have one each
4785
+ * (`EVENT_CATALOG`); every event on an Agent's stream (`AGENT_EVENT_TYPES`) is the Runtime's.
4786
+ */
4787
+ export declare const EVENT_LAYERS: readonly ["agent", "runtime"];
4788
+ export type EventLayer = (typeof EVENT_LAYERS)[number];
4546
4789
  /**
4547
4790
  * How far an event can be trusted, by who could forge it. `observed`: the Runtime saw it itself
4548
4791
  * (commands, the tools core serves, gate records, core's settle). `claimed`: a harness reported
@@ -5508,6 +5751,10 @@ export declare const CommandMessagePayloadSchema: z.ZodObject<{
5508
5751
  }, z.core.$strict>], "type">>>;
5509
5752
  manifest: z.ZodOptional<z.ZodUnknown>;
5510
5753
  removeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
5754
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
5755
+ type: z.ZodOptional<z.ZodString>;
5756
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
5757
+ }, z.core.$strict>>>;
5511
5758
  delivery: z.ZodOptional<z.ZodEnum<{
5512
5759
  queue: "queue";
5513
5760
  reject: "reject";
@@ -5946,6 +6193,10 @@ export declare const EVENT_CATALOG: {
5946
6193
  }, z.core.$strict>], "type">>>;
5947
6194
  manifest: z.ZodOptional<z.ZodUnknown>;
5948
6195
  removeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
6196
+ context: z.ZodOptional<z.ZodArray<z.ZodObject<{
6197
+ type: z.ZodOptional<z.ZodString>;
6198
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
6199
+ }, z.core.$strict>>>;
5949
6200
  delivery: z.ZodOptional<z.ZodEnum<{
5950
6201
  queue: "queue";
5951
6202
  reject: "reject";
@@ -5967,6 +6218,7 @@ export declare const EVENT_CATALOG: {
5967
6218
  }, z.core.$loose>;
5968
6219
  readonly source: "api";
5969
6220
  readonly version: 1;
6221
+ readonly layer: "agent";
5970
6222
  };
5971
6223
  readonly "command.approve": {
5972
6224
  readonly payload: z.ZodObject<{
@@ -5978,6 +6230,7 @@ export declare const EVENT_CATALOG: {
5978
6230
  }, z.core.$loose>;
5979
6231
  readonly source: "api";
5980
6232
  readonly version: 1;
6233
+ readonly layer: "agent";
5981
6234
  };
5982
6235
  readonly "command.respond": {
5983
6236
  readonly payload: z.ZodObject<{
@@ -5989,6 +6242,7 @@ export declare const EVENT_CATALOG: {
5989
6242
  }, z.core.$loose>;
5990
6243
  readonly source: "api";
5991
6244
  readonly version: 1;
6245
+ readonly layer: "agent";
5992
6246
  };
5993
6247
  readonly "turn.completed": {
5994
6248
  readonly payload: z.ZodObject<{
@@ -6008,6 +6262,7 @@ export declare const EVENT_CATALOG: {
6008
6262
  }, z.core.$loose>;
6009
6263
  readonly source: "loop";
6010
6264
  readonly version: 1;
6265
+ readonly layer: "agent";
6011
6266
  };
6012
6267
  readonly "turn.paused": {
6013
6268
  readonly payload: z.ZodObject<{
@@ -6023,6 +6278,7 @@ export declare const EVENT_CATALOG: {
6023
6278
  }, z.core.$loose>;
6024
6279
  readonly source: "loop";
6025
6280
  readonly version: 1;
6281
+ readonly layer: "agent";
6026
6282
  };
6027
6283
  readonly "turn.failed": {
6028
6284
  readonly payload: z.ZodObject<{
@@ -6046,6 +6302,7 @@ export declare const EVENT_CATALOG: {
6046
6302
  }, z.core.$loose>;
6047
6303
  readonly source: "loop";
6048
6304
  readonly version: 1;
6305
+ readonly layer: "agent";
6049
6306
  };
6050
6307
  readonly "turn.cancelled": {
6051
6308
  readonly payload: z.ZodObject<{
@@ -6065,6 +6322,7 @@ export declare const EVENT_CATALOG: {
6065
6322
  }, z.core.$loose>;
6066
6323
  readonly source: "api";
6067
6324
  readonly version: 1;
6325
+ readonly layer: "agent";
6068
6326
  };
6069
6327
  readonly "turn.version_kept": {
6070
6328
  readonly payload: z.ZodObject<{
@@ -6083,6 +6341,7 @@ export declare const EVENT_CATALOG: {
6083
6341
  }, z.core.$loose>;
6084
6342
  readonly source: "api";
6085
6343
  readonly version: 1;
6344
+ readonly layer: "runtime";
6086
6345
  };
6087
6346
  readonly "session.model": {
6088
6347
  readonly payload: z.ZodObject<{
@@ -6137,6 +6396,7 @@ export declare const EVENT_CATALOG: {
6137
6396
  }, z.core.$loose>;
6138
6397
  readonly source: "api";
6139
6398
  readonly version: 1;
6399
+ readonly layer: "runtime";
6140
6400
  };
6141
6401
  readonly "message.queued": {
6142
6402
  readonly payload: z.ZodObject<{
@@ -6150,6 +6410,7 @@ export declare const EVENT_CATALOG: {
6150
6410
  }, z.core.$loose>;
6151
6411
  readonly source: "api";
6152
6412
  readonly version: 1;
6413
+ readonly layer: "runtime";
6153
6414
  };
6154
6415
  readonly "queue.taken": {
6155
6416
  readonly payload: z.ZodObject<{
@@ -6159,6 +6420,7 @@ export declare const EVENT_CATALOG: {
6159
6420
  }, z.core.$loose>;
6160
6421
  readonly source: "api";
6161
6422
  readonly version: 1;
6423
+ readonly layer: "runtime";
6162
6424
  };
6163
6425
  readonly "queue.failed": {
6164
6426
  readonly payload: z.ZodObject<{
@@ -6171,6 +6433,7 @@ export declare const EVENT_CATALOG: {
6171
6433
  }, z.core.$loose>;
6172
6434
  readonly source: "api";
6173
6435
  readonly version: 1;
6436
+ readonly layer: "runtime";
6174
6437
  };
6175
6438
  readonly "queue.cancelled": {
6176
6439
  readonly payload: z.ZodObject<{
@@ -6179,6 +6442,7 @@ export declare const EVENT_CATALOG: {
6179
6442
  }, z.core.$loose>;
6180
6443
  readonly source: "api";
6181
6444
  readonly version: 1;
6445
+ readonly layer: "runtime";
6182
6446
  };
6183
6447
  readonly "wake.booked": {
6184
6448
  readonly payload: z.ZodObject<{
@@ -6189,6 +6453,7 @@ export declare const EVENT_CATALOG: {
6189
6453
  }, z.core.$loose>;
6190
6454
  readonly source: "api";
6191
6455
  readonly version: 1;
6456
+ readonly layer: "runtime";
6192
6457
  };
6193
6458
  readonly "wake.cancelled": {
6194
6459
  readonly payload: z.ZodObject<{
@@ -6196,6 +6461,7 @@ export declare const EVENT_CATALOG: {
6196
6461
  }, z.core.$loose>;
6197
6462
  readonly source: "api";
6198
6463
  readonly version: 1;
6464
+ readonly layer: "runtime";
6199
6465
  };
6200
6466
  readonly "memory.updated": {
6201
6467
  readonly payload: z.ZodObject<{
@@ -6214,6 +6480,7 @@ export declare const EVENT_CATALOG: {
6214
6480
  }, z.core.$loose>;
6215
6481
  readonly source: "api";
6216
6482
  readonly version: 1;
6483
+ readonly layer: "agent";
6217
6484
  };
6218
6485
  readonly "message.assistant": {
6219
6486
  readonly payload: z.ZodObject<{
@@ -6258,6 +6525,7 @@ export declare const EVENT_CATALOG: {
6258
6525
  }, z.core.$loose>;
6259
6526
  readonly source: "loop";
6260
6527
  readonly version: 1;
6528
+ readonly layer: "agent";
6261
6529
  };
6262
6530
  readonly "model.failed": {
6263
6531
  readonly payload: z.ZodObject<{
@@ -6293,6 +6561,7 @@ export declare const EVENT_CATALOG: {
6293
6561
  }, z.core.$loose>;
6294
6562
  readonly source: "loop";
6295
6563
  readonly version: 1;
6564
+ readonly layer: "agent";
6296
6565
  };
6297
6566
  readonly "context.compacted": {
6298
6567
  readonly payload: z.ZodObject<{
@@ -6331,6 +6600,7 @@ export declare const EVENT_CATALOG: {
6331
6600
  }, z.core.$loose>;
6332
6601
  readonly source: "loop";
6333
6602
  readonly version: 1;
6603
+ readonly layer: "agent";
6334
6604
  };
6335
6605
  readonly "tool.completed": {
6336
6606
  readonly payload: z.ZodObject<{
@@ -6388,6 +6658,7 @@ export declare const EVENT_CATALOG: {
6388
6658
  }, z.core.$loose>;
6389
6659
  readonly source: "loop";
6390
6660
  readonly version: 1;
6661
+ readonly layer: "agent";
6391
6662
  };
6392
6663
  readonly "effect.uncertain": {
6393
6664
  readonly payload: z.ZodObject<{
@@ -6396,6 +6667,7 @@ export declare const EVENT_CATALOG: {
6396
6667
  }, z.core.$loose>;
6397
6668
  readonly source: "loop";
6398
6669
  readonly version: 1;
6670
+ readonly layer: "agent";
6399
6671
  };
6400
6672
  readonly "delegation.started": {
6401
6673
  readonly payload: z.ZodObject<{
@@ -6408,6 +6680,7 @@ export declare const EVENT_CATALOG: {
6408
6680
  }, z.core.$loose>;
6409
6681
  readonly source: "loop";
6410
6682
  readonly version: 1;
6683
+ readonly layer: "agent";
6411
6684
  };
6412
6685
  readonly "delegation.completed": {
6413
6686
  readonly payload: z.ZodObject<{
@@ -6420,6 +6693,7 @@ export declare const EVENT_CATALOG: {
6420
6693
  }, z.core.$loose>;
6421
6694
  readonly source: "loop";
6422
6695
  readonly version: 1;
6696
+ readonly layer: "agent";
6423
6697
  };
6424
6698
  readonly "mcp.discovered": {
6425
6699
  readonly payload: z.ZodObject<{
@@ -6445,6 +6719,7 @@ export declare const EVENT_CATALOG: {
6445
6719
  }, z.core.$loose>;
6446
6720
  readonly source: "loop";
6447
6721
  readonly version: 1;
6722
+ readonly layer: "runtime";
6448
6723
  };
6449
6724
  readonly "plan.updated": {
6450
6725
  readonly payload: z.ZodObject<{
@@ -6462,6 +6737,7 @@ export declare const EVENT_CATALOG: {
6462
6737
  }, z.core.$loose>;
6463
6738
  readonly source: "loop";
6464
6739
  readonly version: 1;
6740
+ readonly layer: "agent";
6465
6741
  };
6466
6742
  readonly "engine.diagnostic": {
6467
6743
  readonly payload: z.ZodObject<{
@@ -6471,6 +6747,7 @@ export declare const EVENT_CATALOG: {
6471
6747
  }, z.core.$loose>;
6472
6748
  readonly source: "loop";
6473
6749
  readonly version: 1;
6750
+ readonly layer: "runtime";
6474
6751
  };
6475
6752
  readonly "environment.state": {
6476
6753
  readonly payload: z.ZodObject<{
@@ -6490,6 +6767,7 @@ export declare const EVENT_CATALOG: {
6490
6767
  }, z.core.$loose>;
6491
6768
  readonly source: "loop";
6492
6769
  readonly version: 1;
6770
+ readonly layer: "runtime";
6493
6771
  };
6494
6772
  readonly "environment.exec": {
6495
6773
  readonly payload: z.ZodObject<{
@@ -6501,6 +6779,7 @@ export declare const EVENT_CATALOG: {
6501
6779
  }, z.core.$loose>;
6502
6780
  readonly source: "loop";
6503
6781
  readonly version: 1;
6782
+ readonly layer: "runtime";
6504
6783
  };
6505
6784
  readonly "agent.attached": {
6506
6785
  readonly payload: z.ZodObject<{
@@ -6508,6 +6787,7 @@ export declare const EVENT_CATALOG: {
6508
6787
  }, z.core.$loose>;
6509
6788
  readonly source: "api";
6510
6789
  readonly version: 1;
6790
+ readonly layer: "runtime";
6511
6791
  };
6512
6792
  readonly "node.started": {
6513
6793
  readonly payload: z.ZodObject<{
@@ -6518,6 +6798,7 @@ export declare const EVENT_CATALOG: {
6518
6798
  }, z.core.$loose>;
6519
6799
  readonly source: "loop";
6520
6800
  readonly version: 1;
6801
+ readonly layer: "agent";
6521
6802
  };
6522
6803
  readonly "node.completed": {
6523
6804
  readonly payload: z.ZodObject<{
@@ -6539,6 +6820,7 @@ export declare const EVENT_CATALOG: {
6539
6820
  }, z.core.$loose>;
6540
6821
  readonly source: "loop";
6541
6822
  readonly version: 1;
6823
+ readonly layer: "agent";
6542
6824
  };
6543
6825
  readonly "node.agent": {
6544
6826
  readonly payload: z.ZodObject<{
@@ -6549,6 +6831,7 @@ export declare const EVENT_CATALOG: {
6549
6831
  }, z.core.$loose>;
6550
6832
  readonly source: "loop";
6551
6833
  readonly version: 1;
6834
+ readonly layer: "agent";
6552
6835
  };
6553
6836
  readonly "loop.iteration": {
6554
6837
  readonly payload: z.ZodObject<{
@@ -6560,6 +6843,7 @@ export declare const EVENT_CATALOG: {
6560
6843
  }, z.core.$loose>;
6561
6844
  readonly source: "loop";
6562
6845
  readonly version: 1;
6846
+ readonly layer: "agent";
6563
6847
  };
6564
6848
  readonly "loop.verified": {
6565
6849
  readonly payload: z.ZodObject<{
@@ -6571,6 +6855,7 @@ export declare const EVENT_CATALOG: {
6571
6855
  }, z.core.$loose>;
6572
6856
  readonly source: "api";
6573
6857
  readonly version: 1;
6858
+ readonly layer: "agent";
6574
6859
  };
6575
6860
  readonly "artifact.created": {
6576
6861
  readonly payload: z.ZodObject<{
@@ -6597,6 +6882,7 @@ export declare const EVENT_CATALOG: {
6597
6882
  }, z.core.$loose>;
6598
6883
  readonly source: "api";
6599
6884
  readonly version: 1;
6885
+ readonly layer: "runtime";
6600
6886
  };
6601
6887
  readonly "artifact.version.created": {
6602
6888
  readonly payload: z.ZodObject<{
@@ -6623,6 +6909,7 @@ export declare const EVENT_CATALOG: {
6623
6909
  }, z.core.$loose>;
6624
6910
  readonly source: "api";
6625
6911
  readonly version: 1;
6912
+ readonly layer: "runtime";
6626
6913
  };
6627
6914
  readonly "artifact.deleted": {
6628
6915
  readonly payload: z.ZodObject<{
@@ -6631,6 +6918,7 @@ export declare const EVENT_CATALOG: {
6631
6918
  }, z.core.$loose>;
6632
6919
  readonly source: "api";
6633
6920
  readonly version: 1;
6921
+ readonly layer: "runtime";
6634
6922
  };
6635
6923
  readonly "artifact.export.skipped": {
6636
6924
  readonly payload: z.ZodObject<{
@@ -6648,6 +6936,7 @@ export declare const EVENT_CATALOG: {
6648
6936
  }, z.core.$loose>;
6649
6937
  readonly source: "api";
6650
6938
  readonly version: 1;
6939
+ readonly layer: "runtime";
6651
6940
  };
6652
6941
  readonly "artifact.export.failed": {
6653
6942
  readonly payload: z.ZodObject<{
@@ -6656,6 +6945,7 @@ export declare const EVENT_CATALOG: {
6656
6945
  }, z.core.$loose>;
6657
6946
  readonly source: "api";
6658
6947
  readonly version: 1;
6948
+ readonly layer: "runtime";
6659
6949
  };
6660
6950
  readonly "transcript.updated": {
6661
6951
  readonly payload: z.ZodObject<{
@@ -6665,11 +6955,14 @@ export declare const EVENT_CATALOG: {
6665
6955
  }, z.core.$loose>;
6666
6956
  readonly source: "loop";
6667
6957
  readonly version: 1;
6958
+ readonly layer: "agent";
6668
6959
  readonly visibility: "internal";
6669
6960
  };
6670
6961
  };
6671
6962
  export type EventType = keyof typeof EVENT_CATALOG;
6672
6963
  export declare const EVENT_TYPES: readonly EventType[];
6964
+ /** An event type's layer (ADR-159); `undefined` for a type this version does not know. */
6965
+ export declare function eventLayer(type: string): EventLayer | undefined;
6673
6966
  /** Drops the index signatures `passthrough` adds, so plain interfaces are assignable. */
6674
6967
  type Closed<T> = T extends readonly (infer U)[] ? Closed<U>[] : T extends object ? {
6675
6968
  [K in keyof T as string extends K ? never : K]: Closed<T[K]>;
package/dist/contracts.js CHANGED
@@ -1343,6 +1343,124 @@ export const AgentEventSchema = z
1343
1343
  export const ListAgentEventsResponseSchema = z
1344
1344
  .object({ events: z.array(AgentEventSchema) })
1345
1345
  .strict();
1346
+ /** The schema id of the Tenant's events (its stream in the record, ADR-159). */
1347
+ export const TENANT_EVENT_SCHEMA = "nylorun.tenant-event/1";
1348
+ /**
1349
+ * The Tenant's stream (ADR-159, Host feature `tenant-audit`): who changed who may reach the Tenant
1350
+ * and what its sessions may do, and each use of a vault credential, read with
1351
+ * `GET /v1/tenant/audit`. Every type is the Runtime's record (layer `runtime`): the Runtime saw it
1352
+ * happen, in the change's own transaction where it could; no harness writes one. No payload carries
1353
+ * a secret value: keys, signing keys, rules and credentials are named, never shown.
1354
+ */
1355
+ export const TENANT_EVENT_TYPES = [
1356
+ // An application or management key was put (created, or rotated: `rotated`) or deleted.
1357
+ "key.created",
1358
+ "key.revoked",
1359
+ // The signing keys rotated, or one was revoked.
1360
+ "signing_key.rotated",
1361
+ "signing_key.revoked",
1362
+ // The tool policy was replaced.
1363
+ "policy.changed",
1364
+ // Another Tenant setting was replaced: limits, compute, artifacts, skills, budgets, the model.
1365
+ "settings.changed",
1366
+ // A vault credential was written, replaced, deleted or used (each `vault_audit` row of one).
1367
+ "credential.created",
1368
+ "credential.rotated",
1369
+ "credential.deleted",
1370
+ "credential.used",
1371
+ // A person signed in to Studio (Studio records it with its own key).
1372
+ "studio.signed_in",
1373
+ ];
1374
+ /**
1375
+ * What wrote a Tenant event: `api`, a request to the Runtime or Management API; `operate`,
1376
+ * `nylorun-operate` on the Tenant's machine; `runtime`, the Runtime on its own (a gate using a
1377
+ * credential, a sweep deleting an Agent); `studio`, Studio's server, for a sign-in.
1378
+ */
1379
+ export const TENANT_EVENT_SOURCES = ["api", "operate", "runtime", "studio"];
1380
+ /** How a person signed in to Studio: on its loopback address, with a login token, or through a sign-in proxy. */
1381
+ export const STUDIO_SIGN_IN_METHODS = ["loopback", "token", "forwarded"];
1382
+ /**
1383
+ * A credential event's payload: the `vault_audit` row's fields, never the credential's value.
1384
+ * `outcome` is the row's (`created`, `copied`, `rotated`, `deleted`, `approved`, `refused`); a use
1385
+ * names the session it was for and the URL it was sent to (`target`).
1386
+ */
1387
+ const CredentialEventPayloadSchema = z
1388
+ .object({
1389
+ vaultId: z.string().optional(),
1390
+ credentialId: z.string().optional(),
1391
+ sessionId: z.string().optional(),
1392
+ target: z.string().optional(),
1393
+ outcome: z.string(),
1394
+ })
1395
+ .strict();
1396
+ const KeyRoleNameSchema = z.enum(["application", "management"]);
1397
+ /**
1398
+ * The payload of each Tenant event. Each is strict, so a write that carries anything else, a
1399
+ * secret above all, is refused.
1400
+ */
1401
+ export const TENANT_EVENT_PAYLOADS = {
1402
+ /** Key `keyId` was issued; `rotated` when it replaced a key of that name. */
1403
+ "key.created": z.object({ keyId: z.string(), role: KeyRoleNameSchema, rotated: z.boolean() }).strict(),
1404
+ "key.revoked": z.object({ keyId: z.string(), role: KeyRoleNameSchema }).strict(),
1405
+ /** The standby key became `current`; the old current one `previous`, the old previous one `revoked`. */
1406
+ "signing_key.rotated": z
1407
+ .object({
1408
+ current: z.string(),
1409
+ standby: z.string(),
1410
+ previous: z.string().optional(),
1411
+ revoked: z.string().optional(),
1412
+ force: z.boolean(),
1413
+ })
1414
+ .strict(),
1415
+ /** Key `keyId` was revoked from `state`. */
1416
+ "signing_key.revoked": z.object({ keyId: z.string(), state: z.enum(["previous", "standby"]) }).strict(),
1417
+ /** The tool policy now holds `rules` rules, as of `updatedAt`; the rules are read from `GET /v1/tenant/tool-policy`. */
1418
+ "policy.changed": z.object({ rules: z.number().int().nonnegative(), updatedAt: z.string() }).strict(),
1419
+ /**
1420
+ * Setting `key` was replaced: `limits.config`, `environments.config`, `artifacts.config`,
1421
+ * `skills.config`, `model.budgets`, `model.inputs` or `model` (the provider and model in force,
1422
+ * `provider` and `model`; `model.inputs` names the catalog model in `model`). Never its value.
1423
+ */
1424
+ "settings.changed": z
1425
+ .object({ key: z.string(), provider: z.string().optional(), model: z.string().optional() })
1426
+ .strict(),
1427
+ "credential.created": CredentialEventPayloadSchema,
1428
+ "credential.rotated": CredentialEventPayloadSchema,
1429
+ "credential.deleted": CredentialEventPayloadSchema,
1430
+ "credential.used": CredentialEventPayloadSchema,
1431
+ /** A browser signed in to Studio, by `method`, as `subject` when it names a person. */
1432
+ "studio.signed_in": z
1433
+ .object({ method: z.enum(STUDIO_SIGN_IN_METHODS), subject: z.string().optional() })
1434
+ .strict(),
1435
+ };
1436
+ /**
1437
+ * One event on the Tenant's stream, numbered from 0. `principal` is who acted, from the request's
1438
+ * credential: a key's name (`bootstrap`, `studio`, an application key's), `<key>:<subject>` for a
1439
+ * key acting for a person, `<issuer>:<subject>` for a token, `operate` for `nylorun-operate`,
1440
+ * and `host` for the Runtime itself.
1441
+ */
1442
+ export const TenantEventSchema = z
1443
+ .object({
1444
+ schema: z.literal(TENANT_EVENT_SCHEMA),
1445
+ seq: z.number().int().nonnegative(),
1446
+ time: z.string(),
1447
+ type: z.enum(TENANT_EVENT_TYPES),
1448
+ source: z.enum(TENANT_EVENT_SOURCES),
1449
+ principal: z.string(),
1450
+ payload: z.record(z.string(), z.unknown()),
1451
+ })
1452
+ .strict();
1453
+ /** A page of the Tenant's events, newest first; `nextCursor` reads older ones. */
1454
+ export const TenantAuditPageSchema = z
1455
+ .object({ events: z.array(TenantEventSchema), nextCursor: z.string().nullable() })
1456
+ .strict();
1457
+ /** `POST /v1/tenant/audit/studio-sign-in`: how a person signed in to Studio, and who when known. */
1458
+ export const StudioSignInRequestSchema = z
1459
+ .object({
1460
+ method: z.enum(STUDIO_SIGN_IN_METHODS),
1461
+ subject: z.string().min(1).max(200).optional(),
1462
+ })
1463
+ .strict();
1346
1464
  /**
1347
1465
  * A model role's name (Host feature `model-roles`, ADR-154): a lowercase letter, then up to 31
1348
1466
  * lowercase letters, digits and `-`, such as `builder`.
@@ -2973,6 +3091,28 @@ export const MessageDeliverySchema = z.enum(["queue", "reject", "steer"]);
2973
3091
  * only narrows.
2974
3092
  */
2975
3093
  export const RemoveToolsSchema = z.array(z.string().min(1).max(256)).max(256);
3094
+ /** The most context items one message carries (ADR-157). */
3095
+ export const MESSAGE_CONTEXT_MAX_ITEMS = 16;
3096
+ /** The most bytes a message's context items take, as JSON (ADR-157). */
3097
+ export const MESSAGE_CONTEXT_MAX_BYTES = 16 * 1024;
3098
+ /**
3099
+ * A message's `context` (Host feature `message-context`, ADR-157): facts for its own turn only,
3100
+ * such as the time or who the agent is today. Our engine puts them in the `<runtime-context>` block
3101
+ * of every model call of that turn, after the history; later turns leave them out. The
3102
+ * `command.message` event keeps them.
3103
+ */
3104
+ export const MessageContextSchema = z
3105
+ .array(z
3106
+ .object({
3107
+ type: z.string().min(1).max(64).optional(),
3108
+ value: jsonValue,
3109
+ })
3110
+ .strict())
3111
+ .min(1)
3112
+ .max(MESSAGE_CONTEXT_MAX_ITEMS)
3113
+ .refine((items) => new TextEncoder().encode(JSON.stringify(items)).length <= MESSAGE_CONTEXT_MAX_BYTES, {
3114
+ message: `A message's context takes at most ${MESSAGE_CONTEXT_MAX_BYTES} bytes as JSON`,
3115
+ });
2976
3116
  const messageBase = {
2977
3117
  ...commandBase,
2978
3118
  type: z.literal("message"),
@@ -2985,6 +3125,7 @@ const messageBase = {
2985
3125
  manifest: AgentManifestSchema.optional(),
2986
3126
  removeTools: RemoveToolsSchema.optional(),
2987
3127
  delivery: MessageDeliverySchema.optional(),
3128
+ context: MessageContextSchema.optional(),
2988
3129
  };
2989
3130
  /**
2990
3131
  * One part of a user message (protocol 6): text, or a file by artifact id. A file part without
@@ -3087,6 +3228,11 @@ export const EventSourceKindSchema = z.enum([
3087
3228
  "human",
3088
3229
  "api",
3089
3230
  ]);
3231
+ /**
3232
+ * Whose account an event is: the agent's or the Runtime's (ADR-159). A session's events have one each
3233
+ * (`EVENT_CATALOG`); every event on an Agent's stream (`AGENT_EVENT_TYPES`) is the Runtime's.
3234
+ */
3235
+ export const EVENT_LAYERS = ["agent", "runtime"];
3090
3236
  /**
3091
3237
  * How far an event can be trusted, by who could forge it. `observed`: the Runtime saw it itself
3092
3238
  * (commands, the tools core serves, gate records, core's settle). `claimed`: a harness reported
@@ -3577,6 +3723,8 @@ export const CommandMessagePayloadSchema = z
3577
3723
  manifest: z.unknown().optional(),
3578
3724
  /** The tools the message's turn may not use (Host feature `remove-tools`). */
3579
3725
  removeTools: z.array(z.string()).optional(),
3726
+ /** The context items the message carried for its turn (ADR-157, Host feature `message-context`). */
3727
+ context: z.array(z.object({ type: z.string().optional(), value: jsonValue }).strict()).optional(),
3580
3728
  delivery: MessageDeliverySchema.optional(),
3581
3729
  /** Set when the message waited in the session's queue (protocol 17): its id there. */
3582
3730
  queuedMessageId: z.string().optional(),
@@ -3923,65 +4071,73 @@ export const McpDiscoveredPayloadSchema = z
3923
4071
  * new type or a protocol version, never an edit in place.
3924
4072
  */
3925
4073
  export const EVENT_CATALOG = {
3926
- "command.message": { payload: CommandMessagePayloadSchema, source: "api", version: 1 },
3927
- "command.approve": { payload: CommandApprovePayloadSchema, source: "api", version: 1 },
3928
- "command.respond": { payload: CommandRespondPayloadSchema, source: "api", version: 1 },
3929
- "turn.completed": { payload: TurnCompletedPayloadSchema, source: "loop", version: 1 },
3930
- "turn.paused": { payload: TurnPausedPayloadSchema, source: "loop", version: 1 },
3931
- "turn.failed": { payload: TurnFailedPayloadSchema, source: "loop", version: 1 },
3932
- "turn.cancelled": { payload: TurnCancelledPayloadSchema, source: "api", version: 1 },
3933
- "turn.version_kept": { payload: TurnVersionKeptPayloadSchema, source: "api", version: 1 },
3934
- "session.model": { payload: SessionModelPayloadSchema, source: "api", version: 1 },
3935
- "message.queued": { payload: MessageQueuedPayloadSchema, source: "api", version: 1 },
3936
- "queue.taken": { payload: QueueTakenPayloadSchema, source: "api", version: 1 },
3937
- "queue.failed": { payload: QueueFailedPayloadSchema, source: "api", version: 1 },
3938
- "queue.cancelled": { payload: QueueCancelledPayloadSchema, source: "api", version: 1 },
3939
- "wake.booked": { payload: WakeBookedPayloadSchema, source: "api", version: 1 },
3940
- "wake.cancelled": { payload: WakeCancelledPayloadSchema, source: "api", version: 1 },
3941
- "memory.updated": { payload: MemoryUpdatedPayloadSchema, source: "api", version: 1 },
3942
- "message.assistant": { payload: AssistantMessagePayloadSchema, source: "loop", version: 1 },
3943
- "model.failed": { payload: ModelFailedPayloadSchema, source: "loop", version: 1 },
3944
- "context.compacted": { payload: ContextCompactedPayloadSchema, source: "loop", version: 1 },
3945
- "tool.completed": { payload: ToolCompletedPayloadSchema, source: "loop", version: 1 },
3946
- "effect.uncertain": { payload: EffectUncertainPayloadSchema, source: "loop", version: 1 },
3947
- "delegation.started": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
3948
- "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
3949
- "mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1 },
3950
- "plan.updated": { payload: PlanUpdatedPayloadSchema, source: "loop", version: 1 },
3951
- "engine.diagnostic": { payload: EngineDiagnosticPayloadSchema, source: "loop", version: 1 },
3952
- "environment.state": { payload: EnvironmentStatePayloadSchema, source: "loop", version: 1 },
3953
- "environment.exec": { payload: EnvironmentExecPayloadSchema, source: "loop", version: 1 },
3954
- "agent.attached": { payload: AgentAttachedPayloadSchema, source: "api", version: 1 },
3955
- "node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1 },
3956
- "node.completed": { payload: NodeCompletedPayloadSchema, source: "loop", version: 1 },
3957
- "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
3958
- "loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
3959
- "loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
3960
- "artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1 },
4074
+ "command.message": { payload: CommandMessagePayloadSchema, source: "api", version: 1, layer: "agent" },
4075
+ "command.approve": { payload: CommandApprovePayloadSchema, source: "api", version: 1, layer: "agent" },
4076
+ "command.respond": { payload: CommandRespondPayloadSchema, source: "api", version: 1, layer: "agent" },
4077
+ "turn.completed": { payload: TurnCompletedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4078
+ "turn.paused": { payload: TurnPausedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4079
+ "turn.failed": { payload: TurnFailedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4080
+ "turn.cancelled": { payload: TurnCancelledPayloadSchema, source: "api", version: 1, layer: "agent" },
4081
+ "turn.version_kept": { payload: TurnVersionKeptPayloadSchema, source: "api", version: 1, layer: "runtime" },
4082
+ "session.model": { payload: SessionModelPayloadSchema, source: "api", version: 1, layer: "runtime" },
4083
+ "message.queued": { payload: MessageQueuedPayloadSchema, source: "api", version: 1, layer: "runtime" },
4084
+ "queue.taken": { payload: QueueTakenPayloadSchema, source: "api", version: 1, layer: "runtime" },
4085
+ "queue.failed": { payload: QueueFailedPayloadSchema, source: "api", version: 1, layer: "runtime" },
4086
+ "queue.cancelled": { payload: QueueCancelledPayloadSchema, source: "api", version: 1, layer: "runtime" },
4087
+ "wake.booked": { payload: WakeBookedPayloadSchema, source: "api", version: 1, layer: "runtime" },
4088
+ "wake.cancelled": { payload: WakeCancelledPayloadSchema, source: "api", version: 1, layer: "runtime" },
4089
+ "memory.updated": { payload: MemoryUpdatedPayloadSchema, source: "api", version: 1, layer: "agent" },
4090
+ "message.assistant": { payload: AssistantMessagePayloadSchema, source: "loop", version: 1, layer: "agent" },
4091
+ "model.failed": { payload: ModelFailedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4092
+ "context.compacted": { payload: ContextCompactedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4093
+ "tool.completed": { payload: ToolCompletedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4094
+ "effect.uncertain": { payload: EffectUncertainPayloadSchema, source: "loop", version: 1, layer: "agent" },
4095
+ "delegation.started": { payload: DelegationPayloadSchema, source: "loop", version: 1, layer: "agent" },
4096
+ "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1, layer: "agent" },
4097
+ "mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1, layer: "runtime" },
4098
+ "plan.updated": { payload: PlanUpdatedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4099
+ "engine.diagnostic": { payload: EngineDiagnosticPayloadSchema, source: "loop", version: 1, layer: "runtime" },
4100
+ "environment.state": { payload: EnvironmentStatePayloadSchema, source: "loop", version: 1, layer: "runtime" },
4101
+ "environment.exec": { payload: EnvironmentExecPayloadSchema, source: "loop", version: 1, layer: "runtime" },
4102
+ "agent.attached": { payload: AgentAttachedPayloadSchema, source: "api", version: 1, layer: "runtime" },
4103
+ "node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4104
+ "node.completed": { payload: NodeCompletedPayloadSchema, source: "loop", version: 1, layer: "agent" },
4105
+ "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1, layer: "agent" },
4106
+ "loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1, layer: "agent" },
4107
+ "loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1, layer: "agent" },
4108
+ "artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1, layer: "runtime" },
3961
4109
  "artifact.version.created": {
3962
4110
  payload: ArtifactVersionPayloadSchema,
3963
4111
  source: "api",
3964
4112
  version: 1,
4113
+ layer: "runtime",
3965
4114
  },
3966
- "artifact.deleted": { payload: ArtifactDeletedPayloadSchema, source: "api", version: 1 },
4115
+ "artifact.deleted": { payload: ArtifactDeletedPayloadSchema, source: "api", version: 1, layer: "runtime" },
3967
4116
  "artifact.export.skipped": {
3968
4117
  payload: ArtifactExportSkippedPayloadSchema,
3969
4118
  source: "api",
3970
4119
  version: 1,
4120
+ layer: "runtime",
3971
4121
  },
3972
4122
  "artifact.export.failed": {
3973
4123
  payload: ArtifactExportFailedPayloadSchema,
3974
4124
  source: "api",
3975
4125
  version: 1,
4126
+ layer: "runtime",
3976
4127
  },
3977
4128
  "transcript.updated": {
3978
4129
  payload: TranscriptUpdatedPayloadSchema,
3979
4130
  source: "loop",
3980
4131
  version: 1,
4132
+ layer: "agent",
3981
4133
  visibility: "internal",
3982
4134
  },
3983
4135
  };
3984
4136
  export const EVENT_TYPES = Object.keys(EVENT_CATALOG);
4137
+ /** An event type's layer (ADR-159); `undefined` for a type this version does not know. */
4138
+ export function eventLayer(type) {
4139
+ return Object.hasOwn(EVENT_CATALOG, type) ? EVENT_CATALOG[type].layer : undefined;
4140
+ }
3985
4141
  export function isEventType(type) {
3986
4142
  return Object.hasOwn(EVENT_CATALOG, type);
3987
4143
  }
@@ -66,10 +66,14 @@ export const SERVER_SETTING_KEYS = ["deferred", "tools"];
66
66
  export const PLUGIN_SERVER_SETTING_KEYS = [...SERVER_SETTING_KEYS, "credential"];
67
67
  export const TOOL_KEYS = ["description", "inputSchema", "outputSchema", "http"];
68
68
  /**
69
- * The loop settings our harness reads from `loop`: `plan` (`true` offers the agent `update_plan`)
70
- * and `connections` (`true` offers it `request_connection`). A custom harness reads its own.
69
+ * The loop settings our harness reads from `loop`: `plan` (`true` offers the agent `update_plan`),
70
+ * `connections` (`true` offers it `request_connection`), `ask`, and `compaction` (ADR-157: when
71
+ * the agent's sessions compact, `threshold` and `keepTokens`, and `roles.<role>` over them). A
72
+ * custom harness reads its own.
71
73
  */
72
- const NYLORUN_LOOP_KEYS = ["plan", "connections", "ask"];
74
+ const NYLORUN_LOOP_KEYS = ["plan", "connections", "ask", "compaction"];
75
+ /** What `loop.compaction` and each of its `roles` set: positive whole numbers of tokens. */
76
+ const COMPACTION_KEYS = ["threshold", "keepTokens"];
73
77
  const LOOP_TOOLS = { plan: "update_plan", connections: "request_connection", ask: "ask" };
74
78
  /** The runtime fields only a sandbox has, and the ones only a pod has. */
75
79
  const SANDBOX_FIELDS = ["image", "resources", "storage", "network", "setup", "files"];
@@ -554,6 +558,8 @@ export function compileAgentFolder(input, scope) {
554
558
  if (typeof front.loop[key] !== "boolean")
555
559
  error("value_invalid", `loop.${key} is true or false: true offers the agent ${LOOP_TOOLS[key]}`, AGENT_FILE, ["loop", key]);
556
560
  }
561
+ else if (key === "compaction")
562
+ checkCompaction(front.loop.compaction, error);
557
563
  else if (!NYLORUN_LOOP_KEYS.includes(key)) {
558
564
  const close = suggestion(key, NYLORUN_LOOP_KEYS);
559
565
  warn("loop_key", `Unknown loop setting '${key}'.${close ? ` Did you mean '${close}'?` : ""} loop holds the harness's own settings, and the ${DEFAULT_HARNESS} harness reads ${NYLORUN_LOOP_KEYS.length === 0 ? "none yet" : NYLORUN_LOOP_KEYS.join(", ")}, so it is ignored`, AGENT_FILE, ["loop", key], { key: true });
@@ -1493,3 +1499,35 @@ function trimBlankLines(text) {
1493
1499
  lines.pop();
1494
1500
  return lines.join("\n");
1495
1501
  }
1502
+ /**
1503
+ * Checks `loop.compaction` (ADR-157): a map of `threshold` and `keepTokens`, positive whole numbers
1504
+ * of tokens, and `roles`, a map from a role's name to the same two. The harness also ignores a
1505
+ * value it cannot use, so a folder that passes here never changes how its sessions compact by
1506
+ * accident.
1507
+ */
1508
+ function checkCompaction(value, error) {
1509
+ const at = (...path) => ["loop", "compaction", ...path];
1510
+ const settings = (from, path, roles) => {
1511
+ if (!isObject(from)) {
1512
+ error("value_invalid", `${path.join(".")} is a map of ${COMPACTION_KEYS.join(" and ")}${roles ? ", and roles" : ""}`, AGENT_FILE, path);
1513
+ return;
1514
+ }
1515
+ for (const [key, setting] of Object.entries(from)) {
1516
+ if (roles && key === "roles")
1517
+ continue;
1518
+ if (!COMPACTION_KEYS.includes(key))
1519
+ error("unknown_key", `Unknown compaction setting '${key}': ${path.join(".")} takes ${COMPACTION_KEYS.join(", ")}${roles ? " and roles" : ""}`, AGENT_FILE, [...path, key]);
1520
+ else if (typeof setting !== "number" || !Number.isInteger(setting) || setting <= 0)
1521
+ error("value_invalid", `${path.join(".")}.${key} is a positive whole number of tokens`, AGENT_FILE, [...path, key]);
1522
+ }
1523
+ };
1524
+ settings(value, at(), true);
1525
+ if (!isObject(value) || value.roles === undefined)
1526
+ return;
1527
+ if (!isObject(value.roles)) {
1528
+ error("value_invalid", "loop.compaction.roles is a map from a role's name to its threshold and keepTokens", AGENT_FILE, at("roles"));
1529
+ return;
1530
+ }
1531
+ for (const [role, entry] of Object.entries(value.roles))
1532
+ settings(entry, at("roles", role), false);
1533
+ }
@@ -75,7 +75,16 @@ export function folderV3Edit(input) {
75
75
  }
76
76
  // The frontmatter, edited in place: comments and the other keys stay as they are.
77
77
  doc.delete("memory");
78
- doc.delete("loop");
78
+ // loop keeps the harness's own settings (compaction, ADR-157); its plan, connections and ask are plugins now.
79
+ const loopNode = doc.get("loop", true);
80
+ if (isMap(loopNode)) {
81
+ for (const key of ["plan", "connections", "ask"])
82
+ loopNode.delete(key);
83
+ if (loopNode.items.length === 0)
84
+ doc.delete("loop");
85
+ }
86
+ else
87
+ doc.delete("loop");
79
88
  const engineNode = doc.get("engine", true);
80
89
  if (isMap(engineNode)) {
81
90
  for (const key of ["sandbox", "artifacts", "triggers", "instructions"])
@@ -23,7 +23,12 @@ import type { ReportOptions } from "./context.js";
23
23
  /** The format name a v3 folder writes. */
24
24
  export declare const AGENT_FOLDER_V3 = "agent-folder/3";
25
25
  /** The keys of `AGENT.md` a v3 folder declares as plugins instead. */
26
- export declare const V3_REFUSED_KEYS: readonly ["memory", "loop"];
26
+ export declare const V3_REFUSED_KEYS: readonly ["memory"];
27
+ /**
28
+ * The `loop` keys a v3 folder declares as plugins instead. `loop` itself stays the harness's own
29
+ * settings, such as `compaction` (ADR-157).
30
+ */
31
+ export declare const V3_REFUSED_LOOP_KEYS: readonly ["plan", "connections", "ask"];
27
32
  /** The keys of `engine:` a v3 folder declares as plugins instead. */
28
33
  export declare const V3_REFUSED_ENGINE_KEYS: readonly ["sandbox", "artifacts", "triggers", "instructions"];
29
34
  /** Whether `value` names the v3 format: `agent-folder/3` or `3`. */
package/dist/folder/v3.js CHANGED
@@ -23,7 +23,12 @@ import { suggestion } from "./suggest.js";
23
23
  /** The format name a v3 folder writes. */
24
24
  export const AGENT_FOLDER_V3 = "agent-folder/3";
25
25
  /** The keys of `AGENT.md` a v3 folder declares as plugins instead. */
26
- export const V3_REFUSED_KEYS = ["memory", "loop"];
26
+ export const V3_REFUSED_KEYS = ["memory"];
27
+ /**
28
+ * The `loop` keys a v3 folder declares as plugins instead. `loop` itself stays the harness's own
29
+ * settings, such as `compaction` (ADR-157).
30
+ */
31
+ export const V3_REFUSED_LOOP_KEYS = ["plan", "connections", "ask"];
27
32
  /** The keys of `engine:` a v3 folder declares as plugins instead. */
28
33
  export const V3_REFUSED_ENGINE_KEYS = ["sandbox", "artifacts", "triggers", "instructions"];
29
34
  const MIGRATE = "run nylorun migrate folder <dir> --to 3, which writes the plugins that keep what the agent gets today";
@@ -47,6 +52,12 @@ export function v3Declarations(front, options) {
47
52
  for (const key of V3_REFUSED_KEYS)
48
53
  if (front[key] !== undefined)
49
54
  fail("v3_refused", `${key} is a key of agent-folder/2: an agent-folder/3 folder declares the Runtime's features as plugins. Fix: ${MIGRATE}`, [key], { key: true });
55
+ if (front.loop !== undefined && !isObject(front.loop))
56
+ fail("value_invalid", "loop is a map", ["loop"]);
57
+ if (isObject(front.loop))
58
+ for (const key of V3_REFUSED_LOOP_KEYS)
59
+ if (front.loop[key] !== undefined)
60
+ fail("v3_refused", `loop.${key} is a key of agent-folder/2: an agent-folder/3 folder declares the Runtime's features as plugins. Fix: ${MIGRATE}`, ["loop", key], { key: true });
50
61
  if (isObject(front.engine))
51
62
  for (const key of V3_REFUSED_ENGINE_KEYS)
52
63
  if (front.engine[key] !== undefined)
@@ -110,7 +121,11 @@ export function v3Declarations(front, options) {
110
121
  return { name, tools: within ? tools.filter((tool) => within.tools.includes(tool)) : tools };
111
122
  });
112
123
  const on = (tool) => plugins.some((plugin) => plugin.tools.includes(tool));
113
- const loop = Object.fromEntries([["plan", "update_plan"], ["connections", "request_connection"], ["ask", "ask"]].flatMap(([key, tool]) => (role === "root" && on(tool) ? [[key, true]] : [])));
124
+ // The harness's own settings the folder sets (compaction), then those the plugins stand for.
125
+ const loop = {
126
+ ...(isObject(front.loop) ? front.loop : {}),
127
+ ...Object.fromEntries([["plan", "update_plan"], ["connections", "request_connection"], ["ask", "ask"]].flatMap(([key, tool]) => (role === "root" && on(tool) ? [[key, true]] : []))),
128
+ };
114
129
  const engine = {
115
130
  ...(isObject(front.engine) ? front.engine : {}),
116
131
  sandbox: SANDBOX_TOOL_NAMES.filter((tool) => on(tool)),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://docs.nylorun.com/schemas/harness-api/v5.7.json",
3
+ "$id": "https://docs.nylorun.com/schemas/harness-api/v5.8.json",
4
4
  "title": "Nylorun Harness API 5",
5
5
  "$defs": {
6
6
  "ArtifactMeta": {
@@ -1187,6 +1187,11 @@
1187
1187
  },
1188
1188
  "additionalProperties": {}
1189
1189
  },
1190
+ "role": {
1191
+ "type": "string",
1192
+ "minLength": 1,
1193
+ "maxLength": 64
1194
+ },
1190
1195
  "memory": {
1191
1196
  "type": "object",
1192
1197
  "properties": {
@@ -3393,6 +3398,11 @@
3393
3398
  },
3394
3399
  "additionalProperties": {}
3395
3400
  },
3401
+ "role": {
3402
+ "type": "string",
3403
+ "minLength": 1,
3404
+ "maxLength": 64
3405
+ },
3396
3406
  "memory": {
3397
3407
  "type": "object",
3398
3408
  "properties": {
@@ -61,9 +61,10 @@ export function harnessApiSchemas() {
61
61
  `audience: "model"` (ADR-139), which core accepts and only our own engine sends. Revision 6:
62
62
  `routing.sandbox.computer` and the request `computer.open` (ADR-149), which a v5 harness never
63
63
  sees unless the Tenant's pod Agents are computers. Revision 7: the request `computer.current`,
64
- which only a harness that drives computers sends.
64
+ which only a harness that drives computers sends. Revision 8: `turn.start.role` (ADR-157), the
65
+ session's role, which the Runtime sends only to our own harness.
65
66
  */
66
- const SCHEMA_REVISION = 7;
67
+ const SCHEMA_REVISION = 8;
67
68
  /** The JSON Schema document of the Harness API (draft 2020-12). */
68
69
  export function harnessApiJsonSchema() {
69
70
  const $defs = {};
@@ -453,6 +453,7 @@ export declare const TurnStartSchema: z.ZodObject<{
453
453
  version: z.ZodNumber;
454
454
  }, z.core.$strict>>;
455
455
  loop: z.ZodOptional<z.ZodType<object, unknown, z.core.$ZodTypeInternals<object, unknown>>>;
456
+ role: z.ZodOptional<z.ZodString>;
456
457
  memory: z.ZodOptional<z.ZodObject<{
457
458
  access: z.ZodEnum<{
458
459
  read_only: "read_only";
@@ -697,6 +698,7 @@ export declare const harnessRequests: {
697
698
  version: z.ZodNumber;
698
699
  }, z.core.$strict>>;
699
700
  loop: z.ZodOptional<z.ZodType<object, unknown, z.core.$ZodTypeInternals<object, unknown>>>;
701
+ role: z.ZodOptional<z.ZodString>;
700
702
  memory: z.ZodOptional<z.ZodObject<{
701
703
  access: z.ZodEnum<{
702
704
  read_only: "read_only";
@@ -391,6 +391,11 @@ export const TurnStartSchema = z
391
391
  * "connection"`.
392
392
  */
393
393
  loop: document.optional(),
394
+ /**
395
+ * The role the session was opened with (`PUT /v1/sessions/{id}` `role`, ADR-157), so a harness
396
+ * can use its settings for that role. Absent for a session opened without one.
397
+ */
398
+ role: z.string().min(1).max(64).optional(),
394
399
  /** The Agent's memory, when the version its session runs sets `harness.memory`. Absent for a flow. */
395
400
  memory: TurnMemorySchema.optional(),
396
401
  /** The segment's checkpoint; an agent's state has no transcript (`transcript.cursor`). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.48.0-beta",
3
+ "version": "0.50.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",