@nylorun/runtime 0.24.0-beta → 0.25.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 (157) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +10 -2
  3. package/dist/api/a2a/card.d.ts +11 -1
  4. package/dist/api/a2a/card.js +26 -2
  5. package/dist/api/a2a/endpoint.js +4 -2
  6. package/dist/api/a2a/protocol.d.ts +25 -2
  7. package/dist/api/a2a/protocol.js +20 -3
  8. package/dist/api/a2a/routes.d.ts +4 -1
  9. package/dist/api/a2a/routes.js +65 -7
  10. package/dist/api/ag-ui/endpoint.js +5 -2
  11. package/dist/api/ag-ui/history.d.ts +6 -1
  12. package/dist/api/ag-ui/history.js +35 -2
  13. package/dist/api/ag-ui/routes.js +53 -11
  14. package/dist/api/components.d.ts +1165 -678
  15. package/dist/api/components.js +16 -1
  16. package/dist/api/gate/keys.d.ts +2 -1
  17. package/dist/api/gate/keys.js +7 -0
  18. package/dist/api/gate/routes.js +13 -0
  19. package/dist/api/http/app.js +13 -2
  20. package/dist/api/http/body.d.ts +3 -3
  21. package/dist/api/http/body.js +7 -7
  22. package/dist/api/http/routes/environment-manifests.d.ts +9 -0
  23. package/dist/api/http/routes/environment-manifests.js +118 -0
  24. package/dist/api/http/routes/environments.js +61 -12
  25. package/dist/api/http/routes/reads.d.ts +52 -3
  26. package/dist/api/http/routes/sessions.js +13 -3
  27. package/dist/api/http/routes/tenant.js +35 -7
  28. package/dist/api/inbound-files.d.ts +65 -0
  29. package/dist/api/inbound-files.js +115 -0
  30. package/dist/api/openapi.js +18 -3
  31. package/dist/artifacts/disk.js +20 -14
  32. package/dist/artifacts/media-types.d.ts +15 -0
  33. package/dist/artifacts/media-types.js +56 -4
  34. package/dist/artifacts/parts.d.ts +12 -3
  35. package/dist/artifacts/parts.js +15 -4
  36. package/dist/artifacts/workspace.d.ts +4 -4
  37. package/dist/artifacts/workspace.js +6 -18
  38. package/dist/core/flow-host.d.ts +1 -1
  39. package/dist/core/flow-host.js +2 -2
  40. package/dist/core/sandbox-routes.js +2 -2
  41. package/dist/core/turn-manifest.d.ts +3 -2
  42. package/dist/core/turn-manifest.js +29 -5
  43. package/dist/gates/egress-credentials.js +1 -1
  44. package/dist/gates/egress.d.ts +13 -19
  45. package/dist/gates/egress.js +30 -29
  46. package/dist/gates/http-tool.d.ts +3 -4
  47. package/dist/gates/http-tool.js +8 -12
  48. package/dist/gates/journal.js +0 -1
  49. package/dist/gates/mcp-handler.js +2 -3
  50. package/dist/gates/policy.js +1 -3
  51. package/dist/gates/tool-contract.d.ts +1 -1
  52. package/dist/harness/calls.d.ts +2 -2
  53. package/dist/harness/calls.js +9 -12
  54. package/dist/harness/main.js +7 -1
  55. package/dist/harness/pod.d.ts +6 -1
  56. package/dist/harness/pod.js +5 -0
  57. package/dist/harness/service.js +5 -5
  58. package/dist/harness/setup.d.ts +2 -0
  59. package/dist/harness/setup.js +25 -1
  60. package/dist/harness-api/record.d.ts +1 -1
  61. package/dist/harness-api/record.js +13 -13
  62. package/dist/harness-api/server.d.ts +27 -4
  63. package/dist/harness-api/server.js +41 -8
  64. package/dist/harness-api/tool-journal.d.ts +17 -8
  65. package/dist/harness-api/tool-journal.js +41 -11
  66. package/dist/harness-api/workspace.d.ts +7 -5
  67. package/dist/harness-api/workspace.js +25 -19
  68. package/dist/host/gates.js +2 -2
  69. package/dist/host/stack-config.js +1 -1
  70. package/dist/keys/keys.d.ts +9 -2
  71. package/dist/keys/keys.js +4 -1
  72. package/dist/management-openapi.json +366 -61
  73. package/dist/mcp/connect.d.ts +1 -2
  74. package/dist/mcp/connect.js +1 -4
  75. package/dist/mcp/pool.d.ts +1 -4
  76. package/dist/mcp/pool.js +13 -27
  77. package/dist/mcp/preview.js +0 -1
  78. package/dist/mcp/snapshot.d.ts +11 -13
  79. package/dist/mcp/snapshot.js +27 -38
  80. package/dist/model/capabilities.d.ts +26 -0
  81. package/dist/model/capabilities.js +44 -0
  82. package/dist/model/catalog.d.ts +34 -3
  83. package/dist/model/catalog.js +38 -2
  84. package/dist/model/models.d.ts +2 -0
  85. package/dist/model/models.js +1 -1
  86. package/dist/model/native-blocks.d.ts +35 -0
  87. package/dist/model/native-blocks.js +170 -0
  88. package/dist/model/pi-model.js +106 -94
  89. package/dist/openapi.json +9554 -5104
  90. package/dist/record/environment.js +1 -1
  91. package/dist/sandbox/join.js +4 -0
  92. package/dist/sandbox/manager.d.ts +32 -14
  93. package/dist/sandbox/manager.js +132 -93
  94. package/dist/sandbox/placement.d.ts +1 -1
  95. package/dist/sandbox/placement.js +2 -2
  96. package/dist/sandbox/pods/client.d.ts +3 -1
  97. package/dist/sandbox/pods/lifecycle.d.ts +8 -0
  98. package/dist/sandbox/pods/lifecycle.js +15 -0
  99. package/dist/sandbox/pods/spec.js +2 -1
  100. package/dist/sandbox/resolve.d.ts +5 -3
  101. package/dist/sandbox/resolve.js +9 -2
  102. package/dist/sandbox/runtime-tools.d.ts +9 -0
  103. package/dist/sandbox/runtime-tools.js +16 -0
  104. package/dist/sandbox/session-sandbox.d.ts +4 -6
  105. package/dist/sandbox/session-sandbox.js +47 -94
  106. package/dist/sandbox/setup.d.ts +4 -1
  107. package/dist/sandbox/setup.js +46 -9
  108. package/dist/sandbox/share.d.ts +12 -7
  109. package/dist/sandbox/share.js +27 -25
  110. package/dist/sandbox/skills.d.ts +8 -6
  111. package/dist/sandbox/skills.js +24 -23
  112. package/dist/store/postgres/drizzle/0024_flat_manifest.sql +7 -0
  113. package/dist/store/postgres/drizzle/0025_environment_manifests.sql +14 -0
  114. package/dist/store/postgres/drizzle/0026_environment_forks.sql +1 -0
  115. package/dist/store/postgres/drizzle/0027_environment_image_digest.sql +1 -0
  116. package/dist/store/postgres/drizzle/meta/_journal.json +28 -0
  117. package/dist/store/postgres/reads.js +8 -2
  118. package/dist/store/postgres/schema.d.ts +217 -0
  119. package/dist/store/postgres/schema.js +36 -2
  120. package/dist/store/postgres/store.js +79 -4
  121. package/dist/store/types.d.ts +68 -14
  122. package/dist/tenant/advance.js +3 -0
  123. package/dist/tenant/artifact-tool.d.ts +1 -1
  124. package/dist/tenant/artifact-tool.js +43 -22
  125. package/dist/tenant/commands.js +24 -4
  126. package/dist/tenant/context.d.ts +10 -4
  127. package/dist/tenant/effects.js +7 -9
  128. package/dist/tenant/environment-manifests.d.ts +57 -0
  129. package/dist/tenant/environment-manifests.js +200 -0
  130. package/dist/tenant/environments.d.ts +54 -47
  131. package/dist/tenant/environments.js +304 -83
  132. package/dist/tenant/model-setting.d.ts +14 -0
  133. package/dist/tenant/model-setting.js +51 -0
  134. package/dist/tenant/sessions.d.ts +5 -1
  135. package/dist/tenant/sessions.js +45 -12
  136. package/dist/tenant/skill-tool.d.ts +3 -3
  137. package/dist/tenant/skill-tool.js +6 -11
  138. package/dist/tenant/sweep.js +1 -1
  139. package/dist/tenant/tool-results.js +1 -1
  140. package/dist/tenant/tool-search.d.ts +7 -11
  141. package/dist/tenant/tool-search.js +8 -5
  142. package/dist/tenant/transcript.d.ts +51 -32
  143. package/dist/tenant/transcript.js +2 -1
  144. package/dist/traces/ids.d.ts +0 -1
  145. package/dist/traces/ids.js +0 -4
  146. package/dist/traces/map.d.ts +2 -2
  147. package/dist/traces/map.js +1 -29
  148. package/dist/vault/coverage.js +11 -13
  149. package/dist/vault/host-model.d.ts +4 -1
  150. package/dist/vault/host-model.js +10 -2
  151. package/dist/vault/service.d.ts +49 -4
  152. package/dist/vault/service.js +153 -6
  153. package/dist/version.d.ts +1 -1
  154. package/dist/version.js +1 -1
  155. package/package.json +3 -3
  156. package/dist/sandbox/capability.d.ts +0 -3
  157. package/dist/sandbox/capability.js +0 -10
@@ -80,14 +80,14 @@ export function isWorkflowManifest(manifest) {
80
80
  typeof manifest === "object" &&
81
81
  manifest.kind === "workflow");
82
82
  }
83
- /** Flow tool-node effect: `tool` with path/key and no agent capabilityId. */
83
+ /** Flow tool-node effect: `tool` with path/key and no tool name (an agent's tool call names one). */
84
84
  export function isFlowToolEffect(request) {
85
85
  return (request.kind === "tool" &&
86
86
  typeof request.path === "string" &&
87
87
  request.path.length > 0 &&
88
88
  typeof request.key === "string" &&
89
89
  request.key.length > 0 &&
90
- request.capabilityId === undefined);
90
+ request.toolName === undefined);
91
91
  }
92
92
  export function isFlowEffect(request) {
93
93
  return request.kind === "agent" || isFlowToolEffect(request);
@@ -3,7 +3,7 @@
3
3
  * a tool run in the sandbox of the session's Environment.
4
4
  */
5
5
  import { isSandboxToolName, } from "@nylorun/core/define";
6
- import { capabilityForSandbox, sandboxWorkspaceOf, sessionSandboxSpec, } from "../sandbox/share.js";
6
+ import { sandboxWorkspaceOf, sessionSandboxSpec, } from "../sandbox/share.js";
7
7
  export class SandboxRouteError extends Error {
8
8
  status;
9
9
  constructor(status, message) {
@@ -41,7 +41,7 @@ async function runTool(deps, session, tool, input, signal) {
41
41
  manifest: session.manifest,
42
42
  ...(workspace.environmentId === undefined ? {} : { environmentId: workspace.environmentId }),
43
43
  };
44
- return deps.sandbox.run(ref, capabilityForSandbox(spec), tool, input, signal);
44
+ return deps.sandbox.run(ref, spec, tool, input, signal);
45
45
  }
46
46
  /**
47
47
  * `POST /v1/sessions/:id/sandbox/:tool` — application principal.
@@ -16,8 +16,9 @@ export type TurnManifestErr = {
16
16
  readonly message: string;
17
17
  };
18
18
  /**
19
- * Parse `message.manifest`, require it to be a variant of the session pin,
20
- * hash it, and store it. Applies to that turn only (caller must not latch).
19
+ * Parse `message.manifest`, require it to be a variant of the session pin, and store the
20
+ * manifest the turn runs with: the variant with the pin's `runtime` block (a variant never sets
21
+ * one), by its hash. Applies to that turn only (caller must not latch).
21
22
  */
22
23
  export declare function pinTurnManifest(args: {
23
24
  readonly candidate: unknown;
@@ -2,8 +2,29 @@ import { AgentManifestSchema, } from "@nylorun/core/contracts";
2
2
  import { hashManifest } from "@nylorun/core/compatibility";
3
3
  import { isVariantOf } from "@nylorun/core/define";
4
4
  /**
5
- * Parse `message.manifest`, require it to be a variant of the session pin,
6
- * hash it, and store it. Applies to that turn only (caller must not latch).
5
+ * The candidate's agents used as tools with the `runtime` block the pin gave each, when the
6
+ * candidate left it out: a turn variant is written from the definition, and only the Runtime
7
+ * writes `runtime`. A candidate that sets one keeps it, and must then match the pin's.
8
+ */
9
+ function withPinnedDelegates(candidate, pinned) {
10
+ if (candidate.tools === undefined)
11
+ return candidate;
12
+ const pinnedAgents = new Map((pinned.tools ?? []).flatMap((tool) => tool.agent !== undefined && !("kind" in tool.agent) ? [[tool.name, tool.agent]] : []));
13
+ let changed = false;
14
+ const tools = candidate.tools.map((tool) => {
15
+ const agent = tool.agent;
16
+ const prior = pinnedAgents.get(tool.name);
17
+ if (agent === undefined || "kind" in agent || agent.runtime !== undefined || prior?.runtime === undefined)
18
+ return tool;
19
+ changed = true;
20
+ return { ...tool, agent: { ...agent, runtime: prior.runtime } };
21
+ });
22
+ return changed ? { ...candidate, tools } : candidate;
23
+ }
24
+ /**
25
+ * Parse `message.manifest`, require it to be a variant of the session pin, and store the
26
+ * manifest the turn runs with: the variant with the pin's `runtime` block (a variant never sets
27
+ * one), by its hash. Applies to that turn only (caller must not latch).
7
28
  */
8
29
  export function pinTurnManifest(args) {
9
30
  const parsed = AgentManifestSchema.safeParse(args.candidate);
@@ -14,14 +35,17 @@ export function pinTurnManifest(args) {
14
35
  message: "Turn manifest failed AgentManifestSchema validation",
15
36
  };
16
37
  }
17
- const manifest = parsed.data;
18
- if (!isVariantOf(manifest, args.pinned)) {
38
+ const candidate = withPinnedDelegates(parsed.data, args.pinned);
39
+ if (!isVariantOf(candidate, args.pinned)) {
19
40
  return {
20
41
  ok: false,
21
42
  code: "loop.invalid-agent",
22
- message: "Turn manifest is not a variant of the session's pinned manifest",
43
+ message: candidate.runtime === undefined
44
+ ? "Turn manifest is not a variant of the session's pinned manifest"
45
+ : "Turn manifest sets runtime, which only the Runtime writes: leave it out, and the turn runs with the session's",
23
46
  };
24
47
  }
48
+ const manifest = args.pinned.runtime === undefined ? candidate : { ...candidate, runtime: args.pinned.runtime };
25
49
  const hash = hashManifest(manifest);
26
50
  args.store.put(hash, manifest);
27
51
  return { ok: true, manifest, hash };
@@ -12,7 +12,7 @@
12
12
  * Nothing here knows a tool: the header name and its format are the credential's. A release the
13
13
  * vault refuses (two secrets for one host, an unreadable value) answers 502 and is logged, never
14
14
  * as an event; a value never is. Upgrades (WebSocket) and HTTP/2 are not served on this path.
15
- * Each connection keeps a tally for its `egress.connection` event (R7.3): how many requests it
15
+ * Each connection keeps a tally for its `environment.egress` event (R7.3, D67): how many requests it
16
16
  * read and which credentials it set, by id.
17
17
  */
18
18
  import { createServer } from "node:http";
@@ -1,6 +1,6 @@
1
1
  import { type Server } from "node:http";
2
2
  import { type Socket } from "node:net";
3
- import type { EventPayload, EventWriter } from "@nylorun/core/contracts";
3
+ import type { EgressRunningTurn, EnvironmentEventPayload } from "@nylorun/core/contracts";
4
4
  import type { EgressTokenVerdict } from "../sandbox/egress-token.js";
5
5
  import type { SessionStore } from "../store/types.js";
6
6
  import type { Logger } from "../tenant/types.js";
@@ -16,22 +16,17 @@ export interface EgressSandboxes {
16
16
  readonly allow: readonly string[];
17
17
  } | undefined>;
18
18
  }
19
- /** The session and turn holding an Environment: turns are serial per Environment, so one at most. */
20
- export interface EgressHolder {
21
- readonly sessionId: string;
22
- readonly turnId: string;
23
- }
24
- /** One connection's record (R7.3): `egress.connection`'s payload, `environment.egress`'s too. */
25
- export type EgressConnection = EventPayload<"egress.connection">;
26
- /** Where egress-gate records connections (R7.3). */
19
+ /** One connection's record (R7.3, D67): `environment.egress`'s payload. */
20
+ export type EgressConnection = EnvironmentEventPayload<"environment.egress">;
21
+ /** How many running turns one connection names, at most. */
22
+ export declare const EGRESS_RUNNING_TURNS_MAX = 16;
23
+ /** Where egress-gate records connections (R7.3, D67). */
27
24
  export interface EgressRecord {
28
- /** The session whose turn holds the Environment now; `undefined` between turns. */
29
- holder(environmentId: string): Promise<EgressHolder | undefined>;
30
- /** Writes `connection` to `holder`'s session log, or to the Environment's stream without one. */
31
- write(holder: EgressHolder | undefined, connection: EgressConnection): Promise<void>;
25
+ /** The turns active on the Environment now, at most `EGRESS_RUNNING_TURNS_MAX`. */
26
+ runningTurns(environmentId: string): Promise<readonly EgressRunningTurn[]>;
27
+ /** Writes `connection` to its Environment's stream; a deleted Environment gets nothing. */
28
+ write(connection: EgressConnection): Promise<void>;
32
29
  }
33
- /** egress-gate as the writer of its events (R4.9): the gate saw the connection itself. */
34
- export declare const EGRESS_WRITER: EventWriter;
35
30
  /** Ports a tunnel may open. */
36
31
  export declare const EGRESS_PORTS: readonly number[];
37
32
  /** Tunnels one sandbox may hold open at once. */
@@ -93,10 +88,9 @@ export declare function startEgressGate(options: StartEgressGateOptions): Promis
93
88
  */
94
89
  export declare function storeEgressSandboxes(store: SessionStore): EgressSandboxes;
95
90
  /**
96
- * `EgressRecord` over the Tenant's record (R7.3). The holder is the session on the Environment
97
- * whose body has an `activeTurnId` (turns are serial per Environment). With a holder, the write
98
- * is `egress.connection` on its session log, at that turn, under the session row's lock; without
99
- * one, `environment.egress` on the Environment's stream, under its row's lock. A deleted
91
+ * `EgressRecord` over the Tenant's record (R7.3, D67). The running turns are the sessions on the
92
+ * Environment whose body has an `activeTurnId`, in id order, at most `EGRESS_RUNNING_TURNS_MAX`.
93
+ * The write is `environment.egress` on the Environment's stream, under its row's lock; a deleted
100
94
  * Environment gets nothing.
101
95
  */
102
96
  export declare function storeEgressRecord(store: SessionStore): EgressRecord;
@@ -24,11 +24,12 @@
24
24
  * (an absolute-form plain HTTP request included) is answered 405. Refusals are logged; the token
25
25
  * never is. Tunnels close after `idleMs` without traffic in either direction.
26
26
  *
27
- * Every connection to a named host on a live token is recorded once (R7.3, Q6, Q7), when it
28
- * closes or at once when the gate refuses it: `egress.connection` on the session log of the turn
29
- * that held the Environment when it opened (read as the name resolves), else `environment.egress`
30
- * on the Environment's own stream. Host, port, outcome, bytes, duration and, for a credential
31
- * host, the request count and credential ids; never a header value, a path or a body. A refusal
27
+ * Every connection to a named host on a live token is recorded once (R7.3, D67), when it closes
28
+ * or at once when the gate refuses it, as `environment.egress` on the Environment's own stream:
29
+ * the connection is the Environment's, since its token names the pod and turns run in parallel
30
+ * (D66). `runningTurns` lists the turns active on the Environment as it opened (read as the name
31
+ * resolves), as context and never as an owner. Host, port, outcome, bytes, duration and, for a
32
+ * credential host, the request count and credential ids; never a header value, a path or a body. A refusal
32
33
  * before that (no token, a stale one, no `host:port`) stays a log line, and a client that hangs up
33
34
  * before the gate answers leaves nothing. A write never holds the tunnel up, and a failed one is
34
35
  * logged (`egress_record_failed`).
@@ -40,8 +41,8 @@ import { isSandboxHostPattern } from "@nylorun/core/define";
40
41
  import { isPrivateAddress } from "../tenant/outbound.js";
41
42
  import { bindListener } from "../host/http.js";
42
43
  import { CONNECT_ESTABLISHED, credentialTerminator, } from "./egress-credentials.js";
43
- /** egress-gate as the writer of its events (R4.9): the gate saw the connection itself. */
44
- export const EGRESS_WRITER = { source: { kind: "egress-gate", id: "egress" }, evidence: "observed" };
44
+ /** How many running turns one connection names, at most. */
45
+ export const EGRESS_RUNNING_TURNS_MAX = 16;
45
46
  /** Ports a tunnel may open. */
46
47
  export const EGRESS_PORTS = [443, 80];
47
48
  /** Tunnels one sandbox may hold open at once. */
@@ -146,16 +147,17 @@ function answer(socket, status, message, headers = []) {
146
147
  ].join("\r\n"));
147
148
  }
148
149
  function connectionRecord(sink, logger, client, at) {
149
- let holding;
150
+ let running;
150
151
  let written = false;
151
- const holder = (to) => (holding ??= to.holder(at.environmentId));
152
+ const runningTurns = (to) => (running ??= to.runningTurns(at.environmentId));
152
153
  const write = (fields) => {
153
154
  if (written || !sink)
154
155
  return;
155
156
  written = true;
156
157
  const socket = client;
157
158
  const allowed = fields.outcome === "allowed";
158
- const connection = {
159
+ const durationMs = Math.max(0, Date.now() - at.startedAt.getTime());
160
+ const connection = (turns) => ({
159
161
  environmentId: at.environmentId,
160
162
  host: at.host,
161
163
  port: at.port,
@@ -165,11 +167,12 @@ function connectionRecord(sink, logger, client, at) {
165
167
  // Up is what the sandbox sent after its CONNECT, down what it got after the gate's 200.
166
168
  bytesUp: allowed ? Math.max(0, (socket.bytesRead ?? 0) - at.upFrom) : 0,
167
169
  bytesDown: allowed ? Math.max(0, (socket.bytesWritten ?? 0) - CONNECT_ESTABLISHED.length) : 0,
168
- durationMs: Math.max(0, Date.now() - at.startedAt.getTime()),
170
+ durationMs,
169
171
  startedAt: at.startedAt.toISOString(),
170
- };
171
- holder(sink)
172
- .then((held) => sink.write(held, connection))
172
+ runningTurns: [...turns],
173
+ });
174
+ runningTurns(sink)
175
+ .then((turns) => sink.write(connection(turns)))
173
176
  .catch((error) => logger.error("egress_record_failed", {
174
177
  sandboxId: at.environmentId,
175
178
  host: at.host,
@@ -179,7 +182,7 @@ function connectionRecord(sink, logger, client, at) {
179
182
  const record = {
180
183
  credentialBound: false,
181
184
  // A failed read is logged when the write needs it.
182
- holder: () => void (sink && holder(sink).catch(() => undefined)),
185
+ opened: () => void (sink && runningTurns(sink).catch(() => undefined)),
183
186
  refused: (status, reason) => write({ outcome: "refused", reason, status }),
184
187
  closed: (tally) => write({
185
188
  outcome: "allowed",
@@ -257,8 +260,8 @@ export async function startEgressGate(options) {
257
260
  return refuse(403, "not_a_host_name", { sandboxId }, `${host} is not a host name; IP literals are refused`);
258
261
  if (!egressAllows(host, sandbox.allow))
259
262
  return refuse(403, "host_not_allowed", { sandboxId }, `${host} is not in this sandbox's network.allow`);
260
- // Who holds the Environment as the connection opens, read while the name resolves.
261
- record.holder();
263
+ // The turns running on the Environment as the connection opens, read while the name resolves.
264
+ record.opened();
262
265
  let mine = open.get(sandboxId);
263
266
  if (!mine)
264
267
  open.set(sandboxId, (mine = new Set()));
@@ -409,25 +412,23 @@ export function storeEgressSandboxes(store) {
409
412
  };
410
413
  }
411
414
  /**
412
- * `EgressRecord` over the Tenant's record (R7.3). The holder is the session on the Environment
413
- * whose body has an `activeTurnId` (turns are serial per Environment). With a holder, the write
414
- * is `egress.connection` on its session log, at that turn, under the session row's lock; without
415
- * one, `environment.egress` on the Environment's stream, under its row's lock. A deleted
415
+ * `EgressRecord` over the Tenant's record (R7.3, D67). The running turns are the sessions on the
416
+ * Environment whose body has an `activeTurnId`, in id order, at most `EGRESS_RUNNING_TURNS_MAX`.
417
+ * The write is `environment.egress` on the Environment's stream, under its row's lock; a deleted
416
418
  * Environment gets nothing.
417
419
  */
418
420
  export function storeEgressRecord(store) {
419
421
  return {
420
- async holder(environmentId) {
422
+ async runningTurns(environmentId) {
421
423
  const sessions = await store.tx((t) => t.sessionsOnEnvironment(environmentId));
422
- const holding = sessions.find((session) => typeof session.activeTurnId === "string");
423
- return holding ? { sessionId: holding.id, turnId: holding.activeTurnId } : undefined;
424
+ return sessions
425
+ .filter((session) => typeof session.activeTurnId === "string")
426
+ .map((session) => ({ sessionId: session.id, turnId: session.activeTurnId }))
427
+ .sort((a, b) => (a.sessionId < b.sessionId ? -1 : a.sessionId > b.sessionId ? 1 : 0))
428
+ .slice(0, EGRESS_RUNNING_TURNS_MAX);
424
429
  },
425
- async write(holder, connection) {
430
+ async write(connection) {
426
431
  await store.tx(async (t) => {
427
- if (holder) {
428
- await t.event(holder.sessionId, holder.turnId, "egress.connection", connection, EGRESS_WRITER);
429
- return;
430
- }
431
432
  if (!(await t.environment(connection.environmentId, { lock: true })))
432
433
  return;
433
434
  await t.environmentEvent(connection.environmentId, "environment.egress", connection);
@@ -24,14 +24,13 @@ export type HttpOutcome = {
24
24
  };
25
25
  /**
26
26
  * One declared HTTP tool of a session: what the gate finds it by in the pinned manifest. An
27
- * agent's HTTP tool is named by its capability and tool; a flow's HTTP stage or HTTP verifier
27
+ * agent's HTTP tool is named by its agent and tool name; a flow's HTTP stage or HTTP verifier
28
28
  * by its stage key.
29
29
  */
30
30
  export type HttpToolRef = {
31
31
  readonly sessionId: string;
32
32
  /** The agent used as a tool that declares it; absent for the session's root agent. */
33
33
  readonly agentId?: string;
34
- readonly capabilityId: string;
35
34
  readonly toolName: string;
36
35
  } | {
37
36
  readonly sessionId: string;
@@ -57,8 +56,8 @@ export interface HttpToolTenant {
57
56
  } | undefined>;
58
57
  authorize(sessionId: string, request: McpCredentialRequest): Promise<AuthorizeResult>;
59
58
  }
60
- /** The HTTP tool `capabilityId`/`toolName` of the agent `agentId` (the root when absent). */
61
- export declare function declaredHttpTool(manifest: unknown, agentId: string | undefined, capabilityId: string | undefined, toolName: string | undefined): (ToolManifest & {
59
+ /** The HTTP tool `toolName` of the agent `agentId` (the root when absent). */
60
+ export declare function declaredHttpTool(manifest: unknown, agentId: string | undefined, toolName: string | undefined): (ToolManifest & {
62
61
  readonly http: HttpToolTarget;
63
62
  }) | undefined;
64
63
  /** The HTTP stage or HTTP verifier at stage key `stage` of a flow session's `manifest`. */
@@ -20,15 +20,13 @@ import { MAX_RESPONSE_BYTES, post } from "../tenant/outbound.js";
20
20
  import { credentialSecrets } from "../vault/headers.js";
21
21
  /** How much of a failed answer's body the model sees. */
22
22
  export const HTTP_ERROR_BODY_CHARS = 2_000;
23
- /** The HTTP tool `capabilityId`/`toolName` of the agent `agentId` (the root when absent). */
24
- export function declaredHttpTool(manifest, agentId, capabilityId, toolName) {
23
+ /** The HTTP tool `toolName` of the agent `agentId` (the root when absent). */
24
+ export function declaredHttpTool(manifest, agentId, toolName) {
25
25
  const root = manifest;
26
- if (!root || !Array.isArray(root.capabilities))
26
+ if (!root || typeof root !== "object" || isWorkflowManifest(root) || toolName === undefined)
27
27
  return undefined;
28
28
  const agent = agentId === undefined ? root : delegateManifest(root, agentId);
29
- const tool = agent?.capabilities
30
- .find((capability) => capability.id === capabilityId)
31
- ?.tools?.find((item) => item.name === toolName);
29
+ const tool = agent?.tools?.find((item) => item.name === toolName);
32
30
  return tool?.http ? tool : undefined;
33
31
  }
34
32
  /** The HTTP stage or HTTP verifier at stage key `stage` of a flow session's `manifest`. */
@@ -44,18 +42,17 @@ export function declaredFlowHttp(manifest, stage) {
44
42
  export function isHttpToolCall(manifest, request) {
45
43
  if (request.kind !== "tool")
46
44
  return false;
47
- if (request.capabilityId === undefined)
45
+ if (request.toolName === undefined)
48
46
  return declaredFlowHttp(manifest, request.key) !== undefined;
49
- return declaredHttpTool(manifest, request.agent?.id, request.capabilityId, request.toolName) !== undefined;
47
+ return declaredHttpTool(manifest, request.agent?.id, request.toolName) !== undefined;
50
48
  }
51
49
  /** The ref a `tool` effect calls the Tool Gate with: its agent's HTTP tool, or its flow stage. */
52
50
  export function httpToolRefOf(request) {
53
- if (request.capabilityId === undefined)
51
+ if (request.toolName === undefined)
54
52
  return { sessionId: request.sessionId, stage: request.key };
55
53
  return {
56
54
  sessionId: request.sessionId,
57
55
  ...(request.agent ? { agentId: request.agent.id } : {}),
58
- capabilityId: request.capabilityId,
59
56
  toolName: request.toolName,
60
57
  };
61
58
  }
@@ -138,7 +135,6 @@ export async function runHttpTool(tenant, call, options) {
138
135
  ...("stage" in tool
139
136
  ? { stage: tool.stage }
140
137
  : {
141
- capability: tool.capabilityId,
142
138
  tool: tool.toolName,
143
139
  ...(tool.agentId === undefined ? {} : { agent: tool.agentId }),
144
140
  }),
@@ -154,7 +150,7 @@ export async function runHttpTool(tenant, call, options) {
154
150
  const agentId = "stage" in tool ? undefined : tool.agentId;
155
151
  const declared = "stage" in tool
156
152
  ? declaredFlowHttp(session.manifest, tool.stage)
157
- : declaredHttpTool(session.manifest, agentId, tool.capabilityId, tool.toolName);
153
+ : declaredHttpTool(session.manifest, agentId, tool.toolName);
158
154
  if (!declared)
159
155
  return failed("http.undeclared", "stage" in tool
160
156
  ? `'${tool.stage}' is not an HTTP stage of the flow`
@@ -28,7 +28,6 @@ export function journalCheck(vaults) {
28
28
  const session = await t.get("sessions", request.sessionId);
29
29
  const tool = mcpToolOf(session?.mcpSnapshot, request);
30
30
  if (!tool ||
31
- tool.capabilityId !== call.server.capabilityId ||
32
31
  tool.serverName !== call.server.serverName ||
33
32
  (tool.agentId ?? null) !== (call.server.agentId ?? null) ||
34
33
  tool.serverToolName !== call.name)
@@ -13,13 +13,13 @@ export function createMcpHandler(options) {
13
13
  const open = options.open ?? openMcpServer;
14
14
  const live = new Map();
15
15
  const opening = new Map();
16
- const keyOf = (server) => JSON.stringify([server.sessionId, server.agentId ?? null, server.capabilityId, server.serverName]);
16
+ const keyOf = (server) => JSON.stringify([server.sessionId, server.agentId ?? null, server.serverName]);
17
17
  /** The declared remote server, from the session's pinned manifest. */
18
18
  async function declared(vault, server) {
19
19
  const session = await vault.session(server.sessionId);
20
20
  if (!session)
21
21
  throw new NotDeclared(`Session ${server.sessionId} not found`);
22
- const found = findServer(session.manifest, server.agentId, server.capabilityId, server.serverName);
22
+ const found = findServer(session.manifest, server.agentId, server.serverName);
23
23
  if (!found)
24
24
  throw new NotDeclared(`MCP server '${server.serverName}' is not declared`);
25
25
  return found.server;
@@ -174,7 +174,6 @@ export function createMcpHandler(options) {
174
174
  function fields(server) {
175
175
  return {
176
176
  session: server.sessionId,
177
- capability: server.capabilityId,
178
177
  server: server.serverName,
179
178
  ...(server.agentId === undefined ? {} : { agent: server.agentId }),
180
179
  };
@@ -68,9 +68,7 @@ export function pinnedApproval(manifest, snapshot, request) {
68
68
  const mcp = mcpToolOf(snapshot, request);
69
69
  if (mcp)
70
70
  return mcpToolSettingsIn(manifest, mcp).approval === "always";
71
- if (request.capabilityId === undefined)
72
- return false;
73
- return declaredHttpTool(manifest, request.agent?.id, request.capabilityId, request.toolName)?.approval === "always";
71
+ return declaredHttpTool(manifest, request.agent?.id, request.toolName)?.approval === "always";
74
72
  }
75
73
  function matches(rule, call) {
76
74
  if (rule.kind !== undefined && rule.kind !== call.kind)
@@ -30,7 +30,7 @@
30
30
  * answers `{ok: false, error: {uncertain: true}}`, and the caller sends it again.
31
31
  *
32
32
  * HTTP tools (R2 M3). `POST /nylorun/v1/http-calls` `{tool, effectId, turnId, input}`: one call
33
- * of an HTTP tool. The loop names the tool (`{sessionId?, agentId?, capabilityId, toolName}`), or a
33
+ * of an HTTP tool. The loop names the tool (`{sessionId?, agentId?, toolName}`), or a
34
34
  * flow's HTTP stage or HTTP verifier by its stage key (`{sessionId?, stage}`); the gate finds its
35
35
  * URL, method and credential in the session's pinned manifest
36
36
  * (`gates/http-tool.ts`). A run token's turn is the call's; `turnId` counts only under core's
@@ -49,9 +49,9 @@ export declare function invokeModel(route: ModelRoute, request: HostEffect, sign
49
49
  * so the next advance replays it.
50
50
  */
51
51
  export declare function abortOn(signal: AbortSignal, kinds: readonly AbortReason[]): AbortSignal;
52
- /** True when `request` calls `save_artifact` of the `nylorun.artifacts` capability `manifest` has. */
52
+ /** True when `request` calls `save_artifact`, which the Runtime pinned on `manifest`. */
53
53
  export declare function isSaveArtifactCall(manifest: AgentManifest | undefined, request: HostEffect): boolean;
54
- /** True when `request` calls `read_artifact` (R2b C11) of the `nylorun.artifacts` capability. */
54
+ /** True when `request` calls `read_artifact` (R2b C11), which the Runtime pinned on `manifest`. */
55
55
  export declare function isReadArtifactCall(manifest: AgentManifest | undefined, request: HostEffect): boolean;
56
56
  /** True when `request` calls a tool of a declared MCP server (every one is remote). */
57
57
  export declare function isRemoteMcpCall(routing: Pick<ToolRouting, "rootManifest" | "mcpSnapshot">, request: HostEffect): boolean;
@@ -3,13 +3,13 @@
3
3
  * Tenant's provider), the Tool Gate, the MCP pool, the SandboxManager. No store, no record: the
4
4
  * session's routing comes with the run (`TurnStart.routing`).
5
5
  */
6
- import { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, } from "@nylorun/core/define";
6
+ import { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, } from "@nylorun/core/define";
7
7
  import { runAbortKind } from "@nylorun/harness/api";
8
8
  import { httpToolRefOf } from "../gates/http-tool.js";
9
9
  import { classifyThrown } from "../model/classify.js";
10
10
  import { findServer } from "../mcp/pool.js";
11
11
  import { manifestFor, mcpToolOf } from "../mcp/snapshot.js";
12
- import { sandboxCapabilityOf } from "../sandbox/capability.js";
12
+ import { isPinnedRuntimeTool, sandboxToolSpec } from "../sandbox/runtime-tools.js";
13
13
  /**
14
14
  * Call the model for one effect. A provider failure comes back as a failure outcome
15
15
  * (Model Calls §6), whichever provider serves the call; only an abort throws, and the
@@ -65,20 +65,18 @@ export function abortOn(signal, kinds) {
65
65
  signal.addEventListener("abort", follow, { once: true });
66
66
  return controller.signal;
67
67
  }
68
- /** True when `request` calls `save_artifact` of the `nylorun.artifacts` capability `manifest` has. */
68
+ /** True when `request` calls `save_artifact`, which the Runtime pinned on `manifest`. */
69
69
  export function isSaveArtifactCall(manifest, request) {
70
70
  return isArtifactsToolCall(manifest, request, SAVE_ARTIFACT_TOOL);
71
71
  }
72
- /** True when `request` calls `read_artifact` (R2b C11) of the `nylorun.artifacts` capability. */
72
+ /** True when `request` calls `read_artifact` (R2b C11), which the Runtime pinned on `manifest`. */
73
73
  export function isReadArtifactCall(manifest, request) {
74
74
  return isArtifactsToolCall(manifest, request, READ_ARTIFACT_TOOL);
75
75
  }
76
76
  function isArtifactsToolCall(manifest, request, toolName) {
77
77
  return (request.kind === "tool" &&
78
- request.capabilityId === ARTIFACTS_CAPABILITY_ID &&
79
78
  request.toolName === toolName &&
80
- manifest?.capabilities.some((capability) => capability.id === ARTIFACTS_CAPABILITY_ID &&
81
- capability.tools?.some((tool) => tool.name === toolName) === true) === true);
79
+ isPinnedRuntimeTool(manifest, toolName));
82
80
  }
83
81
  /** True when `request` calls a tool of a declared MCP server (every one is remote). */
84
82
  export function isRemoteMcpCall(routing, request) {
@@ -87,7 +85,7 @@ export function isRemoteMcpCall(routing, request) {
87
85
  const tool = mcpToolOf(routing.mcpSnapshot, request);
88
86
  if (!tool)
89
87
  return false;
90
- return findServer(routing.rootManifest, tool.agentId, tool.capabilityId, tool.serverName) !== undefined;
88
+ return findServer(routing.rootManifest, tool.agentId, tool.serverName) !== undefined;
91
89
  }
92
90
  export async function callMcpTool(mcp, routing, request, signal,
93
91
  /** The call's span context (R7.4), sent as `traceparent` where this process holds the connection. */
@@ -98,7 +96,6 @@ traceparent) {
98
96
  return mcp.call({
99
97
  sessionId: request.sessionId,
100
98
  ...(tool.agentId === undefined ? {} : { agentId: tool.agentId }),
101
- capabilityId: tool.capabilityId,
102
99
  serverName: tool.serverName,
103
100
  serverToolName: tool.serverToolName,
104
101
  args: request.input,
@@ -127,8 +124,8 @@ traceparent) {
127
124
  }, signal);
128
125
  }
129
126
  export async function callSandboxTool(sandbox, routing, request, signal) {
130
- const capability = sandboxCapabilityOf(manifestFor(routing.rootManifest, request.agent), request.capabilityId, request.toolName);
131
- if (!capability)
127
+ const spec = sandboxToolSpec(manifestFor(routing.rootManifest, request.agent), request.toolName);
128
+ if (!spec)
132
129
  throw new Error(`'${request.toolName ?? ""}' is not a sandbox tool`);
133
130
  // Agents used as tools share the session's sandbox; the tree declares one sandbox spec.
134
131
  return sandbox.run({
@@ -138,5 +135,5 @@ export async function callSandboxTool(sandbox, routing, request, signal) {
138
135
  ...(routing.environmentId === undefined ? {} : { environmentId: routing.environmentId }),
139
136
  ...(routing.environment === undefined ? {} : { environment: routing.environment }),
140
137
  ...(routing.claim === undefined ? {} : { claim: routing.claim }),
141
- }, capability, request.toolName, request.input, signal);
138
+ }, spec, request.toolName, request.input, signal);
142
139
  }
@@ -40,6 +40,7 @@ export async function runHarness(stack, baseline) {
40
40
  logger.info("host_stack_config", { services: [...stack.services], harness: config.url, gates: config.gatesUrl });
41
41
  // A pod's engine trusts the network only once its NetworkPolicy blocks what it must.
42
42
  let pod;
43
+ let prepare;
43
44
  if (config.pod) {
44
45
  const { waitedMs } = await awaitNetworkPolicy({
45
46
  addresses: config.pod.blocked,
@@ -53,13 +54,16 @@ export async function runHarness(stack, baseline) {
53
54
  // Join, then make the disk ready (R2d step 2) before taking any turn.
54
55
  await pod.token();
55
56
  const host = pod;
56
- await prepareDisk({
57
+ prepare = () => prepareDisk({
57
58
  host,
58
59
  exec: localExec({ env: baseline, proxyEnv: () => host.proxyEnv() }),
59
60
  volumeFile: join(config.root, "volume-id"),
60
61
  markerFile: join(config.root, "setup.json"),
61
62
  logger,
62
63
  });
64
+ // A fork onto other setup (Q17) runs it after connecting: core writes its disk through the connection.
65
+ if (!pod.afterSeed)
66
+ await prepare();
63
67
  }
64
68
  const token = pod ? () => pod.token() : config.token;
65
69
  if (token === undefined)
@@ -79,6 +83,8 @@ export async function runHarness(stack, baseline) {
79
83
  version: RUNTIME_VERSION,
80
84
  onGrant: (grant) => runTokens.grant(grant),
81
85
  });
86
+ if (pod?.afterSeed && prepare)
87
+ void prepare().catch((error) => logger.warn("environment_setup_failed", { message: error instanceof Error ? error.message : String(error) }));
82
88
  const health = createServer((request, response) => {
83
89
  if (request.url !== "/health") {
84
90
  response.writeHead(404).end();
@@ -31,8 +31,13 @@ export interface PodHost {
31
31
  readonly epoch: number | undefined;
32
32
  /** The disk's setup from the last join, if its recipe has one. */
33
33
  readonly setup: DiskSetup | undefined;
34
- /** The last join's volume starts from a disk version core writes: no setup runs on it. */
34
+ /** The last join's volume starts from a disk version core writes: no setup runs on it… */
35
35
  readonly seeded: boolean;
36
+ /**
37
+ * …unless it is a fork onto other setup (Q17): the setup runs once core has written the
38
+ * version, which it does through this engine's connection, so the engine connects first.
39
+ */
40
+ readonly afterSeed: boolean;
36
41
  /** Whether to run the setup again after a failure, with the plan to run now. */
37
42
  setupState(): Promise<{
38
43
  retry: boolean;
@@ -33,6 +33,7 @@ export function podHost(config, logger, options = {}) {
33
33
  let held;
34
34
  let setup;
35
35
  let seeded = false;
36
+ let afterSeed = false;
36
37
  /** The CA in the bundle on disk, once one is written. */
37
38
  let bundled;
38
39
  const post = async (path, init) => {
@@ -56,6 +57,7 @@ export function podHost(config, logger, options = {}) {
56
57
  if (path === "join") {
57
58
  setup = body.setup;
58
59
  seeded = body.seeded === true;
60
+ afterSeed = body.afterSeed === true;
59
61
  }
60
62
  return {
61
63
  hostToken: body.hostToken,
@@ -168,6 +170,9 @@ export function podHost(config, logger, options = {}) {
168
170
  get seeded() {
169
171
  return seeded;
170
172
  },
173
+ get afterSeed() {
174
+ return afterSeed;
175
+ },
171
176
  async setupState() {
172
177
  const response = await authorized("setup", { method: "GET" });
173
178
  if (!response.ok)