@tangle-network/agent-runtime 0.92.1 → 0.93.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -69,22 +69,32 @@ const result = await supervise(
69
69
  ### Improve an agent
70
70
 
71
71
  `improve` optimizes one part of an agent and **only ships a change if it beats the current agent on tasks it never practiced on**.
72
- It accepts prompt, skill document, tool, MCP, hook, subagent, workflow, rollout-policy, whole-profile, and code surfaces through one call.
73
- Prompt and skill-document optimization have built-in generators; structured surfaces take an explicit generator, and code runs from isolated incumbent and candidate checkouts.
72
+ It accepts prompt, skill document, curated memory, tool, MCP, hook, subagent, workflow, rollout-policy, whole-profile, and code surfaces through one call.
73
+ Prompt, skill-document, memory, and rollout-policy optimization have built-in generators; structured surfaces take an explicit generator, and code runs from isolated incumbent and candidate checkouts.
74
74
 
75
75
  ```ts
76
76
  import { improve } from '@tangle-network/agent-runtime'
77
77
 
78
78
  const { profile, shipped, lift } = await improve(baseProfile, findings, {
79
- surface: 'prompt', // or skills/tools/mcp/hooks/subagents/workflow/agent-profile/code
79
+ surface: 'prompt', // or skills/memory/tools/mcp/hooks/subagents/workflow/agent-profile/rollout-policy/code
80
80
  gate: 'holdout', // certified on a held-back exam, never the practice set
81
81
  scenarios, judge, agent, // how to measure a candidate
82
82
  })
83
83
  ```
84
84
 
85
+ Curated memory is an external lesson document, not a knowledge store. Supply its current text and persist only the promoted winner:
86
+
87
+ ```ts
88
+ await improve(baseProfile, findings, {
89
+ surface: 'memory',
90
+ memory: { document: currentLessons, writeBack: saveLessons },
91
+ scenarios, judge, agent,
92
+ })
93
+ ```
94
+
85
95
  ### Improve a knowledge base
86
96
 
87
- `runKnowledgeImprovementJob` is the runtime-owned front door for KB, wiki, memory-backed, and RAG improvement jobs. It creates a candidate copy, runs supervised agents against it, checks readiness through `@tangle-network/agent-knowledge`, measures spend and timing, and promotes only when the candidate passes.
97
+ `runKnowledgeImprovementJob` is the runtime-owned front door for KB, wiki, memory-backed, and RAG improvement jobs. It creates a candidate copy, runs supervised agents against it, checks readiness through `@tangle-network/agent-knowledge`, measures spend and timing, and promotes only when the candidate passes. Use `improve(..., { surface: 'memory' })` for the agent's curated lesson document; use this job for source, retrieval, and knowledge-store changes.
88
98
 
89
99
  ```ts
90
100
  import { runKnowledgeImprovementJob } from '@tangle-network/agent-runtime/knowledge'
@@ -1,8 +1,52 @@
1
- import { $ as PreparedAgentCandidateExecution, i as AgentCandidateExecutionClaim, k as AgentCandidateExecutionClaimStore, j as AgentCandidateExecutionClaimResult, h as AgentCandidateExecutionAttemptRef, g as AgentCandidateExecutionAttemptRecord, o as AgentCandidateExecutionLease, q as AgentCandidateExecutionPhaseResult, u as AgentCandidateExecutionTerminalResult, s as AgentCandidateExecutionStageResult, n as AgentCandidateExecutionFinishResult, r as AgentCandidateExecutionRecoveryEvidence, L as AgentCandidateOutputArtifactPort, M as AgentCandidateOutputPurpose, K as AgentCandidateModelPort, Q as AgentCandidateProtectedModelReservation, N as AgentCandidateProtectedModelActivation, R as AgentCandidateProtectedModelSettlement, y as AgentCandidateExecutorPort, a as AgentCandidateExecutionPorts, V as AgentCandidateVerificationPorts, a4 as VerifiedAgentCandidate } from '../prepare-Z08a4heC.js';
2
- export { c as AgentCandidateArtifactPort, d as AgentCandidateBenchmarkGraderIdentity, e as AgentCandidateBenchmarkGraderPort, f as AgentCandidateContainerPort, l as AgentCandidateExecutionCleanupHandles, m as AgentCandidateExecutionFailureClass, p as AgentCandidateExecutionPhase, t as AgentCandidateExecutionTerminalRecord, v as AgentCandidateExecutionUsage, w as AgentCandidateExecutorFinalCapture, x as AgentCandidateExecutorMemoryCapture, z as AgentCandidateExecutorProfileFile, B as AgentCandidateExecutorRequest, C as AgentCandidateExecutorStopRequest, D as AgentCandidateExecutorTaskOutcomeCapture, F as AgentCandidateExecutorWorkspaceFile, G as AgentCandidateExecutorWorkspaceInput, H as AgentCandidateMemoryPort, I as AgentCandidateMemoryResetResult, J as AgentCandidateModelLimits, O as AgentCandidateProtectedModelCall, S as AgentCandidateProtectedRunCapture, T as AgentCandidateRepositoryPort, U as AgentCandidateRetryRejection, b as AgentCandidateRunFinalization, A as AgentCandidateTaskExecution, W as AgentCandidateWorkspacePort, X as CANDIDATE_TRACE_ENV, Y as CANDIDATE_TRACE_TAGS, Z as CanonicalCandidateDocument, E as ExecutePreparedAgentCandidateOptions, _ as InMemoryAgentCandidateExecutionClaimStore, P as PrepareAgentCandidateExecutionOptions, a0 as PreparedAgentCandidateInstruction, a1 as PreparedAgentCandidateLaunch, a2 as PreparedAgentCandidateTrace, a3 as ResolvedAgentCandidateContainer, a5 as VerifiedAgentCandidateTaskOutcome, a6 as executePreparedAgentCandidate, a7 as prepareAgentCandidateExecution } from '../prepare-Z08a4heC.js';
3
- import { Sha256Digest, AgentCandidateArtifactRef } from '@tangle-network/agent-interface';
1
+ import { CodeSurface } from '@tangle-network/agent-eval/campaign';
2
+ import { AgentCandidateCodeDisabled, AgentCandidateCodeNoOp, AgentCandidateGitHubRepository, AgentProfile, AgentProfileDiff, AgentCandidateProfile, AgentCandidateExecution, AgentCandidateKnowledge, AgentCandidateMemoryPolicy, AgentCandidateLineage, Sha256Digest, AgentCandidateArtifactRef } from '@tangle-network/agent-interface';
3
+ import { a9 as sealAgentCandidateBundle, a0 as PreparedAgentCandidateExecution, j as AgentCandidateExecutionClaim, l as AgentCandidateExecutionClaimStore, k as AgentCandidateExecutionClaimResult, i as AgentCandidateExecutionAttemptRef, h as AgentCandidateExecutionAttemptRecord, p as AgentCandidateExecutionLease, r as AgentCandidateExecutionPhaseResult, v as AgentCandidateExecutionTerminalResult, t as AgentCandidateExecutionStageResult, o as AgentCandidateExecutionFinishResult, s as AgentCandidateExecutionRecoveryEvidence, M as AgentCandidateOutputArtifactPort, N as AgentCandidateOutputPurpose, L as AgentCandidateModelPort, R as AgentCandidateProtectedModelReservation, O as AgentCandidateProtectedModelActivation, S as AgentCandidateProtectedModelSettlement, z as AgentCandidateExecutorPort, a as AgentCandidateExecutionPorts, W as AgentCandidateVerificationPorts, a5 as VerifiedAgentCandidate } from '../prepare-DiVGKcwS.js';
4
+ export { d as AgentCandidateArtifactPort, e as AgentCandidateBenchmarkGraderIdentity, f as AgentCandidateBenchmarkGraderPort, c as AgentCandidateBundleInput, g as AgentCandidateContainerPort, m as AgentCandidateExecutionCleanupHandles, n as AgentCandidateExecutionFailureClass, q as AgentCandidateExecutionPhase, u as AgentCandidateExecutionTerminalRecord, w as AgentCandidateExecutionUsage, x as AgentCandidateExecutorFinalCapture, y as AgentCandidateExecutorMemoryCapture, B as AgentCandidateExecutorProfileFile, C as AgentCandidateExecutorRequest, D as AgentCandidateExecutorStopRequest, F as AgentCandidateExecutorTaskOutcomeCapture, G as AgentCandidateExecutorWorkspaceFile, H as AgentCandidateExecutorWorkspaceInput, I as AgentCandidateMemoryPort, J as AgentCandidateMemoryResetResult, K as AgentCandidateModelLimits, Q as AgentCandidateProtectedModelCall, T as AgentCandidateProtectedRunCapture, U as AgentCandidateRepositoryPort, V as AgentCandidateRetryRejection, b as AgentCandidateRunFinalization, A as AgentCandidateTaskExecution, X as AgentCandidateWorkspacePort, Y as CANDIDATE_TRACE_ENV, Z as CANDIDATE_TRACE_TAGS, _ as CanonicalCandidateDocument, E as ExecutePreparedAgentCandidateOptions, $ as InMemoryAgentCandidateExecutionClaimStore, P as PrepareAgentCandidateExecutionOptions, a1 as PreparedAgentCandidateInstruction, a2 as PreparedAgentCandidateLaunch, a3 as PreparedAgentCandidateTrace, a4 as ResolvedAgentCandidateContainer, a6 as VerifiedAgentCandidateTaskOutcome, a7 as executePreparedAgentCandidate, a8 as prepareAgentCandidateExecution } from '../prepare-DiVGKcwS.js';
4
5
  import { TraceStore } from '@tangle-network/agent-eval';
5
6
 
7
+ /** A complete profile that can be frozen without losing behavior. */
8
+ type AgentCandidateProfileSource = {
9
+ kind: 'profile';
10
+ profile: AgentProfile;
11
+ } | {
12
+ kind: 'profile-diffs';
13
+ base: AgentProfile;
14
+ /** Applied in order. Each exact diff is content-addressed into lineage. */
15
+ diffs: readonly AgentProfileDiff[];
16
+ } | {
17
+ kind: 'candidate-profile';
18
+ /** Already converted to the closed, secret-free candidate profile contract. */
19
+ profile: AgentCandidateProfile;
20
+ };
21
+ /** The only accepted path from an agent-eval code candidate to executable bytes. */
22
+ interface AgentCandidateCodeSurfaceSource {
23
+ kind: 'code-surface';
24
+ surface: CodeSurface;
25
+ repository: AgentCandidateGitHubRepository;
26
+ /** Optional parent directory used to resolve a relative `surface.worktreeRef`. */
27
+ worktreeDir?: string;
28
+ }
29
+ /** Explicit control/no-op code or one finalized CodeSurface whose bytes must still verify. */
30
+ type AgentCandidateCodeSource = AgentCandidateCodeDisabled | AgentCandidateCodeNoOp | AgentCandidateCodeSurfaceSource;
31
+ /** Complete measured surfaces and execution policy compiled into one candidate bundle. */
32
+ interface BuildAgentCandidateBundleInput {
33
+ profile: AgentCandidateProfileSource;
34
+ code: AgentCandidateCodeSource;
35
+ execution: AgentCandidateExecution;
36
+ knowledge?: AgentCandidateKnowledge;
37
+ memory: AgentCandidateMemoryPolicy;
38
+ /** `profileDiffIds` is derived from `profile`; callers cannot contradict it. */
39
+ lineage: Omit<AgentCandidateLineage, 'profileDiffIds'>;
40
+ }
41
+ /**
42
+ * Compile one measured profile/code candidate into the immutable execution
43
+ * contract. Code bytes are re-read and verified by agent-eval before they are
44
+ * embedded. The returned bundle is schema-validated, canonically digested, and
45
+ * deeply immutable; call `verifyAgentCandidateBundle` at the execution boundary
46
+ * to re-read external knowledge, memory, repository, and workspace artifacts.
47
+ */
48
+ declare function buildAgentCandidateBundle(input: BuildAgentCandidateBundleInput): ReturnType<typeof sealAgentCandidateBundle>;
49
+
6
50
  /** Extract the complete durable claim from a prepared execution. */
7
51
  declare function candidateExecutionClaim(prepared: PreparedAgentCandidateExecution): AgentCandidateExecutionClaim;
8
52
 
@@ -101,4 +145,4 @@ declare function recoverExpiredAgentCandidateExecution(options: RecoverExpiredAg
101
145
  /** Verifies every digest, resource, workspace, and Git object in a candidate bundle. */
102
146
  declare function verifyAgentCandidateBundle(input: unknown, ports: AgentCandidateVerificationPorts): Promise<VerifiedAgentCandidate>;
103
147
 
104
- export { AgentCandidateExecutionAttemptRecord, AgentCandidateExecutionAttemptRef, AgentCandidateExecutionClaim, AgentCandidateExecutionClaimResult, AgentCandidateExecutionClaimStore, AgentCandidateExecutionFinishResult, AgentCandidateExecutionLease, AgentCandidateExecutionPhaseResult, AgentCandidateExecutionPorts, AgentCandidateExecutionRecoveryEvidence, AgentCandidateExecutionStageResult, AgentCandidateExecutionTerminalResult, AgentCandidateExecutorPort, type AgentCandidateModelGrantActivateInput, type AgentCandidateModelGrantClient, type AgentCandidateModelGrantReservation, type AgentCandidateModelGrantReserveInput, type AgentCandidateModelGrantSettleInput, AgentCandidateModelPort, AgentCandidateOutputArtifactPort, AgentCandidateOutputPurpose, AgentCandidateProtectedModelActivation, AgentCandidateProtectedModelReservation, AgentCandidateProtectedModelSettlement, AgentCandidateVerificationPorts, type CreateProtectedAgentCandidateModelPortOptions, type DisposePreparedAgentCandidateOptions, FileAgentCandidateExecutionClaimStore, type FileAgentCandidateExecutionClaimStoreOptions, PreparedAgentCandidateExecution, type RecoverExpiredAgentCandidateOptions, VerifiedAgentCandidate, candidateExecutionClaim, createProtectedAgentCandidateModelPort, disposePreparedAgentCandidateExecution, persistCandidateOutputArtifact, recoverExpiredAgentCandidateExecution, verifyAgentCandidateBundle };
148
+ export { type AgentCandidateCodeSource, type AgentCandidateCodeSurfaceSource, AgentCandidateExecutionAttemptRecord, AgentCandidateExecutionAttemptRef, AgentCandidateExecutionClaim, AgentCandidateExecutionClaimResult, AgentCandidateExecutionClaimStore, AgentCandidateExecutionFinishResult, AgentCandidateExecutionLease, AgentCandidateExecutionPhaseResult, AgentCandidateExecutionPorts, AgentCandidateExecutionRecoveryEvidence, AgentCandidateExecutionStageResult, AgentCandidateExecutionTerminalResult, AgentCandidateExecutorPort, type AgentCandidateModelGrantActivateInput, type AgentCandidateModelGrantClient, type AgentCandidateModelGrantReservation, type AgentCandidateModelGrantReserveInput, type AgentCandidateModelGrantSettleInput, AgentCandidateModelPort, AgentCandidateOutputArtifactPort, AgentCandidateOutputPurpose, type AgentCandidateProfileSource, AgentCandidateProtectedModelActivation, AgentCandidateProtectedModelReservation, AgentCandidateProtectedModelSettlement, AgentCandidateVerificationPorts, type BuildAgentCandidateBundleInput, type CreateProtectedAgentCandidateModelPortOptions, type DisposePreparedAgentCandidateOptions, FileAgentCandidateExecutionClaimStore, type FileAgentCandidateExecutionClaimStoreOptions, PreparedAgentCandidateExecution, type RecoverExpiredAgentCandidateOptions, VerifiedAgentCandidate, buildAgentCandidateBundle, candidateExecutionClaim, createProtectedAgentCandidateModelPort, disposePreparedAgentCandidateExecution, persistCandidateOutputArtifact, recoverExpiredAgentCandidateExecution, sealAgentCandidateBundle, verifyAgentCandidateBundle };
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  FileAgentCandidateExecutionClaimStore,
3
+ buildAgentCandidateBundle,
3
4
  createProtectedAgentCandidateModelPort,
4
5
  disposePreparedAgentCandidateExecution,
5
6
  recoverExpiredAgentCandidateExecution
6
- } from "../chunk-PH65PR4F.js";
7
+ } from "../chunk-XDSWWUKE.js";
7
8
  import {
8
9
  CANDIDATE_TRACE_ENV,
9
10
  CANDIDATE_TRACE_TAGS,
@@ -12,8 +13,9 @@ import {
12
13
  executePreparedAgentCandidate,
13
14
  persistCandidateOutputArtifact,
14
15
  prepareAgentCandidateExecution,
16
+ sealAgentCandidateBundle,
15
17
  verifyAgentCandidateBundle
16
- } from "../chunk-A62TP7SK.js";
18
+ } from "../chunk-OX3QRJOA.js";
17
19
  import "../chunk-3D2RHC4K.js";
18
20
  import "../chunk-3MDZX7YU.js";
19
21
  import "../chunk-DGUM43GV.js";
@@ -22,6 +24,7 @@ export {
22
24
  CANDIDATE_TRACE_TAGS,
23
25
  FileAgentCandidateExecutionClaimStore,
24
26
  InMemoryAgentCandidateExecutionClaimStore,
27
+ buildAgentCandidateBundle,
25
28
  candidateExecutionClaim,
26
29
  createProtectedAgentCandidateModelPort,
27
30
  disposePreparedAgentCandidateExecution,
@@ -29,6 +32,7 @@ export {
29
32
  persistCandidateOutputArtifact,
30
33
  prepareAgentCandidateExecution,
31
34
  recoverExpiredAgentCandidateExecution,
35
+ sealAgentCandidateBundle,
32
36
  verifyAgentCandidateBundle
33
37
  };
34
38
  //# sourceMappingURL=index.js.map
@@ -2,39 +2,8 @@ import {
2
2
  contentAddress
3
3
  } from "./chunk-3D2RHC4K.js";
4
4
 
5
- // src/candidate-execution/types.ts
6
- var verifiedCandidateBrand = /* @__PURE__ */ Symbol("verifiedAgentCandidate");
7
- var preparedCandidateBrand = /* @__PURE__ */ Symbol("preparedAgentCandidate");
8
- var verifiedTaskOutcomeBrand = /* @__PURE__ */ Symbol("verifiedTaskOutcome");
9
- var CANDIDATE_TRACE_TAGS = {
10
- executionId: "tangle.candidate.execution_id",
11
- bundleDigest: "tangle.candidate.bundle_digest",
12
- executionPlanDigest: "tangle.candidate.execution_plan_digest",
13
- materializationReceiptDigest: "tangle.candidate.materialization_receipt_digest"
14
- };
15
- var CANDIDATE_TRACE_ENV = {
16
- executionId: "TANGLE_CANDIDATE_EXECUTION_ID",
17
- bundleDigest: "TANGLE_CANDIDATE_BUNDLE_DIGEST",
18
- executionPlanDigest: "TANGLE_CANDIDATE_EXECUTION_PLAN_DIGEST",
19
- materializationReceiptDigest: "TANGLE_CANDIDATE_MATERIALIZATION_RECEIPT_DIGEST",
20
- traceRunId: "TANGLE_TRACE_RUN_ID"
21
- };
22
-
23
- // src/candidate-execution/claim.ts
24
- import { createHash as createHash2, randomBytes, timingSafeEqual } from "crypto";
25
- import { readFile } from "fs/promises";
26
- import {
27
- agentCandidateResolvedModelSchema
28
- } from "@tangle-network/agent-interface";
29
-
30
- // src/candidate-execution/claim-file-formats.ts
31
- var CLAIM_FORMAT_VERSION = 7;
32
- var PENDING_FORMAT_VERSION = 1;
33
- var TERMINAL_FORMAT_VERSION = 3;
34
- var PHASE_FORMAT_VERSION = 1;
35
-
36
- // src/candidate-execution/claim-terminal.ts
37
- import { agentCandidateArtifactRefSchema } from "@tangle-network/agent-interface";
5
+ // src/candidate-execution/bundle.ts
6
+ import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
38
7
 
39
8
  // src/candidate-execution/digest.ts
40
9
  import { createHash } from "crypto";
@@ -92,6 +61,51 @@ function deepFreezeCandidate(value, seen = /* @__PURE__ */ new Set()) {
92
61
  return Object.freeze(value);
93
62
  }
94
63
 
64
+ // src/candidate-execution/bundle.ts
65
+ function sealAgentCandidateBundle(input) {
66
+ const digest = canonicalCandidateDigest(input);
67
+ const parsed = agentCandidateBundleSchema.parse({ ...input, digest });
68
+ const parsedDigest = canonicalCandidateDigest(omitTopLevelDigest(parsed));
69
+ if (parsedDigest !== digest) {
70
+ throw new Error("candidate bundle changed while validating its canonical wire shape");
71
+ }
72
+ return immutableCandidateValue(parsed);
73
+ }
74
+
75
+ // src/candidate-execution/types.ts
76
+ var verifiedCandidateBrand = /* @__PURE__ */ Symbol("verifiedAgentCandidate");
77
+ var preparedCandidateBrand = /* @__PURE__ */ Symbol("preparedAgentCandidate");
78
+ var verifiedTaskOutcomeBrand = /* @__PURE__ */ Symbol("verifiedTaskOutcome");
79
+ var CANDIDATE_TRACE_TAGS = {
80
+ executionId: "tangle.candidate.execution_id",
81
+ bundleDigest: "tangle.candidate.bundle_digest",
82
+ executionPlanDigest: "tangle.candidate.execution_plan_digest",
83
+ materializationReceiptDigest: "tangle.candidate.materialization_receipt_digest"
84
+ };
85
+ var CANDIDATE_TRACE_ENV = {
86
+ executionId: "TANGLE_CANDIDATE_EXECUTION_ID",
87
+ bundleDigest: "TANGLE_CANDIDATE_BUNDLE_DIGEST",
88
+ executionPlanDigest: "TANGLE_CANDIDATE_EXECUTION_PLAN_DIGEST",
89
+ materializationReceiptDigest: "TANGLE_CANDIDATE_MATERIALIZATION_RECEIPT_DIGEST",
90
+ traceRunId: "TANGLE_TRACE_RUN_ID"
91
+ };
92
+
93
+ // src/candidate-execution/claim.ts
94
+ import { createHash as createHash2, randomBytes, timingSafeEqual } from "crypto";
95
+ import { readFile } from "fs/promises";
96
+ import {
97
+ agentCandidateResolvedModelSchema
98
+ } from "@tangle-network/agent-interface";
99
+
100
+ // src/candidate-execution/claim-file-formats.ts
101
+ var CLAIM_FORMAT_VERSION = 7;
102
+ var PENDING_FORMAT_VERSION = 1;
103
+ var TERMINAL_FORMAT_VERSION = 3;
104
+ var PHASE_FORMAT_VERSION = 1;
105
+
106
+ // src/candidate-execution/claim-terminal.ts
107
+ import { agentCandidateArtifactRefSchema } from "@tangle-network/agent-interface";
108
+
95
109
  // src/candidate-execution/exact-object.ts
96
110
  function assertExactObjectKeys(value, required, label, optional = []) {
97
111
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -3898,10 +3912,10 @@ var CandidateExecutionDeadlineError = class extends Error {
3898
3912
  };
3899
3913
 
3900
3914
  // src/candidate-execution/verify.ts
3901
- import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
3915
+ import { agentCandidateBundleSchema as agentCandidateBundleSchema2 } from "@tangle-network/agent-interface";
3902
3916
  var verifiedCandidateState = /* @__PURE__ */ new WeakMap();
3903
3917
  async function verifyAgentCandidateBundle(input, ports) {
3904
- const parsed = agentCandidateBundleSchema.parse(input);
3918
+ const parsed = agentCandidateBundleSchema2.parse(input);
3905
3919
  const withoutDigest = omitTopLevelDigest(parsed);
3906
3920
  const actualDigest = canonicalCandidateDigest(withoutDigest);
3907
3921
  if (actualDigest !== parsed.digest) {
@@ -4014,6 +4028,255 @@ import {
4014
4028
  applyAgentCandidateWorkspacePlan,
4015
4029
  materializeCandidateProfile
4016
4030
  } from "@tangle-network/agent-profile-materialize";
4031
+
4032
+ // src/candidate-execution/profile.ts
4033
+ import { agentCandidateProfileSchema, agentProfileSchema } from "@tangle-network/agent-interface";
4034
+ var CANDIDATE_PROFILE_DIRECT_FIELDS = [
4035
+ "name",
4036
+ "description",
4037
+ "version",
4038
+ "tags",
4039
+ "prompt",
4040
+ "harness",
4041
+ "permissions",
4042
+ "tools",
4043
+ "confidential"
4044
+ ];
4045
+ function freezeGenericAgentCandidateProfile(input) {
4046
+ const profile = parseExactAgentProfile(input, "profile");
4047
+ if (profile.connections !== void 0) unsupportedProfileField("connections");
4048
+ if (profile.metadata !== void 0) unsupportedProfileField("metadata");
4049
+ if (profile.extensions !== void 0) unsupportedProfileField("extensions");
4050
+ if (profile.model?.metadata !== void 0) unsupportedProfileField("model.metadata");
4051
+ const candidate = {};
4052
+ copyDirectProfileFields(candidate, profile);
4053
+ if (profile.model) {
4054
+ const { metadata: _metadata, ...model } = profile.model;
4055
+ candidate.model = model;
4056
+ }
4057
+ if (profile.mcp) candidate.mcp = freezeMcpServers(profile.mcp);
4058
+ if (profile.subagents) {
4059
+ candidate.subagents = Object.fromEntries(
4060
+ Object.entries(profile.subagents).map(([name, subagent]) => {
4061
+ if (subagent.metadata !== void 0) unsupportedProfileField(`subagents.${name}.metadata`);
4062
+ const { metadata: _metadata, ...value } = subagent;
4063
+ return [name, value];
4064
+ })
4065
+ );
4066
+ }
4067
+ if (profile.resources) candidate.resources = freezeResources(profile.resources);
4068
+ if (profile.hooks && Object.values(profile.hooks).some((commands) => commands.length > 0)) {
4069
+ throw new Error(
4070
+ "generic AgentProfile hooks cannot be safely tokenized; use a candidate-profile source with executable/args"
4071
+ );
4072
+ }
4073
+ if (profile.hooks) candidate.hooks = profile.hooks;
4074
+ if (profile.modes) {
4075
+ candidate.modes = Object.fromEntries(
4076
+ Object.entries(profile.modes).map(([name, mode]) => {
4077
+ if (mode.metadata !== void 0) unsupportedProfileField(`modes.${name}.metadata`);
4078
+ const { metadata: _metadata, ...value } = mode;
4079
+ return [name, value];
4080
+ })
4081
+ );
4082
+ }
4083
+ const parsed = parseExactCandidateProfile(candidate);
4084
+ assertCandidateProfileBinding(profile, parsed);
4085
+ return parsed;
4086
+ }
4087
+ function assertCandidateProfileBinding(measuredInput, bundled) {
4088
+ const measured = parseExactAgentProfile(measuredInput, "proposal candidate profile");
4089
+ if (measured.connections || measured.metadata || measured.extensions) {
4090
+ throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
4091
+ }
4092
+ const normalized = candidateProfileAsAgentProfile(bundled);
4093
+ if (canonicalCandidateDigest(measured) !== canonicalCandidateDigest(normalized)) {
4094
+ throw new Error("proposal candidateProfile does not match candidateBundle.profile");
4095
+ }
4096
+ }
4097
+ function parseExactAgentProfile(input, label) {
4098
+ const parsed = agentProfileSchema.parse(input);
4099
+ assertCanonicalParse(input, parsed, label);
4100
+ return parsed;
4101
+ }
4102
+ function parseExactCandidateProfile(input) {
4103
+ const parsed = agentCandidateProfileSchema.parse(input);
4104
+ assertCanonicalParse(input, parsed, "candidate profile");
4105
+ return parsed;
4106
+ }
4107
+ function assertCandidateProfileExecutionSupport(profile) {
4108
+ const fields = ["tools", "permissions", "modes", "confidential"];
4109
+ const unsupported = fields.filter((field) => hasEntries(profile[field]));
4110
+ if (unsupported.length > 0) {
4111
+ throw new Error(
4112
+ `candidate execution cannot prove in-session effects for non-empty AgentProfile fields: ${unsupported.join(", ")}`
4113
+ );
4114
+ }
4115
+ }
4116
+ function candidateProfileAsAgentProfile(candidate) {
4117
+ const output = {};
4118
+ copyDirectProfileFields(output, candidate);
4119
+ if (candidate.model) output.model = { ...candidate.model };
4120
+ if (candidate.mcp) {
4121
+ output.mcp = Object.fromEntries(
4122
+ Object.entries(candidate.mcp).map(([name, server]) => [
4123
+ name,
4124
+ {
4125
+ ...server,
4126
+ ...server.args ? { args: server.args.map(publicValue) } : {},
4127
+ ...server.env ? { env: mapPublicValues(server.env) } : {}
4128
+ }
4129
+ ])
4130
+ );
4131
+ }
4132
+ if (candidate.subagents) output.subagents = cloneRecord(candidate.subagents);
4133
+ if (candidate.modes) output.modes = cloneRecord(candidate.modes);
4134
+ if (candidate.hooks) {
4135
+ output.hooks = Object.fromEntries(
4136
+ Object.entries(candidate.hooks).map(([event, hooks]) => [
4137
+ event,
4138
+ hooks.map(({ executable, args, env, ...hook }) => ({
4139
+ ...hook,
4140
+ command: [executable, ...(args ?? []).map(publicValue)].map(shellQuote).join(" "),
4141
+ ...env ? { env: mapPublicValues(env) } : {}
4142
+ }))
4143
+ ])
4144
+ );
4145
+ }
4146
+ if (candidate.resources) {
4147
+ if (candidate.resources.failOnError !== true) {
4148
+ throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
4149
+ }
4150
+ output.resources = {
4151
+ failOnError: true,
4152
+ ...candidate.resources.files ? {
4153
+ files: candidate.resources.files.map((file) => ({
4154
+ ...file,
4155
+ resource: publicResource(file.resource)
4156
+ }))
4157
+ } : {},
4158
+ ...candidate.resources.tools ? { tools: candidate.resources.tools.map(publicResource) } : {},
4159
+ ...candidate.resources.skills ? { skills: candidate.resources.skills.map(publicResource) } : {},
4160
+ ...candidate.resources.agents ? { agents: candidate.resources.agents.map(publicResource) } : {},
4161
+ ...candidate.resources.commands ? { commands: candidate.resources.commands.map(publicResource) } : {},
4162
+ ...candidate.resources.instructions !== void 0 ? {
4163
+ instructions: typeof candidate.resources.instructions === "string" ? candidate.resources.instructions : publicResource(candidate.resources.instructions)
4164
+ } : {}
4165
+ };
4166
+ }
4167
+ return output;
4168
+ }
4169
+ function freezeMcpServers(servers) {
4170
+ return Object.fromEntries(
4171
+ Object.entries(servers).map(([name, server]) => {
4172
+ if (server.transport !== void 0 && server.transport !== "stdio") {
4173
+ unsupportedProfileField(`mcp.${name}.transport=${server.transport}`);
4174
+ }
4175
+ if (server.url !== void 0) unsupportedProfileField(`mcp.${name}.url`);
4176
+ if (server.headers !== void 0) unsupportedProfileField(`mcp.${name}.headers`);
4177
+ if (server.metadata !== void 0) unsupportedProfileField(`mcp.${name}.metadata`);
4178
+ return [
4179
+ name,
4180
+ {
4181
+ ...server.transport ? { transport: server.transport } : {},
4182
+ ...server.command ? { command: server.command } : {},
4183
+ ...server.args ? { args: server.args.map(candidatePublicValue) } : {},
4184
+ ...server.env ? { env: mapCandidatePublicValues(server.env) } : {},
4185
+ ...server.cwd ? { cwd: server.cwd } : {},
4186
+ ...server.enabled === void 0 ? {} : { enabled: server.enabled }
4187
+ }
4188
+ ];
4189
+ })
4190
+ );
4191
+ }
4192
+ function freezeResources(resources) {
4193
+ if (resources.failOnError !== true) {
4194
+ throw new Error("candidate profile resources require failOnError: true");
4195
+ }
4196
+ return {
4197
+ failOnError: true,
4198
+ ...resources.files ? {
4199
+ files: resources.files.map((file) => ({
4200
+ ...file,
4201
+ resource: freezeResource(file.resource)
4202
+ }))
4203
+ } : {},
4204
+ ...resources.tools ? { tools: resources.tools.map(freezeResource) } : {},
4205
+ ...resources.skills ? { skills: resources.skills.map(freezeResource) } : {},
4206
+ ...resources.agents ? { agents: resources.agents.map(freezeResource) } : {},
4207
+ ...resources.commands ? { commands: resources.commands.map(freezeResource) } : {},
4208
+ ...resources.instructions === void 0 ? {} : {
4209
+ instructions: typeof resources.instructions === "string" ? resources.instructions : freezeResource(resources.instructions)
4210
+ }
4211
+ };
4212
+ }
4213
+ function freezeResource(resource) {
4214
+ if (resource.kind === "github") {
4215
+ throw new Error(
4216
+ "generic GitHub profile resources do not carry byte identity; use a candidate-profile source with a pinned commit, digest, and byte length"
4217
+ );
4218
+ }
4219
+ const bytes = Buffer.from(resource.content, "utf8");
4220
+ return {
4221
+ ...resource,
4222
+ sha256: embeddedCandidateArtifact(bytes).sha256,
4223
+ byteLength: bytes.byteLength
4224
+ };
4225
+ }
4226
+ function copyDirectProfileFields(target, source) {
4227
+ for (const key of CANDIDATE_PROFILE_DIRECT_FIELDS) {
4228
+ if (source[key] !== void 0) target[key] = source[key];
4229
+ }
4230
+ }
4231
+ function assertCanonicalParse(input, parsed, label) {
4232
+ if (!Buffer.from(canonicalCandidateBytes(input)).equals(canonicalCandidateBytes(parsed))) {
4233
+ throw new Error(`${label} contains unsupported or non-canonical fields`);
4234
+ }
4235
+ }
4236
+ function publicResource(resource) {
4237
+ if (resource.kind === "inline") {
4238
+ return { kind: "inline", name: resource.name, content: resource.content };
4239
+ }
4240
+ return {
4241
+ kind: "github",
4242
+ repository: `${resource.repository.owner}/${resource.repository.repo}`,
4243
+ path: resource.path,
4244
+ ref: resource.commit,
4245
+ ...resource.name ? { name: resource.name } : {}
4246
+ };
4247
+ }
4248
+ function candidatePublicValue(value) {
4249
+ return { kind: "public", value };
4250
+ }
4251
+ function mapCandidatePublicValues(values) {
4252
+ return Object.fromEntries(
4253
+ Object.entries(values).map(([name, value]) => [name, candidatePublicValue(value)])
4254
+ );
4255
+ }
4256
+ function publicValue(value) {
4257
+ return value.value;
4258
+ }
4259
+ function mapPublicValues(values) {
4260
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, publicValue(value)]));
4261
+ }
4262
+ function cloneRecord(values) {
4263
+ return Object.fromEntries(
4264
+ Object.entries(values).map(([key, value]) => [key, { ...value }])
4265
+ );
4266
+ }
4267
+ function hasEntries(value) {
4268
+ return value !== void 0 && value !== null && typeof value === "object" ? Object.keys(value).length > 0 : false;
4269
+ }
4270
+ function shellQuote(value) {
4271
+ return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
4272
+ }
4273
+ function unsupportedProfileField(path) {
4274
+ throw new Error(
4275
+ `generic AgentProfile field ${path} is not representable in a sealed candidate profile`
4276
+ );
4277
+ }
4278
+
4279
+ // src/candidate-execution/prepare.ts
4017
4280
  var MATERIALIZER_HARNESSES = /* @__PURE__ */ new Set([
4018
4281
  "claude-code",
4019
4282
  "claude",
@@ -4035,6 +4298,7 @@ async function prepareAgentCandidateExecution(candidate, task, ports, options =
4035
4298
  const verifiedState = getVerifiedCandidateState(candidate);
4036
4299
  assertSameVerificationPorts(verifiedState.ports, ports);
4037
4300
  const bundle = candidate.bundle;
4301
+ assertCandidateProfileExecutionSupport(bundle.profile);
4038
4302
  const harness = materializerHarness(bundle.execution.harness);
4039
4303
  assertTaskInput(task, bundle.execution.instructionDelivery);
4040
4304
  const resultTimeoutMs = candidateResultTimeout(options.resultTimeoutMs, task.limits.timeoutMs);
@@ -4740,15 +5004,21 @@ function errorMessage2(error) {
4740
5004
  }
4741
5005
 
4742
5006
  export {
4743
- CLAIM_FORMAT_VERSION,
4744
- PENDING_FORMAT_VERSION,
4745
- TERMINAL_FORMAT_VERSION,
4746
- PHASE_FORMAT_VERSION,
4747
5007
  canonicalCandidateBytes,
4748
5008
  canonicalCandidateDigest,
4749
5009
  immutableCandidateValue,
4750
5010
  canonicalCandidateDocument,
5011
+ embeddedCandidateArtifact,
4751
5012
  omitTopLevelDigest,
5013
+ sealAgentCandidateBundle,
5014
+ freezeGenericAgentCandidateProfile,
5015
+ assertCandidateProfileBinding,
5016
+ parseExactAgentProfile,
5017
+ parseExactCandidateProfile,
5018
+ CLAIM_FORMAT_VERSION,
5019
+ PENDING_FORMAT_VERSION,
5020
+ TERMINAL_FORMAT_VERSION,
5021
+ PHASE_FORMAT_VERSION,
4752
5022
  assertExactObjectKeys,
4753
5023
  terminalRecord,
4754
5024
  recoveredTerminalRecord,
@@ -4781,4 +5051,4 @@ export {
4781
5051
  verifyAgentCandidateBundle,
4782
5052
  prepareAgentCandidateExecution
4783
5053
  };
4784
- //# sourceMappingURL=chunk-A62TP7SK.js.map
5054
+ //# sourceMappingURL=chunk-OX3QRJOA.js.map