@nylorun/core 0.32.0-beta → 0.34.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 (56) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/compatibility.d.ts +17 -1
  3. package/dist/compatibility.js +16 -0
  4. package/dist/contracts.d.ts +447 -11
  5. package/dist/contracts.js +211 -16
  6. package/dist/define.d.ts +1 -1
  7. package/dist/define.js +1 -1
  8. package/dist/definition/assemble.d.ts +2 -1
  9. package/dist/definition/assemble.js +1 -0
  10. package/dist/definition/from.js +1 -0
  11. package/dist/definition/manifest.d.ts +2 -1
  12. package/dist/definition/manifest.js +1 -0
  13. package/dist/definition/sections.d.ts +1 -1
  14. package/dist/definition/sections.js +5 -1
  15. package/dist/definition/variant.d.ts +16 -1
  16. package/dist/definition/variant.js +81 -3
  17. package/dist/engine/blocks.d.ts +52 -0
  18. package/dist/engine/blocks.js +155 -0
  19. package/dist/engine/explain.d.ts +36 -0
  20. package/dist/engine/explain.js +108 -0
  21. package/dist/engine/features.d.ts +28 -0
  22. package/dist/engine/features.js +34 -0
  23. package/dist/engine/index.d.ts +14 -0
  24. package/dist/engine/index.js +14 -0
  25. package/dist/engine/mcp.d.ts +119 -0
  26. package/dist/engine/mcp.js +267 -0
  27. package/dist/engine/names.d.ts +12 -0
  28. package/dist/engine/names.js +25 -0
  29. package/dist/engine/preview.d.ts +88 -0
  30. package/dist/engine/preview.js +119 -0
  31. package/dist/engine/projection.d.ts +61 -0
  32. package/dist/engine/projection.js +100 -0
  33. package/dist/engine/tools.d.ts +108 -0
  34. package/dist/engine/tools.js +460 -0
  35. package/dist/folder/compile.d.ts +11 -4
  36. package/dist/folder/compile.js +123 -13
  37. package/dist/folder/context.d.ts +5 -0
  38. package/dist/folder/decompile.js +22 -1
  39. package/dist/folder/engine.d.ts +70 -0
  40. package/dist/folder/engine.js +210 -0
  41. package/dist/folder/nested.js +1 -0
  42. package/dist/folder/schemas.js +42 -3
  43. package/dist/harness-api/harness-api.schema.json +11 -4
  44. package/dist/harness-api/json-schema.js +5 -2
  45. package/dist/harness-api/messages.d.ts +4 -2
  46. package/dist/harness-api/messages.js +4 -1
  47. package/dist/harness-api/schema.d.ts +9 -4
  48. package/dist/harness-api/schema.js +11 -2
  49. package/dist/manifest-schemas.js +8 -4
  50. package/dist/schemas/agent-folder/agent-md.schema.json +79 -3
  51. package/dist/schemas/agent-folder/runtime.schema.json +13 -1
  52. package/dist/schemas/agent-manifest.schema.json +139 -1
  53. package/dist/schemas/harness-manifest.schema.json +124 -1
  54. package/dist/schemas/runtime-manifest.schema.json +13 -1
  55. package/dist/types/manifest.d.ts +47 -0
  56. package/package.json +5 -1
package/dist/contracts.js CHANGED
@@ -1,11 +1,12 @@
1
1
  /** Public wire contracts only. Never import checkpoint or engine modules here. */
2
2
  import { z } from "zod";
3
- import { SANDBOX_NETWORK_PRESETS, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
3
+ import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
4
  import { REMOVED_MANIFEST_FIELDS, REMOVED_RUNTIME_SECTION_FIELDS, agentManifestVersionIssue, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
5
  import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "./definition/delegate.js";
6
6
  import { stdioMcpRefusal } from "./definition/mcp.js";
7
7
  import { APPROVAL_MODES, HTTP_TOOL_METHODS, httpInputIssue, httpUrlIssue, httpUrlTemplateIssue, httpVerifierIssue, } from "./definition/http-tool.js";
8
8
  import { canonical } from "./utils/canonical.js";
9
+ import { ENGINE_BLOCK_NAMES } from "./engine/names.js";
9
10
  import { FILE_NAME_MAX, FILE_PATH_MAX, LINK_TARGET_MAX } from "./utils/file-systems.js";
10
11
  export { FILE_NAME_MAX, FILE_PATH_MAX } from "./utils/file-systems.js";
11
12
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId } from "./utils/harness-id.js";
@@ -230,6 +231,43 @@ const agentRequirementsSchema = z
230
231
  secrets: z.array(z.string().regex(ENVIRONMENT_NAME_PATTERN, "A secret name in requires is an environment variable name")).optional(),
231
232
  })
232
233
  .strict();
234
+ /**
235
+ * The engine features an agent declares (ADR-100, `agent-folder/2`): `harness.engine` of an
236
+ * agent manifest v8 and `engine` of the loop manifest (v7) the harness runs. With it, our engine
237
+ * adds only what it names; without it, the defaults of `agent-folder/1`.
238
+ */
239
+ const engineBlockRefSchema = z
240
+ .object({
241
+ name: z.enum(ENGINE_BLOCK_NAMES),
242
+ version: z.number().int().positive(),
243
+ sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
244
+ source: z.string().min(1).optional(),
245
+ })
246
+ .strict();
247
+ export const HarnessEngineSchema = z
248
+ .strictObject({
249
+ sandbox: z
250
+ .array(z.enum(SANDBOX_TOOL_NAMES))
251
+ .refine((tools) => new Set(tools).size === tools.length, { message: "engine.sandbox names each tool once" })
252
+ .optional()
253
+ .meta({ description: "The sandbox tools offered: any of bash, read, write, edit, grep and glob; needs a computer" }),
254
+ artifacts: z
255
+ .strictObject({ read: z.boolean().optional(), save: z.boolean().optional() })
256
+ .optional()
257
+ .meta({ description: "read: read_artifact and its text; save: save_artifact and its text (needs a computer)" }),
258
+ outputs: z.boolean().optional().meta({ description: "Save /workspace/outputs when a turn ends; needs a computer" }),
259
+ toolSearch: z
260
+ .boolean()
261
+ .optional()
262
+ .meta({ description: "Defer MCP tools behind tool_search when their schemas pass the threshold" }),
263
+ instructions: z
264
+ .partialRecord(z.enum(ENGINE_BLOCK_NAMES), z.string().min(1))
265
+ .optional()
266
+ .meta({ description: "A block's wording replaced, by block name" }),
267
+ blocks: z.array(engineBlockRefSchema).optional().meta({ description: "The engine text blocks the agent gets, with their hashes" }),
268
+ })
269
+ .meta({ id: "HarnessEngine" });
270
+ const harnessEngineField = HarnessEngineSchema.optional();
233
271
  const agentManifestSchema = z
234
272
  .strictObject({
235
273
  manifestSchemaVersion: z.literal(7, {
@@ -245,6 +283,7 @@ const agentManifestSchema = z
245
283
  skills: z.record(z.string(), skillManifestSchema).optional(),
246
284
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
247
285
  requires: agentRequirementsSchema.optional(),
286
+ engine: harnessEngineField,
248
287
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
249
288
  // uploaded definition files (a `functions/` folder). Any value is refused below.
250
289
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
@@ -1257,6 +1296,21 @@ export const TenantEnvironmentsConfigSchema = z
1257
1296
  })
1258
1297
  .strict()
1259
1298
  .optional(),
1299
+ /**
1300
+ * Pods: images that carry this Runtime's engine under `/opt/nylorun` (ADR-99), by repository
1301
+ * (`ghcr.io/nylorun/bot-worker`). A pod of a listed image runs that engine with nothing copied
1302
+ * in, while the engine is the Runtime's own version; otherwise the engine is copied in, as for
1303
+ * any other image.
1304
+ */
1305
+ engine: z
1306
+ .object({
1307
+ images: z
1308
+ .array(z.string().min(1).max(256).regex(/^[a-z0-9]([a-z0-9._:/-]*[a-z0-9])?$/, "an image repository, without a tag or digest"))
1309
+ .max(32)
1310
+ .optional(),
1311
+ })
1312
+ .strict()
1313
+ .optional(),
1260
1314
  /**
1261
1315
  * Where each harness may run, by harness id (`nylorun`, or `*` for the rest):
1262
1316
  * `harness-container` (the Runtime's harness) and `sandbox` (the engine in a pod).
@@ -1328,8 +1382,10 @@ export const CredentialIdentitySchema = z.object({ header: CredentialHeaderNameS
1328
1382
  * `toolPrefix`: what the gateway at `via` puts before each tool name it lists, such as
1329
1383
  * LiteLLM's `github-` (Host feature `gateway-credentials`). The Runtime lists the server's tools
1330
1384
  * without it, so tool names, a manifest's `tools` settings and tool policy rules name the server's
1331
- * own tools, and calls a tool by the name the gateway listed. Only with `via`, and only on an
1332
- * Agent's secret: how a gateway names tools is the installation's routing, never a manifest's.
1385
+ * own tools, and calls a tool by the name the gateway listed. On an Agent's secret, only with
1386
+ * `via`. A manifest's `bearer` or `headers` slot may name it too (Host feature `secret-routing`),
1387
+ * with or without a `via`: it applies whenever the credential's requests go to a `via`, and wins
1388
+ * over the secret's.
1333
1389
  */
1334
1390
  export const CredentialToolPrefixSchema = z
1335
1391
  .string()
@@ -1504,14 +1560,22 @@ export const PutAgentSecretRequestSchema = z.discriminatedUnion("type", [
1504
1560
  /**
1505
1561
  * A secret write on an Environment whose manifest declares the secret's slot: only the
1506
1562
  * value, `value` (or `headers` for a `headers` slot). Its type and binding come from the slot,
1507
- * except the gateway's `toolPrefix`, which this installation's write may add to a slot with `via`.
1563
+ * except this installation's routing of a `bearer` or `headers` slot (Host feature
1564
+ * `secret-routing`): `via`, where its requests go, which wins over the slot's; and the gateway's
1565
+ * `toolPrefix`, which needs a `via` (the write's or the slot's) and gives way to the slot's.
1508
1566
  */
1509
1567
  export const PutAgentSecretValueRequestSchema = z
1510
1568
  .object({
1511
1569
  requestId: RequestIdSchema.optional(),
1512
1570
  value: z.string().min(1).optional(),
1513
1571
  headers: CredentialHeadersSchema.optional(),
1514
- /** A `bearer` or `headers` slot with `via`: how the gateway there prefixes tool names. */
1572
+ /**
1573
+ * A `bearer` or `headers` slot: where this installation sends the credential's requests,
1574
+ * such as a gateway's endpoint for the server. Wins over the slot's `via`; the credential is
1575
+ * still chosen by the slot's `url`.
1576
+ */
1577
+ via: CredentialViaSchema.optional(),
1578
+ /** A `bearer` or `headers` slot with a `via`: how the gateway there prefixes tool names. */
1515
1579
  toolPrefix: CredentialToolPrefixSchema.optional(),
1516
1580
  })
1517
1581
  .strict()
@@ -1541,7 +1605,11 @@ const slotBase = {
1541
1605
  /**
1542
1606
  * One secret an Environment of a kind needs: its type and binding, never its value. The
1543
1607
  * value is written into each Environment's vault (`PUT /v1/agents/{id}/secrets/{name}`
1544
- * with `{ value }`, or `{ headers }` for `headers`), and the binding comes from here.
1608
+ * with `{ value }`, or `{ headers }` for `headers`), and the binding comes from here. A
1609
+ * `bearer` or `headers` slot may name the gateway's `toolPrefix` without a `via`, so a folder
1610
+ * names how tools are listed and each installation binds where requests go (the write's `via`,
1611
+ * Host feature `secret-routing`). At each request the credential's `via` is the secret's, else
1612
+ * the slot's, else none (the slot's `url`), and its tool prefix the slot's, else the secret's.
1545
1613
  */
1546
1614
  export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1547
1615
  z
@@ -1553,8 +1621,24 @@ export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1553
1621
  })
1554
1622
  .strict(),
1555
1623
  z.object({ type: z.literal("environment_variable"), ...slotBase }).strict(),
1556
- z.object({ type: z.literal("bearer"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1557
- z.object({ type: z.literal("headers"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1624
+ z
1625
+ .object({
1626
+ type: z.literal("bearer"),
1627
+ url: z.string().min(1),
1628
+ ...credentialRouting,
1629
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1630
+ ...slotBase,
1631
+ })
1632
+ .strict(),
1633
+ z
1634
+ .object({
1635
+ type: z.literal("headers"),
1636
+ url: z.string().min(1),
1637
+ ...credentialRouting,
1638
+ toolPrefix: CredentialToolPrefixSchema.optional(),
1639
+ ...slotBase,
1640
+ })
1641
+ .strict(),
1558
1642
  ]);
1559
1643
  /** A manifest's secret slots: at most the Tenant's Runtime limit `environmentSecretSlots`. */
1560
1644
  export const EnvironmentSecretSlotsSchema = z
@@ -1615,6 +1699,10 @@ export const HarnessMemorySchema = z.strictObject({
1615
1699
  .max(MEMORY_INSTRUCTIONS_MAX)
1616
1700
  .optional()
1617
1701
  .meta({ description: "What this agent should remember, after the engine's own memory rules" }),
1702
+ index: z
1703
+ .boolean()
1704
+ .optional()
1705
+ .meta({ description: "agent-folder/2: false pins no memory index in a session. Default true" }),
1618
1706
  });
1619
1707
  const harnessMemoryField = HarnessMemorySchema.optional()
1620
1708
  .meta({ description: "The Agent's memory: Markdown files under /memories it keeps across sessions" });
@@ -1661,6 +1749,7 @@ const agentHarnessObject = z
1661
1749
  loop: harnessLoopField,
1662
1750
  memory: harnessMemoryField,
1663
1751
  model: harnessModelField,
1752
+ engine: harnessEngineField,
1664
1753
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
1665
1754
  }, { error: removedFieldError(REMOVED_HARNESS_FIELDS) })
1666
1755
  .superRefine((harness, ctx) => {
@@ -1984,6 +2073,7 @@ export const HarnessManifestFileSchema = z
1984
2073
  loop: harnessLoopField,
1985
2074
  memory: harnessMemoryField,
1986
2075
  model: harnessModelField,
2076
+ engine: harnessEngineField,
1987
2077
  /** MCP server or HTTP tool name → the `runtime.secrets` slot it authenticates with. */
1988
2078
  credentials: z.record(z.string().min(1), z.string().min(1)).optional(),
1989
2079
  /** What this harness needs of any runtime it is combined with; checked by the composer only. */
@@ -2461,8 +2551,15 @@ export const AgentSecretViewSchema = z
2461
2551
  .strict(),
2462
2552
  /** A `headers` credential's header names (lower case), never their values. */
2463
2553
  headerNames: z.array(z.string()).optional(),
2554
+ /**
2555
+ * Where its requests go: the secret's own `via`, else its slot's (Host feature
2556
+ * `secret-routing`). Absent: to its `url`.
2557
+ */
2464
2558
  via: z.string().optional(),
2465
- /** How the gateway at `via` prefixes tool names (Host feature `gateway-credentials`). */
2559
+ /**
2560
+ * How the gateway at `via` prefixes tool names (Host feature `gateway-credentials`): its
2561
+ * slot's, else the secret's; only with a `via`.
2562
+ */
2466
2563
  toolPrefix: z.string().optional(),
2467
2564
  identity: CredentialIdentitySchema.optional(),
2468
2565
  createdAt: z.string(),
@@ -2628,11 +2725,27 @@ const commandBase = {
2628
2725
  * default is `queue`, a protocol 16 client's `reject`.
2629
2726
  */
2630
2727
  export const MessageDeliverySchema = z.enum(["queue", "reject"]);
2728
+ /**
2729
+ * A message's `removeTools` (Host feature `remove-tools`): the tools its turn may not use, by
2730
+ * name. In the root agent and each agent it uses as a tool, a name removes the declared tool of
2731
+ * that name (an agent used as a tool included), `<server>__<tool>` disables an MCP server's tool
2732
+ * (the server's name and the tool's own name on it), and `<server>` every tool of that server.
2733
+ * Applied to the version the turn runs, after a turn's first segment re-pins the session to its
2734
+ * Agent's version; names that version does not have are ignored. Any caller may send it: it
2735
+ * only narrows.
2736
+ */
2737
+ export const RemoveToolsSchema = z.array(z.string().min(1).max(256)).max(256);
2631
2738
  const messageBase = {
2632
2739
  ...commandBase,
2633
2740
  type: z.literal("message"),
2634
- /** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
2741
+ /**
2742
+ * Optional turn manifest (Loop patch): a variant of the version the turn runs. Validated
2743
+ * against the session's pin when the message is accepted, and again against the Agent's
2744
+ * version when the turn's first segment re-pins the session to it; one that is no variant of
2745
+ * that version keeps the turn on the version it pinned (`turn.version_kept`).
2746
+ */
2635
2747
  manifest: AgentManifestSchema.optional(),
2748
+ removeTools: RemoveToolsSchema.optional(),
2636
2749
  delivery: MessageDeliverySchema.optional(),
2637
2750
  };
2638
2751
  /**
@@ -3174,6 +3287,8 @@ export const CommandMessagePayloadSchema = z
3174
3287
  parts: z.array(MessagePartSchema).optional(),
3175
3288
  /** The turn manifest the message carried, if any. */
3176
3289
  manifest: z.unknown().optional(),
3290
+ /** The tools the message's turn may not use (Host feature `remove-tools`). */
3291
+ removeTools: z.array(z.string()).optional(),
3177
3292
  delivery: MessageDeliverySchema.optional(),
3178
3293
  /** Set when the message waited in the session's queue (protocol 17): its id there. */
3179
3294
  queuedMessageId: z.string().optional(),
@@ -3395,6 +3510,70 @@ export const ArtifactExportSkippedPayloadSchema = z
3395
3510
  export const ArtifactExportFailedPayloadSchema = z
3396
3511
  .object({ name: z.string(), message: z.string() })
3397
3512
  .passthrough();
3513
+ /**
3514
+ * `engine.diagnostic`: our engine met something about the session's agent that the agent's
3515
+ * declarations decide, and says so instead of choosing for it (ADR-100), such as `mcp_tools_inline`:
3516
+ * an agent that does not declare `engine.toolSearch` has MCP tool schemas past the share of the
3517
+ * model's context window at which they would be deferred, and keeps them all in its tool list.
3518
+ */
3519
+ export const EngineDiagnosticPayloadSchema = z
3520
+ .object({
3521
+ code: z.string().min(1),
3522
+ message: z.string(),
3523
+ /** The agent used as a tool it is about; absent for the session's root agent. */
3524
+ agentId: z.string().optional(),
3525
+ })
3526
+ .passthrough();
3527
+ /** Where the model a session's turns call comes from (`SessionModelRecord.source`). */
3528
+ export const SESSION_MODEL_SOURCES = ["manifest", "session", "tenant"];
3529
+ /**
3530
+ * Why a session's turns call the Tenant's model and not the one its manifest (`harness.model`) or
3531
+ * its own choice (`PUT /v1/sessions/{id}/model`) names: that model's provider is not connected,
3532
+ * its provider's catalog does not list it, or it is no `<provider>/<model>` the Tenant takes.
3533
+ */
3534
+ export const SESSION_MODEL_FALLBACK_REASONS = ["provider_not_connected", "not_in_catalog", "invalid_model"];
3535
+ /**
3536
+ * The model a session's turns call, and why (`model` on `GET /v1/sessions/{id}`, and the
3537
+ * `session.model` event): `source` `manifest` for the model its Agent's version names
3538
+ * (`harness.model`, Host feature `agent-model`), `session` for its own choice, `tenant` for the
3539
+ * Tenant's model. On a fallback to the Tenant's, `reason` says why the model `requested` (by the
3540
+ * manifest or the session) is not used.
3541
+ */
3542
+ export const SessionModelRecordSchema = z
3543
+ .object({
3544
+ provider: z.string(),
3545
+ model: z.string(),
3546
+ source: z.enum(SESSION_MODEL_SOURCES),
3547
+ reason: z.enum(SESSION_MODEL_FALLBACK_REASONS).optional(),
3548
+ requested: z
3549
+ .object({ provider: z.string(), model: z.string(), by: z.enum(["manifest", "session"]) })
3550
+ .strict()
3551
+ .optional(),
3552
+ })
3553
+ .strict();
3554
+ /**
3555
+ * `session.model`: the model the session's turns call was set (the session opened, its own model
3556
+ * was chosen or cleared) or changed (at a turn's start: a provider was connected or disconnected,
3557
+ * the Tenant's model changed), fallbacks included. `previous` is what it was, absent at the first.
3558
+ */
3559
+ export const SessionModelPayloadSchema = SessionModelRecordSchema.extend({
3560
+ previous: SessionModelRecordSchema.optional(),
3561
+ }).passthrough();
3562
+ /**
3563
+ * `turn.version_kept`: a turn's first segment did not move the session to the version its Agent
3564
+ * runs now (`from` is the version the session keeps, `to` the Agent's). `variant_invalid`: the
3565
+ * turn manifest its message carried is no variant of that version, and the turn runs it on the
3566
+ * version it was accepted for, so the variant never widens what the turn may do. Send the message
3567
+ * again with a variant of the new version, or name the tools with `removeTools`.
3568
+ */
3569
+ export const TurnVersionKeptPayloadSchema = z
3570
+ .object({
3571
+ reason: z.enum(["variant_invalid"]),
3572
+ from: z.object({ name: z.string(), version: z.number().int() }).strict(),
3573
+ to: z.object({ name: z.string(), version: z.number().int() }).strict(),
3574
+ message: z.string(),
3575
+ })
3576
+ .passthrough();
3398
3577
  /** What readying one declared MCP server found (`mcp.discovered`). */
3399
3578
  export const McpServerOutcomeSchema = z
3400
3579
  .object({
@@ -3421,11 +3600,17 @@ export const McpServerOutcomeSchema = z
3421
3600
  .passthrough();
3422
3601
  /**
3423
3602
  * `mcp.discovered`: the session's first turn readied its MCP servers and pinned the tools they
3424
- * offer, one outcome per declared server. A server that did not connect adds no tools for the
3425
- * session's life, so this is where the model's missing tools show (also `mcpDiagnostics`).
3603
+ * offer, one outcome per declared server. A server that did not connect adds no tools until a
3604
+ * later turn's first segment, which tries it again: once it answers, it joins the session's
3605
+ * snapshot and a second `mcp.discovered` names it (`rejoined`, with only the servers that joined).
3606
+ * This is where the model's missing tools show (also `mcpDiagnostics`).
3426
3607
  */
3427
3608
  export const McpDiscoveredPayloadSchema = z
3428
- .object({ servers: z.array(McpServerOutcomeSchema) })
3609
+ .object({
3610
+ servers: z.array(McpServerOutcomeSchema),
3611
+ /** Set when the servers joined the snapshot at a later turn, having failed at the first. */
3612
+ rejoined: z.literal(true).optional(),
3613
+ })
3429
3614
  .passthrough();
3430
3615
  /**
3431
3616
  * The event catalog (Durable Streams §9.5): every session event type, its payload schema, its
@@ -3445,6 +3630,8 @@ export const EVENT_CATALOG = {
3445
3630
  "turn.paused": { payload: TurnPausedPayloadSchema, source: "loop", version: 1 },
3446
3631
  "turn.failed": { payload: TurnFailedPayloadSchema, source: "loop", version: 1 },
3447
3632
  "turn.cancelled": { payload: TurnCancelledPayloadSchema, source: "api", version: 1 },
3633
+ "turn.version_kept": { payload: TurnVersionKeptPayloadSchema, source: "api", version: 1 },
3634
+ "session.model": { payload: SessionModelPayloadSchema, source: "api", version: 1 },
3448
3635
  "message.queued": { payload: MessageQueuedPayloadSchema, source: "api", version: 1 },
3449
3636
  "queue.taken": { payload: QueueTakenPayloadSchema, source: "api", version: 1 },
3450
3637
  "wake.booked": { payload: WakeBookedPayloadSchema, source: "api", version: 1 },
@@ -3459,6 +3646,7 @@ export const EVENT_CATALOG = {
3459
3646
  "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
3460
3647
  "mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1 },
3461
3648
  "plan.updated": { payload: PlanUpdatedPayloadSchema, source: "loop", version: 1 },
3649
+ "engine.diagnostic": { payload: EngineDiagnosticPayloadSchema, source: "loop", version: 1 },
3462
3650
  "environment.state": { payload: EnvironmentStatePayloadSchema, source: "loop", version: 1 },
3463
3651
  "environment.exec": { payload: EnvironmentExecPayloadSchema, source: "loop", version: 1 },
3464
3652
  "agent.attached": { payload: AgentAttachedPayloadSchema, source: "api", version: 1 },
@@ -4096,6 +4284,12 @@ export const SessionViewSchema = z
4096
4284
  closedReason: z.string().optional(),
4097
4285
  mcpSnapshot: z.record(z.string(), z.unknown()).nullable(),
4098
4286
  mcpDiagnostics: z.array(z.record(z.string(), z.unknown())),
4287
+ /**
4288
+ * The model the session's turns call and why (`SessionModelRecord`): as its last turn
4289
+ * started, or as the session opened or chose it since. Null for a flow and while the Tenant
4290
+ * has no model.
4291
+ */
4292
+ model: SessionModelRecordSchema.nullable(),
4099
4293
  /** What the session waits on: interactions, approvals, timers. */
4100
4294
  waits: z.unknown().optional(),
4101
4295
  error: z.string().optional(),
@@ -4349,8 +4543,9 @@ export const ToolInputConditionSchema = z
4349
4543
  * identity: an MCP tool's own name on its server, or an HTTP tool's declared name; never the name
4350
4544
  * a harness gave the model; `*` for any run of characters), `server` (an MCP server's name),
4351
4545
  * `kind`, `agent` (the agent that calls it: the agent manifest's name, or the id of an agent used
4352
- * as a tool or of a flow's agent; never an Agent's id) and `when` (fields of the input, by dotted
4353
- * path). The strictest matching rule decides: `deny` refuses the call before it is sent,
4546
+ * as a tool or of a flow's agent; never an Agent's id; the session's root agent's name matches its
4547
+ * subagents' calls too, those of the agents it uses as tools) and `when` (fields of the input, by
4548
+ * dotted path). The strictest matching rule decides: `deny` refuses the call before it is sent,
4354
4549
  * `ask` holds it until a person approves it on the session (`approve`), `allow` runs it. A call no
4355
4550
  * rule matches runs. Sandbox tools never cross the gate; their network side is egress policy.
4356
4551
  *
@@ -4376,7 +4571,7 @@ export const ToolRuleSchema = z
4376
4571
  .min(1)
4377
4572
  .optional()
4378
4573
  .meta({
4379
- description: "The agent that calls the tool: the agent manifest's name, or the id of an agent used as a tool or of a flow's agent, never an Agent's id. `*` matches any run of characters",
4574
+ description: "The agent that calls the tool: the agent manifest's name, or the id of an agent used as a tool or of a flow's agent, never an Agent's id. The session's root agent's name also matches the calls of the agents it uses as tools. `*` matches any run of characters",
4380
4575
  }),
4381
4576
  when: z
4382
4577
  .record(z.string().min(1), ToolInputConditionSchema)
package/dist/define.d.ts CHANGED
@@ -37,7 +37,7 @@ export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
37
37
  export type { AgentBinding } from "./definition/binding.js";
38
38
  export { VerdictSchema, isVerdict, WorkflowBuildError, isBuiltWorkflow, } from "./definition/workflow/index.js";
39
39
  export type { BuiltWorkflow } from "./definition/workflow/index.js";
40
- export { isVariantOf } from "./definition/variant.js";
40
+ export { isVariantOf, withoutTools } from "./definition/variant.js";
41
41
  export type { Verdict, WorkflowBinding, WorkflowHttpVerify, WorkflowLoopVerify, WorkflowManifest, WorkflowNode, } from "./types/workflow.js";
42
42
  export type { DefinitionPart, BoundToolDefinition, } from "./definition/bound.js";
43
43
  export { bindTool } from "./definition/bind-tool.js";
package/dist/define.js CHANGED
@@ -19,7 +19,7 @@ export { SKILL_ENTRY, SKILL_TOTAL_BYTES_DEFAULT, SKILL_FILE_PATH_MAX, SKILLS_MOU
19
19
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
20
20
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
21
21
  export { VerdictSchema, isVerdict, WorkflowBuildError, isBuiltWorkflow, } from "./definition/workflow/index.js";
22
- export { isVariantOf } from "./definition/variant.js";
22
+ export { isVariantOf, withoutTools } from "./definition/variant.js";
23
23
  export { bindTool } from "./definition/bind-tool.js";
24
24
  export { bindOutputContract } from "./definition/output-contract.js";
25
25
  export { agentFrom } from "./definition/from.js";
@@ -1,6 +1,6 @@
1
1
  import type { DefinitionPart } from "./bound.js";
2
2
  import type { BuiltAgent } from "../types/agent.js";
3
- import type { AgentManifest, AgentRequirements } from "../types/manifest.js";
3
+ import type { AgentManifest, AgentRequirements, HarnessEngine } from "../types/manifest.js";
4
4
  import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
5
5
  import type { ToolSchemaSource } from "../types/tool.js";
6
6
  type BuildResult<Agent> = {
@@ -18,5 +18,6 @@ export declare function assembleAgent(parts: readonly DefinitionPart[], identity
18
18
  metadata?: JsonObject;
19
19
  outputSchema?: ToolSchemaSource;
20
20
  requires?: AgentRequirements;
21
+ engine?: HarnessEngine;
21
22
  }>): BuildResult<BuiltAgent>;
22
23
  export {};
@@ -52,6 +52,7 @@ export function assembleAgent(parts, identity) {
52
52
  metadata: identity.metadata,
53
53
  outputSchema: identity.outputSchema,
54
54
  requires: identity.requires,
55
+ engine: identity.engine,
55
56
  parts: frozenParts,
56
57
  });
57
58
  const agent = bindAgent(frozenParts, manifest, identity);
@@ -56,6 +56,7 @@ export function agentFrom(json, implementations, options) {
56
56
  metadata: manifest.metadata,
57
57
  outputSchema,
58
58
  ...(manifest.requires === undefined ? {} : { requires: manifest.requires }),
59
+ ...(manifest.engine === undefined ? {} : { engine: manifest.engine }),
59
60
  });
60
61
  if (!result.ok)
61
62
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
@@ -1,5 +1,5 @@
1
1
  import type { DefinitionPart } from "./bound.js";
2
- import type { AgentManifest, AgentRequirements } from "../types/manifest.js";
2
+ import type { AgentManifest, AgentRequirements, HarnessEngine } from "../types/manifest.js";
3
3
  import type { JsonObject } from "../types/shared.js";
4
4
  import type { ToolSchemaSource } from "../types/tool.js";
5
5
  /**
@@ -18,5 +18,6 @@ export declare function createManifest(input: {
18
18
  metadata?: JsonObject;
19
19
  outputSchema?: ToolSchemaSource;
20
20
  requires?: AgentRequirements;
21
+ engine?: HarnessEngine;
21
22
  parts: readonly DefinitionPart[];
22
23
  }): AgentManifest;
@@ -43,6 +43,7 @@ export function createManifest(input) {
43
43
  ...(Object.keys(skills).length === 0 ? {} : { skills }),
44
44
  ...(Object.keys(mcpServers).length === 0 ? {} : { mcpServers }),
45
45
  ...(input.requires === undefined ? {} : { requires: copyRequirements(input.requires) }),
46
+ ...(input.engine === undefined ? {} : { engine: JSON.parse(JSON.stringify(input.engine)) }),
46
47
  });
47
48
  }
48
49
  /** `requires` as plain data, its secret names sorted and each once. */
@@ -56,7 +56,7 @@ export declare function sectionGapsAt(manifest: Pick<AgentManifestV8, "harness"
56
56
  * The loop manifest the harness runs for a version of an agent manifest: the harness section
57
57
  * with the manifest's name as its id, in the shape the engine reads (agent manifest v7, workflow
58
58
  * manifest v3). The fields only the Runtime reads (`credential`, a skill's `secrets`, `plugins`,
59
- * `loop`, the harness id) stay out.
59
+ * `loop`, the harness id) stay out; `engine` (ADR-100), which our engine reads, goes in.
60
60
  */
61
61
  export declare function loopManifestOf(manifest: Pick<AgentManifestV8, "name" | "description" | "metadata" | "harness">): AgentManifest | WorkflowManifest;
62
62
  /**
@@ -164,7 +164,7 @@ export function sectionGapsAt(manifest) {
164
164
  * The loop manifest the harness runs for a version of an agent manifest: the harness section
165
165
  * with the manifest's name as its id, in the shape the engine reads (agent manifest v7, workflow
166
166
  * manifest v3). The fields only the Runtime reads (`credential`, a skill's `secrets`, `plugins`,
167
- * `loop`, the harness id) stay out.
167
+ * `loop`, the harness id) stay out; `engine` (ADR-100), which our engine reads, goes in.
168
168
  */
169
169
  export function loopManifestOf(manifest) {
170
170
  const { harness } = manifest;
@@ -193,6 +193,9 @@ export function loopManifestOf(manifest) {
193
193
  ...(harness.tools === undefined ? {} : { tools: harness.tools }),
194
194
  ...(skills.length === 0 ? {} : { skills: Object.fromEntries(skills) }),
195
195
  ...(servers.length === 0 ? {} : { mcpServers: Object.fromEntries(servers) }),
196
+ // What the agent declares of our engine (ADR-100): the harness reads it for this agent, and
197
+ // an embedded subagent carries its own.
198
+ ...(harness.engine === undefined ? {} : { engine: harness.engine }),
196
199
  };
197
200
  }
198
201
  /**
@@ -222,6 +225,7 @@ export function harnessSectionOf(loop, options = {}) {
222
225
  ...(loop.skills === undefined ? {} : { skills: loop.skills }),
223
226
  ...(loop.mcpServers === undefined ? {} : { mcpServers: loop.mcpServers }),
224
227
  ...(loop.outputSchema === undefined ? {} : { outputSchema: loop.outputSchema }),
228
+ ...(loop.engine === undefined ? {} : { engine: loop.engine }),
225
229
  };
226
230
  }
227
231
  /** The Agent Plugins whose labels a loop manifest's skills and servers carry, each once, by name. */
@@ -3,7 +3,22 @@ import type { AgentManifest } from "../types/manifest.js";
3
3
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned manifest
4
4
  * (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
5
5
  * tighten its MCP servers' tool settings, and change its instructions, name,
6
- * description and metadata. Its skills and servers are setup: the sandbox holds the skills from
6
+ * description and metadata. An agent it uses as a tool may only be narrowed the same way: its
7
+ * tools removed and its MCP servers' tool settings tightened (what `withoutTools` makes). Its skills and servers are setup: the sandbox holds the skills from
7
8
  * the session's start.
8
9
  */
9
10
  export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
11
+ /**
12
+ * `manifest` without the tools `names` names (a message's `removeTools`): a turn variant of it
13
+ * (`isVariantOf`) that the Runtime makes, so a client names what a turn may not use without
14
+ * sending a whole manifest. In the root agent and in each agent it uses as a tool, a name removes:
15
+ *
16
+ * - the tool of that name: an agent used as a tool, an HTTP tool, any declared tool;
17
+ * - `<server>__<tool>`, an MCP server's tool by the server's name and the tool's own name on it:
18
+ * disabled in the server's `tools` settings (`{enabled: false}`);
19
+ * - `<server>`, an MCP server's name: every tool of it disabled (`"*"` and each entry).
20
+ *
21
+ * A name that matches nothing is ignored: the version the turn runs may not have it. Returns
22
+ * `manifest` itself when nothing matched.
23
+ */
24
+ export declare function withoutTools(manifest: AgentManifest, names: readonly string[]): AgentManifest;
@@ -8,16 +8,38 @@ function toolsByName(tools) {
8
8
  map.set(tool.name, tool);
9
9
  return map;
10
10
  }
11
- /** Candidate tools (agents used as tools included) may only be removed, never added or changed. */
11
+ /** An agent used as a tool that runs in the turn (not a flow agent, which runs in its own session). */
12
+ function loopAgentOf(tool) {
13
+ return tool.agent && !("kind" in tool.agent) ? tool.agent : undefined;
14
+ }
15
+ /**
16
+ * Candidate tools (agents used as tools included) may only be removed, never added or changed,
17
+ * except that an agent used as a tool may be narrowed (`narrows`): its own tools removed and its
18
+ * MCP servers' tools disabled, the rest of it the same.
19
+ */
12
20
  function removeOnlyTools(pinned, candidate) {
13
21
  const base = toolsByName(pinned);
14
22
  for (const tool of candidate ?? []) {
15
23
  const prior = base.get(tool.name);
16
- if (!prior || !same(prior, tool))
24
+ if (!prior)
25
+ return false;
26
+ if (same(prior, tool))
27
+ continue;
28
+ const child = loopAgentOf(tool);
29
+ const priorChild = loopAgentOf(prior);
30
+ const { agent: _agent, ...rest } = tool;
31
+ const { agent: _prior, ...priorRest } = prior;
32
+ if (!child || !priorChild || !same(rest, priorRest) || !narrows(child, priorChild))
17
33
  return false;
18
34
  }
19
35
  return true;
20
36
  }
37
+ /** `candidate` is `prior` with tools removed and MCP tools disabled, and nothing else changed. */
38
+ function narrows(candidate, prior) {
39
+ const { tools, mcpServers, ...rest } = candidate;
40
+ const { tools: priorTools, mcpServers: priorServers, ...priorRest } = prior;
41
+ return same(rest, priorRest) && removeOnlyTools(priorTools, tools) && tightensServers(priorServers, mcpServers);
42
+ }
21
43
  /**
22
44
  * One tool setting, or the `"*"` entry, only tightened: `enabled` kept or set to
23
45
  * `false`, `approval` and `deferred` kept. Each level of a tool's resolution (its entry, then
@@ -57,7 +79,8 @@ function tightensServers(pinned, candidate) {
57
79
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned manifest
58
80
  * (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
59
81
  * tighten its MCP servers' tool settings, and change its instructions, name,
60
- * description and metadata. Its skills and servers are setup: the sandbox holds the skills from
82
+ * description and metadata. An agent it uses as a tool may only be narrowed the same way: its
83
+ * tools removed and its MCP servers' tool settings tightened (what `withoutTools` makes). Its skills and servers are setup: the sandbox holds the skills from
61
84
  * the session's start.
62
85
  */
63
86
  export function isVariantOf(candidate, pinned) {
@@ -76,3 +99,58 @@ export function isVariantOf(candidate, pinned) {
76
99
  return false;
77
100
  return tightensServers(pinned.mcpServers, candidate.mcpServers);
78
101
  }
102
+ /**
103
+ * `manifest` without the tools `names` names (a message's `removeTools`): a turn variant of it
104
+ * (`isVariantOf`) that the Runtime makes, so a client names what a turn may not use without
105
+ * sending a whole manifest. In the root agent and in each agent it uses as a tool, a name removes:
106
+ *
107
+ * - the tool of that name: an agent used as a tool, an HTTP tool, any declared tool;
108
+ * - `<server>__<tool>`, an MCP server's tool by the server's name and the tool's own name on it:
109
+ * disabled in the server's `tools` settings (`{enabled: false}`);
110
+ * - `<server>`, an MCP server's name: every tool of it disabled (`"*"` and each entry).
111
+ *
112
+ * A name that matches nothing is ignored: the version the turn runs may not have it. Returns
113
+ * `manifest` itself when nothing matched.
114
+ */
115
+ export function withoutTools(manifest, names) {
116
+ const removed = new Set(names);
117
+ if (removed.size === 0)
118
+ return manifest;
119
+ const next = narrowAgent(manifest, removed, true);
120
+ return same(next, manifest) ? manifest : next;
121
+ }
122
+ function narrowAgent(agent, removed, root) {
123
+ const { tools: _tools, mcpServers: _servers, ...rest } = agent;
124
+ const tools = agent.tools
125
+ ?.filter((tool) => !removed.has(tool.name))
126
+ .map((tool) => {
127
+ const child = root ? loopAgentOf(tool) : undefined;
128
+ return child ? { ...tool, agent: narrowAgent(child, removed, false) } : tool;
129
+ });
130
+ const servers = agent.mcpServers === undefined
131
+ ? undefined
132
+ : Object.fromEntries(Object.entries(agent.mcpServers).map(([key, server]) => [key, narrowServer(server, removed)]));
133
+ return {
134
+ ...rest,
135
+ ...(tools === undefined ? {} : { tools }),
136
+ ...(servers === undefined ? {} : { mcpServers: servers }),
137
+ };
138
+ }
139
+ function narrowServer(server, removed) {
140
+ const prefix = `${server.name}__`;
141
+ const all = removed.has(server.name);
142
+ const named = [...removed].filter((name) => name.startsWith(prefix) && name.length > prefix.length);
143
+ if (!all && named.length === 0)
144
+ return server;
145
+ const tools = { ...(server.tools ?? {}) };
146
+ const disable = (key) => {
147
+ tools[key] = { ...(Object.hasOwn(tools, key) ? tools[key] : {}), enabled: false };
148
+ };
149
+ if (all)
150
+ for (const key of [...Object.keys(tools), "*"])
151
+ disable(key);
152
+ else
153
+ for (const name of named)
154
+ disable(name.slice(prefix.length));
155
+ return { ...server, tools };
156
+ }