@nylorun/core 0.18.0-beta → 0.20.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 (42) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/dist/compatibility.d.ts +78 -30
  3. package/dist/compatibility.js +83 -30
  4. package/dist/contracts.d.ts +1531 -461
  5. package/dist/contracts.js +972 -344
  6. package/dist/define.d.ts +1 -0
  7. package/dist/define.js +1 -0
  8. package/dist/definition/approval.d.ts +16 -0
  9. package/dist/definition/approval.js +35 -0
  10. package/dist/definition/code-tools.d.ts +1 -1
  11. package/dist/definition/code-tools.js +1 -1
  12. package/dist/definition/flow/compile.js +0 -2
  13. package/dist/definition/http-tool.d.ts +7 -4
  14. package/dist/definition/http-tool.js +6 -10
  15. package/dist/definition/manifest.js +1 -0
  16. package/dist/definition/mcp.d.ts +4 -4
  17. package/dist/definition/mcp.js +15 -12
  18. package/dist/definition/removed.js +1 -1
  19. package/dist/definition/variant.d.ts +1 -1
  20. package/dist/definition/variant.js +6 -5
  21. package/dist/harness-api/entries.d.ts +241 -0
  22. package/dist/harness-api/entries.js +117 -0
  23. package/dist/harness-api/gates.d.ts +172 -0
  24. package/dist/harness-api/gates.js +119 -0
  25. package/dist/harness-api/harness-api.schema.json +5056 -0
  26. package/dist/harness-api/index.d.ts +19 -3
  27. package/dist/harness-api/index.js +16 -3
  28. package/dist/harness-api/json-schema.d.ts +12 -0
  29. package/dist/harness-api/json-schema.js +61 -0
  30. package/dist/harness-api/mcp.d.ts +61 -0
  31. package/dist/harness-api/mcp.js +41 -0
  32. package/dist/harness-api/messages.d.ts +12 -4
  33. package/dist/harness-api/messages.js +6 -2
  34. package/dist/harness-api/schema.d.ts +356 -31
  35. package/dist/harness-api/schema.js +147 -20
  36. package/dist/harness-api/transport.d.ts +55 -0
  37. package/dist/harness-api/transport.js +61 -0
  38. package/dist/types/manifest.d.ts +15 -9
  39. package/dist/types/observe.d.ts +3 -2
  40. package/dist/utils/harness-id.d.ts +9 -0
  41. package/dist/utils/harness-id.js +11 -0
  42. package/package.json +5 -4
package/dist/define.d.ts CHANGED
@@ -11,6 +11,7 @@ export { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, S
11
11
  export { MCP_TOOL_DEFAULTS, manifestVersionFor, mcp, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
12
12
  export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, TOOLS_CAPABILITY_ID, deferredToolsInstructions, deferredToolsTools, toolsCapabilityManifest, type DeferredServerNote, } from "./definition/tools-capability.js";
13
13
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
14
+ export { approvalRefusal, approvalsOf } from "./definition/approval.js";
14
15
  export type { CodeTool } from "./definition/code-tools.js";
15
16
  export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
16
17
  export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
package/dist/define.js CHANGED
@@ -7,6 +7,7 @@ export { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, S
7
7
  export { MCP_TOOL_DEFAULTS, manifestVersionFor, mcp, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
8
8
  export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, TOOLS_CAPABILITY_ID, deferredToolsInstructions, deferredToolsTools, toolsCapabilityManifest, } from "./definition/tools-capability.js";
9
9
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
10
+ export { approvalRefusal, approvalsOf } from "./definition/approval.js";
10
11
  export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
11
12
  export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, flowHttpTarget, forEachFlowNode, indexSuffix, isLeafNode, isWorkflowManifest, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
12
13
  export { ToolError, isToolError } from "./definition/tool-error.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `approval` in a manifest (R5 step 2). Tool approvals are the Tenant's tool policy now, decided
3
+ * at the Runtime's Tool Gate for every harness: `PUT /v1/tenant/tool-policy`, a rule with
4
+ * `effect: "ask"`. So `PUT /v1/agents/:id` and a turn's manifest refuse a definition that sets
5
+ * `approval` on an HTTP tool, an MCP server or an MCP tool's settings, and the SDK refuses it
6
+ * before sending. A manifest saved before keeps it: the gateway reads it from the session's
7
+ * pinned manifest as an ask, so no session loses the approval it was opened with.
8
+ */
9
+ import type { AgentManifest } from "../types/manifest.js";
10
+ import type { WorkflowManifest } from "../types/workflow.js";
11
+ /** Why the SDK refuses an `approval` option. */
12
+ export declare const APPROVAL_REMOVED = "approval was removed: tool approvals are the Tenant's tool policy now, decided at the Tool Gate for every harness (PUT /v1/tenant/tool-policy, a rule with effect \"ask\"; see MIGRATION.md)";
13
+ /** Where a definition sets `approval`, as a person reads it. */
14
+ export declare function approvalsOf(manifest: AgentManifest | WorkflowManifest, into?: string[]): string[];
15
+ /** Why a definition that sets `approval` is refused, naming the first; undefined when none does. */
16
+ export declare function approvalRefusal(manifest: AgentManifest | WorkflowManifest): string | undefined;
@@ -0,0 +1,35 @@
1
+ /** Why the SDK refuses an `approval` option. */
2
+ export const APPROVAL_REMOVED = 'approval was removed: tool approvals are the Tenant\'s tool policy now, decided at the Tool Gate for every harness (PUT /v1/tenant/tool-policy, a rule with effect "ask"; see MIGRATION.md)';
3
+ /** Where a definition sets `approval`, as a person reads it. */
4
+ export function approvalsOf(manifest, into = []) {
5
+ if ("kind" in manifest && manifest.kind === "workflow") {
6
+ for (const agent of Object.values(manifest.agents))
7
+ approvalsOf(agent, into);
8
+ return into;
9
+ }
10
+ const agent = manifest;
11
+ for (const capability of agent.capabilities) {
12
+ for (const tool of capability.tools ?? []) {
13
+ if (tool.agent !== undefined)
14
+ approvalsOf(tool.agent, into);
15
+ else if (tool.approval !== undefined)
16
+ into.push(`tool '${tool.name}' of agent '${agent.id}'`);
17
+ }
18
+ for (const [key, server] of Object.entries(capability.mcpServers ?? {})) {
19
+ if (server.approval !== undefined)
20
+ into.push(`MCP server '${server.name ?? key}' of agent '${agent.id}'`);
21
+ for (const [name, settings] of Object.entries(server.tools ?? {}))
22
+ if (settings.approval !== undefined)
23
+ into.push(`tool '${name}' of MCP server '${server.name ?? key}' of agent '${agent.id}'`);
24
+ }
25
+ }
26
+ return into;
27
+ }
28
+ /** Why a definition that sets `approval` is refused, naming the first; undefined when none does. */
29
+ export function approvalRefusal(manifest) {
30
+ const [first, ...rest] = approvalsOf(manifest);
31
+ if (!first)
32
+ return undefined;
33
+ const more = rest.length === 0 ? "" : ` (and ${rest.length} more)`;
34
+ return `approval was removed from the manifest: remove it from ${first}${more}. Tool approvals are the Tenant's tool policy now, decided at the Tool Gate for every harness: PUT /v1/tenant/tool-policy with a rule whose effect is "ask" (see MIGRATION.md).`;
35
+ }
@@ -2,7 +2,7 @@
2
2
  * Tools that would run the developer's code (track R2 M6): an agent tool with no `http` and no
3
3
  * `agent` that is not one of the Runtime's built-ins (sandbox tools, skill tools,
4
4
  * `save_artifact`, `read_artifact`), and a flow agent's `tool` stage without `http`. The
5
- * Runtime runs no code of yours during a session, so `PUT /v1/agents/:id` refuses a definition
5
+ * Runtime runs agents from their manifests alone, so `PUT /v1/agents/:id` refuses a definition
6
6
  * with one, and the SDK refuses it before sending. The local engine (`@nylorun/harness/run`)
7
7
  * still runs `tool({ run })`.
8
8
  */
@@ -43,5 +43,5 @@ export function codeToolRefusal(manifest) {
43
43
  ? `The tool stage '${first.name}' of flow agent '${first.owner}'`
44
44
  : `Tool '${first.name}' of agent '${first.owner}'`;
45
45
  const more = rest.length === 0 ? "" : ` (and ${rest.length} more)`;
46
- return `${what}${more} runs your code, and the Runtime runs no code of yours during a session. Make it an http() tool or serve it from a remote MCP server (see MIGRATION.md).`;
46
+ return `${what}${more} runs your code, but the Runtime runs agents from their manifests alone. Make it an http() tool or serve it from a remote MCP server (see MIGRATION.md).`;
47
47
  }
@@ -141,8 +141,6 @@ function childNode(child, build) {
141
141
  attach(build, node, { tool });
142
142
  return node;
143
143
  }
144
- if (target.approval === "always")
145
- build.diagnostics.push(diagnostic("flow.approval-unsupported", `HTTP stage '${tool.name}': approval on a flow stage is not supported yet`));
146
144
  // The Runtime runs it through its Tool Gate: nothing is bound.
147
145
  return { tool: { ...node.tool, http: { ...target.http } } };
148
146
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * HTTP tools (R2 M3): a tool the manifest describes as one HTTP request, which the Runtime makes
3
3
  * itself through its Tool Gate. No developer code runs for it: the tool value carries its target
4
- * (`http`) and static approval into the manifest, and its `execute` only says where it runs.
4
+ * (`http`) into the manifest, and its `execute` only says where it runs. Whether a call waits for
5
+ * a person is the Tenant's tool policy, decided at the Tool Gate (R5 step 2), never the tool's.
5
6
  * An HTTP tool is also a flow stage. `http({ url })` without a name and an input is a bare
6
7
  * target, a Loop's HTTP verifier: its manifest form is itself, `{ http: { url, … } }`.
7
8
  */
@@ -18,6 +19,11 @@ export declare const HTTP_TOOL_MAX_TIMEOUT_MS = 300000;
18
19
  /** What an HTTP tool puts in its manifest entry besides its name and schemas. */
19
20
  export interface HttpTool {
20
21
  readonly http: HttpToolTarget;
22
+ /**
23
+ * @deprecated A pinned manifest's `approval`, from before R5 step 2: kept so the rebuilt
24
+ * definition hashes as pinned, and held by the Tool Gate. Nothing asks for it here, and
25
+ * `http()` refuses it.
26
+ */
21
27
  readonly approval?: ApprovalMode;
22
28
  }
23
29
  export interface HttpToolOptions<InputSchema extends ToolInputSchema | JsonObject = ToolInputSchema, OutputSchema extends ToolOutputSchema | JsonObject | undefined = undefined> extends HttpToolTarget {
@@ -27,8 +33,6 @@ export interface HttpToolOptions<InputSchema extends ToolInputSchema | JsonObjec
27
33
  readonly input: InputSchema;
28
34
  /** Checked against the answer; a mismatch is a tool error the model sees. */
29
35
  readonly output?: OutputSchema;
30
- /** `always`: each call waits for approval. Default `never`. */
31
- readonly approval?: ApprovalMode;
32
36
  }
33
37
  /** A bare HTTP target: a Loop's HTTP verifier, `.loop(body, { verify: http({ url }), max })`. */
34
38
  export interface HttpTarget {
@@ -54,7 +58,6 @@ export declare function httpToolFromManifest(declared: ToolManifest & {
54
58
  /**
55
59
  * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
56
60
  * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
57
- * `approval: "always"` makes each call wait for approval.
58
61
  */
59
62
  export declare function withHttpTarget(tool: Omit<AnyTool, "execute"> & Pick<Partial<AnyTool>, "execute">, target: HttpTool): AnyTool;
60
63
  /** The HTTP target behind a tool definition, or behind the bound snapshot of one. */
@@ -1,3 +1,4 @@
1
+ import { APPROVAL_REMOVED } from "./approval.js";
1
2
  import { HarnessError } from "../errors.js";
2
3
  import { ToolError } from "./tool-error.js";
3
4
  import { prepareTool } from "./schema.js";
@@ -14,9 +15,11 @@ export const HTTP_TOOL_MAX_TIMEOUT_MS = 300_000;
14
15
  export function http(options) {
15
16
  if (!("name" in options) && !("input" in options))
16
17
  return httpTarget(options);
17
- const { name, description, input, output, approval } = options;
18
+ const { name, description, input, output } = options;
18
19
  const target = targetOf(options);
19
- const issue = (input === undefined ? "input is required" : undefined) ?? httpTargetIssue(target) ?? approvalIssue(approval);
20
+ const issue = (input === undefined ? "input is required" : undefined) ??
21
+ httpTargetIssue(target) ??
22
+ ("approval" in options ? APPROVAL_REMOVED : undefined);
20
23
  if (issue)
21
24
  throw new HarnessError("tool.invalid", `HTTP tool '${name}': ${issue}`);
22
25
  return prepareTool(withHttpTarget({
@@ -24,7 +27,7 @@ export function http(options) {
24
27
  ...(description === undefined ? {} : { description }),
25
28
  inputSchema: schemaSource(input),
26
29
  ...(output === undefined ? {} : { outputSchema: schemaSource(output) }),
27
- }, { http: target, ...(approval === undefined ? {} : { approval }) }));
30
+ }, { http: target }));
28
31
  }
29
32
  function targetOf({ url, method, credential, timeoutMs }) {
30
33
  return {
@@ -63,13 +66,11 @@ export function httpToolFromManifest(declared) {
63
66
  /**
64
67
  * Marks `tool` as an HTTP tool. A host gives its own `execute` (the Runtime's engine routes the
65
68
  * call to its Tool Gate); without one, calling it explains that only the Runtime runs it.
66
- * `approval: "always"` makes each call wait for approval.
67
69
  */
68
70
  export function withHttpTarget(tool, target) {
69
71
  const definition = {
70
72
  ...tool,
71
73
  execute: tool.execute ?? runtimeOnly,
72
- ...(target.approval === "always" ? { approval: () => true } : {}),
73
74
  };
74
75
  Object.defineProperty(definition, HTTP, {
75
76
  value: Object.freeze({ http: Object.freeze({ ...target.http }), ...(target.approval ? { approval: target.approval } : {}) }),
@@ -115,11 +116,6 @@ export function httpUrlIssue(url) {
115
116
  return "url must not have a fragment";
116
117
  return undefined;
117
118
  }
118
- function approvalIssue(approval) {
119
- return approval === undefined || APPROVAL_MODES.includes(approval)
120
- ? undefined
121
- : `approval must be one of ${APPROVAL_MODES.join(", ")}`;
122
- }
123
119
  async function runtimeOnly() {
124
120
  throw new ToolError("http.runtime-only", "HTTP tools are run by the Nylorun Runtime, not in this process");
125
121
  }
@@ -66,6 +66,7 @@ function projectTool(tool) {
66
66
  : { outputSchema: schemas.outputSchema.jsonSchema }),
67
67
  ...(delegate === undefined ? {} : { agent: delegate.manifest }),
68
68
  ...(http === undefined ? {} : { http: { ...http.http } }),
69
+ // A pinned manifest's, from before R5 step 2: identity only.
69
70
  ...(http?.approval === undefined ? {} : { approval: http.approval }),
70
71
  };
71
72
  }
@@ -31,9 +31,9 @@ export declare class McpError extends Error {
31
31
  * })
32
32
  * ```
33
33
  *
34
- * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist, approval
35
- * per tool, deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either
36
- * makes the manifest v6.
34
+ * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist and
35
+ * deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either makes the
36
+ * manifest v6. Whether a call waits for a person is the Tenant's tool policy (R5 step 2).
37
37
  *
38
38
  * ```ts
39
39
  * Agent({ id: "assistant" }).mcp({
@@ -43,7 +43,7 @@ export declare class McpError extends Error {
43
43
  * tools: {
44
44
  * "*": { enabled: false },
45
45
  * search_issues: { enabled: true },
46
- * create_issue: { enabled: true, approval: "always" },
46
+ * create_issue: { enabled: true },
47
47
  * },
48
48
  * },
49
49
  * })
@@ -1,4 +1,4 @@
1
- import { APPROVAL_MODES } from "./http-tool.js";
1
+ import { APPROVAL_REMOVED } from "./approval.js";
2
2
  export class McpError extends Error {
3
3
  code;
4
4
  constructor(code, message) {
@@ -20,9 +20,9 @@ export class McpError extends Error {
20
20
  * })
21
21
  * ```
22
22
  *
23
- * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist, approval
24
- * per tool, deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either
25
- * makes the manifest v6.
23
+ * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist and
24
+ * deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either makes the
25
+ * manifest v6. Whether a call waits for a person is the Tenant's tool policy (R5 step 2).
26
26
  *
27
27
  * ```ts
28
28
  * Agent({ id: "assistant" }).mcp({
@@ -32,7 +32,7 @@ export class McpError extends Error {
32
32
  * tools: {
33
33
  * "*": { enabled: false },
34
34
  * search_issues: { enabled: true },
35
- * create_issue: { enabled: true, approval: "always" },
35
+ * create_issue: { enabled: true },
36
36
  * },
37
37
  * },
38
38
  * })
@@ -60,10 +60,12 @@ export function normalizeMcpServers(servers, caller = "mcp()") {
60
60
  const server = isRecord(spec) && spec.name === undefined ? { ...spec, name: key } : spec;
61
61
  if (isRecord(server) && server.type === "stdio")
62
62
  throw new McpError("mcp.stdio", stdioMcpRefusal(key));
63
+ if (isRecord(server) && setsApproval(server))
64
+ throw new McpError("mcp.approval-removed", `MCP server '${key}': ${APPROVAL_REMOVED}`);
63
65
  if (!isMcpServer(server)) {
64
66
  throw new McpError("mcp.invalid-server", `MCP server '${key}' is not a valid streamable-http or sse declaration` +
65
67
  (isRecord(server) && (server.tools !== undefined || server.deferred !== undefined)
66
- ? ": deferred is a boolean, and tools maps tool names to { enabled?, approval?, deferred? }"
68
+ ? ": deferred is a boolean, and tools maps tool names to { enabled?, deferred? }"
67
69
  : ""));
68
70
  }
69
71
  if (server.name !== key) {
@@ -117,7 +119,6 @@ function freezeServer(server) {
117
119
  ...(server.headers === undefined
118
120
  ? {}
119
121
  : { headers: Object.freeze({ ...server.headers }) }),
120
- ...(server.approval === undefined ? {} : { approval: server.approval }),
121
122
  ...(server.deferred === undefined ? {} : { deferred: server.deferred }),
122
123
  ...(server.tools === undefined
123
124
  ? {}
@@ -126,7 +127,6 @@ function freezeServer(server) {
126
127
  name,
127
128
  Object.freeze({
128
129
  ...(settings.enabled === undefined ? {} : { enabled: settings.enabled }),
129
- ...(settings.approval === undefined ? {} : { approval: settings.approval }),
130
130
  ...(settings.deferred === undefined ? {} : { deferred: settings.deferred }),
131
131
  }),
132
132
  ]))),
@@ -139,20 +139,23 @@ function isMcpServer(value) {
139
139
  if (value.type === "streamable-http" || value.type === "sse")
140
140
  return (typeof value.url === "string" &&
141
141
  value.url.length > 0 &&
142
- (value.approval === undefined || isApprovalMode(value.approval)) &&
143
142
  (value.deferred === undefined || typeof value.deferred === "boolean") &&
144
143
  (value.tools === undefined || isToolSettingsMap(value.tools)));
145
144
  return false;
146
145
  }
147
- const isApprovalMode = (value) => APPROVAL_MODES.includes(value);
146
+ /** A server, or one of its tools' settings, that sets `approval` (removed in R5 step 2). */
147
+ function setsApproval(server) {
148
+ if (server.approval !== undefined)
149
+ return true;
150
+ return isRecord(server.tools) && Object.values(server.tools).some((settings) => isRecord(settings) && settings.approval !== undefined);
151
+ }
148
152
  function isToolSettingsMap(value) {
149
153
  if (!isRecord(value))
150
154
  return false;
151
155
  return Object.entries(value).every(([name, settings]) => name.length > 0 &&
152
156
  isRecord(settings) &&
153
- Object.keys(settings).every((key) => key === "enabled" || key === "approval" || key === "deferred") &&
157
+ Object.keys(settings).every((key) => key === "enabled" || key === "deferred") &&
154
158
  (settings.enabled === undefined || typeof settings.enabled === "boolean") &&
155
- (settings.approval === undefined || isApprovalMode(settings.approval)) &&
156
159
  (settings.deferred === undefined || typeof settings.deferred === "boolean"));
157
160
  }
158
161
  function isRecord(value) {
@@ -4,7 +4,7 @@
4
4
  * during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
5
5
  */
6
6
  export const REMOVED_CAPABILITY_FIELDS = Object.freeze({
7
- hooks: "hooks were removed: the Runtime no longer calls your code during a session. Use an HTTP tool, approval on a tool, or a loop verifier instead (see MIGRATION.md)",
7
+ hooks: "hooks were removed: the Runtime runs agents from their manifests alone. Use an HTTP tool, approval on a tool, or a loop verifier instead (see MIGRATION.md)",
8
8
  beforeModelCall: "beforeModelCall was removed with hooks (see MIGRATION.md)",
9
9
  afterModelCall: "afterModelCall was removed with hooks (see MIGRATION.md)",
10
10
  model: "A capability must not include model; the Runtime owns model resolution",
@@ -2,7 +2,7 @@ import type { AgentManifest } from "../types/manifest.js";
2
2
  /**
3
3
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned
4
4
  * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
5
- * server's tools or require their approval (R2b C9, Q18);
5
+ * server's tools (R2b C9, Q18);
6
6
  * code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
7
7
  */
8
8
  export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
@@ -29,17 +29,18 @@ function removeOnlySkills(pinned, candidate) {
29
29
  }
30
30
  /**
31
31
  * One tool setting, or the `"*"` entry, only tightened (R2b C9, Q18): `enabled` kept or set to
32
- * `false`, `approval` kept or set to `always`, `deferred` kept. Each level of a tool's resolution
33
- * (its entry, then `"*"`) either keeps its value or tightens it, so the tool does too.
32
+ * `false`, `approval` and `deferred` kept. Each level of a tool's resolution (its entry, then
33
+ * `"*"`) either keeps its value or tightens it, so the tool does too. A variant adds no
34
+ * approval: tool approvals are the Tenant's tool policy (R5 step 2).
34
35
  */
35
36
  function tightensSettings(prior, next) {
36
37
  return ((next.enabled === prior?.enabled || next.enabled === false) &&
37
- (next.approval === prior?.approval || next.approval === "always") &&
38
+ next.approval === prior?.approval &&
38
39
  next.deferred === prior?.deferred);
39
40
  }
40
41
  /**
41
42
  * The servers of a turn variant: the pinned ones, the same but for their `tools` maps, where a
42
- * variant may only disable a tool or require its approval (R2b C9, Q18). An entry the pin has
43
+ * variant may only disable a tool (R2b C9, Q18). An entry the pin has
43
44
  * stays, since dropping one could widen.
44
45
  */
45
46
  function tightensServers(pinned, candidate) {
@@ -64,7 +65,7 @@ function tightensServers(pinned, candidate) {
64
65
  /**
65
66
  * Whether `candidate` is a valid turn-manifest variant of the session's pinned
66
67
  * manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
67
- * server's tools or require their approval (R2b C9, Q18);
68
+ * server's tools (R2b C9, Q18);
68
69
  * code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
69
70
  */
70
71
  export function isVariantOf(candidate, pinned) {
@@ -0,0 +1,241 @@
1
+ /**
2
+ * What a harness writes into the session's record besides its effects (R4.5): transcript
3
+ * entries, and the effect id rule replays depend on.
4
+ *
5
+ * Transcript. A session's transcript is shared by every turn: a run reads it once
6
+ * (`transcript.read`), and its output edits it (`TurnOutput.transcript`, a list of
7
+ * `TranscriptUpdate`s whose `entries` are `TranscriptEntry`s). History, `transcript.read` and the
8
+ * next turn's cursor fold these edits, so a harness writes the five published kinds only.
9
+ *
10
+ * Effect ids. Core hands a run the completed outcomes of its segment whose effect id starts with
11
+ * `<turnId>:<segment>:`, and a harness replays them instead of calling again. An id must be
12
+ * derived from stable names, never call order, so a run that starts over asks for the same ids.
13
+ */
14
+ import { z } from "zod";
15
+ /** One block of a model candidate's output. */
16
+ export declare const ModelOutputBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
17
+ type: z.ZodLiteral<"text">;
18
+ text: z.ZodString;
19
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"reasoning">;
22
+ text: z.ZodString;
23
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<"json">;
26
+ value: z.ZodUnknown;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ type: z.ZodLiteral<"tool-call">;
29
+ id: z.ZodString;
30
+ name: z.ZodString;
31
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
32
+ raw: z.ZodOptional<z.ZodString>;
33
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ }, z.core.$strip>], "type">;
35
+ /** A model's answer: what the Model Gate's `outcome` is when the call worked. */
36
+ export declare const ModelCandidateSchema: z.ZodObject<{
37
+ output: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
38
+ type: z.ZodLiteral<"text">;
39
+ text: z.ZodString;
40
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
+ }, z.core.$strip>, z.ZodObject<{
42
+ type: z.ZodLiteral<"reasoning">;
43
+ text: z.ZodString;
44
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"json">;
47
+ value: z.ZodUnknown;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ type: z.ZodLiteral<"tool-call">;
50
+ id: z.ZodString;
51
+ name: z.ZodString;
52
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
53
+ raw: z.ZodOptional<z.ZodString>;
54
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
55
+ }, z.core.$strip>], "type">>;
56
+ finishReason: z.ZodOptional<z.ZodEnum<{
57
+ "content-filter": "content-filter";
58
+ length: "length";
59
+ other: "other";
60
+ stop: "stop";
61
+ "tool-calls": "tool-calls";
62
+ }>>;
63
+ usage: z.ZodOptional<z.ZodObject<{
64
+ inputTokens: z.ZodOptional<z.ZodNumber>;
65
+ outputTokens: z.ZodOptional<z.ZodNumber>;
66
+ totalTokens: z.ZodOptional<z.ZodNumber>;
67
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
68
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
69
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
70
+ costUsd: z.ZodOptional<z.ZodNumber>;
71
+ }, z.core.$strip>>;
72
+ evidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ }, z.core.$strip>;
74
+ /** One tool call's result, as the model sees it next. */
75
+ export declare const ToolResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
76
+ callId: z.ZodString;
77
+ toolName: z.ZodString;
78
+ kind: z.ZodLiteral<"completed">;
79
+ output: z.ZodUnknown;
80
+ files: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ callId: z.ZodString;
83
+ toolName: z.ZodString;
84
+ kind: z.ZodLiteral<"denied">;
85
+ reason: z.ZodString;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ callId: z.ZodString;
88
+ toolName: z.ZodString;
89
+ kind: z.ZodLiteral<"failed">;
90
+ code: z.ZodString;
91
+ message: z.ZodString;
92
+ details: z.ZodOptional<z.ZodUnknown>;
93
+ retryable: z.ZodOptional<z.ZodBoolean>;
94
+ }, z.core.$strip>], "kind">;
95
+ /** What started a turn: a user message (text or content parts), or an answer to a question. */
96
+ export declare const InputEventSchema: z.ZodUnion<readonly [z.ZodObject<{
97
+ kind: z.ZodEnum<{
98
+ interrupt: "interrupt";
99
+ "user-message": "user-message";
100
+ }>;
101
+ text: z.ZodString;
102
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
103
+ }, z.core.$strip>, z.ZodObject<{
104
+ kind: z.ZodEnum<{
105
+ interrupt: "interrupt";
106
+ "user-message": "user-message";
107
+ }>;
108
+ content: z.ZodArray<z.ZodUnknown>;
109
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ kind: z.ZodLiteral<"approve">;
112
+ interactionId: z.ZodString;
113
+ approved: z.ZodBoolean;
114
+ }, z.core.$strip>, z.ZodObject<{
115
+ kind: z.ZodLiteral<"respond">;
116
+ interactionId: z.ZodString;
117
+ value: z.ZodUnknown;
118
+ }, z.core.$strip>]>;
119
+ /**
120
+ * One transcript entry. Every entry names its turn; a step's entries share a `stepId` (the model
121
+ * candidate, then its tools' results). `compaction` is always first: a summary that replaced the
122
+ * older part, followed by the kept tail.
123
+ */
124
+ export declare const TranscriptEntrySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
125
+ kind: z.ZodLiteral<"input">;
126
+ turnId: z.ZodString;
127
+ event: z.ZodUnion<readonly [z.ZodObject<{
128
+ kind: z.ZodEnum<{
129
+ interrupt: "interrupt";
130
+ "user-message": "user-message";
131
+ }>;
132
+ text: z.ZodString;
133
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
134
+ }, z.core.$strip>, z.ZodObject<{
135
+ kind: z.ZodEnum<{
136
+ interrupt: "interrupt";
137
+ "user-message": "user-message";
138
+ }>;
139
+ content: z.ZodArray<z.ZodUnknown>;
140
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ kind: z.ZodLiteral<"approve">;
143
+ interactionId: z.ZodString;
144
+ approved: z.ZodBoolean;
145
+ }, z.core.$strip>, z.ZodObject<{
146
+ kind: z.ZodLiteral<"respond">;
147
+ interactionId: z.ZodString;
148
+ value: z.ZodUnknown;
149
+ }, z.core.$strip>]>;
150
+ }, z.core.$strip>, z.ZodObject<{
151
+ kind: z.ZodLiteral<"candidate">;
152
+ turnId: z.ZodString;
153
+ stepId: z.ZodString;
154
+ candidate: z.ZodObject<{
155
+ output: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
156
+ type: z.ZodLiteral<"text">;
157
+ text: z.ZodString;
158
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
159
+ }, z.core.$strip>, z.ZodObject<{
160
+ type: z.ZodLiteral<"reasoning">;
161
+ text: z.ZodString;
162
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
163
+ }, z.core.$strip>, z.ZodObject<{
164
+ type: z.ZodLiteral<"json">;
165
+ value: z.ZodUnknown;
166
+ }, z.core.$strip>, z.ZodObject<{
167
+ type: z.ZodLiteral<"tool-call">;
168
+ id: z.ZodString;
169
+ name: z.ZodString;
170
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
171
+ raw: z.ZodOptional<z.ZodString>;
172
+ providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
173
+ }, z.core.$strip>], "type">>;
174
+ finishReason: z.ZodOptional<z.ZodEnum<{
175
+ "content-filter": "content-filter";
176
+ length: "length";
177
+ other: "other";
178
+ stop: "stop";
179
+ "tool-calls": "tool-calls";
180
+ }>>;
181
+ usage: z.ZodOptional<z.ZodObject<{
182
+ inputTokens: z.ZodOptional<z.ZodNumber>;
183
+ outputTokens: z.ZodOptional<z.ZodNumber>;
184
+ totalTokens: z.ZodOptional<z.ZodNumber>;
185
+ cachedTokens: z.ZodOptional<z.ZodNumber>;
186
+ cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
187
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
188
+ costUsd: z.ZodOptional<z.ZodNumber>;
189
+ }, z.core.$strip>>;
190
+ evidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>, z.ZodObject<{
193
+ kind: z.ZodLiteral<"tool-results">;
194
+ turnId: z.ZodString;
195
+ stepId: z.ZodString;
196
+ results: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
197
+ callId: z.ZodString;
198
+ toolName: z.ZodString;
199
+ kind: z.ZodLiteral<"completed">;
200
+ output: z.ZodUnknown;
201
+ files: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
202
+ }, z.core.$strip>, z.ZodObject<{
203
+ callId: z.ZodString;
204
+ toolName: z.ZodString;
205
+ kind: z.ZodLiteral<"denied">;
206
+ reason: z.ZodString;
207
+ }, z.core.$strip>, z.ZodObject<{
208
+ callId: z.ZodString;
209
+ toolName: z.ZodString;
210
+ kind: z.ZodLiteral<"failed">;
211
+ code: z.ZodString;
212
+ message: z.ZodString;
213
+ details: z.ZodOptional<z.ZodUnknown>;
214
+ retryable: z.ZodOptional<z.ZodBoolean>;
215
+ }, z.core.$strip>], "kind">>;
216
+ }, z.core.$strip>, z.ZodObject<{
217
+ kind: z.ZodLiteral<"final">;
218
+ turnId: z.ZodString;
219
+ stepId: z.ZodString;
220
+ output: z.ZodUnknown;
221
+ }, z.core.$strip>, z.ZodObject<{
222
+ kind: z.ZodLiteral<"compaction">;
223
+ turnId: z.ZodString;
224
+ stepId: z.ZodString;
225
+ summary: z.ZodString;
226
+ trigger: z.ZodEnum<{
227
+ overflow: "overflow";
228
+ threshold: "threshold";
229
+ }>;
230
+ tokensBefore: z.ZodNumber;
231
+ tokensAfter: z.ZodNumber;
232
+ }, z.core.$strip>], "kind">;
233
+ /** The prefix every effect id of a segment carries. */
234
+ export declare function effectIdPrefix(turnId: string, segment: number): string;
235
+ /**
236
+ * An effect's id: `<turnId>:<segment>:<kind>:<identity>`, where `identity` names the effect
237
+ * stably within the segment (the model step's invocation id, a tool call's id).
238
+ */
239
+ export declare function effectIdOf(turnId: string, segment: number, kind: string, identity: string): string;
240
+ /** True when `effectId` is one of the segment's, so core replays its outcome to the segment. */
241
+ export declare function isEffectIdOf(effectId: string, turnId: string, segment: number): boolean;