@tangle-network/agent-runtime 0.92.1 → 0.93.0
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 +14 -4
- package/dist/candidate-execution/index.d.ts +48 -4
- package/dist/candidate-execution/index.js +6 -2
- package/dist/{chunk-A62TP7SK.js → chunk-26WCEARH.js} +295 -40
- package/dist/chunk-26WCEARH.js.map +1 -0
- package/dist/{chunk-PH65PR4F.js → chunk-3VU2OWOY.js} +106 -2
- package/dist/chunk-3VU2OWOY.js.map +1 -0
- package/dist/{chunk-4FPXIMSI.js → chunk-VMHKMNEU.js} +38 -9
- package/dist/chunk-VMHKMNEU.js.map +1 -0
- package/dist/{improve-CUVCq7xg.d.ts → improve-DDhQaaJT.d.ts} +17 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +6 -8
- package/dist/intelligence.js +23 -131
- package/dist/intelligence.js.map +1 -1
- package/dist/{prepare-Z08a4heC.d.ts → prepare-DiVGKcwS.d.ts} +7 -2
- package/package.json +4 -4
- package/skills/build-with-agent-runtime/SKILL.md +2 -1
- package/dist/chunk-4FPXIMSI.js.map +0 -1
- package/dist/chunk-A62TP7SK.js.map +0 -1
- package/dist/chunk-PH65PR4F.js.map +0 -1
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
|
|
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 {
|
|
2
|
-
|
|
3
|
-
import {
|
|
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-
|
|
7
|
+
} from "../chunk-3VU2OWOY.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-
|
|
18
|
+
} from "../chunk-26WCEARH.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/
|
|
6
|
-
|
|
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 =
|
|
3918
|
+
const parsed = agentCandidateBundleSchema2.parse(input);
|
|
3905
3919
|
const withoutDigest = omitTopLevelDigest(parsed);
|
|
3906
3920
|
const actualDigest = canonicalCandidateDigest(withoutDigest);
|
|
3907
3921
|
if (actualDigest !== parsed.digest) {
|
|
@@ -4739,16 +4753,257 @@ function errorMessage2(error) {
|
|
|
4739
4753
|
return error instanceof Error ? error.message : String(error);
|
|
4740
4754
|
}
|
|
4741
4755
|
|
|
4756
|
+
// src/candidate-execution/profile.ts
|
|
4757
|
+
import { agentCandidateProfileSchema, agentProfileSchema } from "@tangle-network/agent-interface";
|
|
4758
|
+
var CANDIDATE_PROFILE_DIRECT_FIELDS = [
|
|
4759
|
+
"name",
|
|
4760
|
+
"description",
|
|
4761
|
+
"version",
|
|
4762
|
+
"tags",
|
|
4763
|
+
"prompt",
|
|
4764
|
+
"harness",
|
|
4765
|
+
"permissions",
|
|
4766
|
+
"tools",
|
|
4767
|
+
"confidential"
|
|
4768
|
+
];
|
|
4769
|
+
function freezeGenericAgentCandidateProfile(input) {
|
|
4770
|
+
const profile = parseExactAgentProfile(input, "profile");
|
|
4771
|
+
if (profile.connections !== void 0) unsupportedProfileField("connections");
|
|
4772
|
+
if (profile.metadata !== void 0) unsupportedProfileField("metadata");
|
|
4773
|
+
if (profile.extensions !== void 0) unsupportedProfileField("extensions");
|
|
4774
|
+
if (profile.model?.metadata !== void 0) unsupportedProfileField("model.metadata");
|
|
4775
|
+
const candidate = {};
|
|
4776
|
+
copyDirectProfileFields(candidate, profile);
|
|
4777
|
+
if (profile.model) {
|
|
4778
|
+
const { metadata: _metadata, ...model } = profile.model;
|
|
4779
|
+
candidate.model = model;
|
|
4780
|
+
}
|
|
4781
|
+
if (profile.mcp) candidate.mcp = freezeMcpServers(profile.mcp);
|
|
4782
|
+
if (profile.subagents) {
|
|
4783
|
+
candidate.subagents = Object.fromEntries(
|
|
4784
|
+
Object.entries(profile.subagents).map(([name, subagent]) => {
|
|
4785
|
+
if (subagent.metadata !== void 0) unsupportedProfileField(`subagents.${name}.metadata`);
|
|
4786
|
+
const { metadata: _metadata, ...value } = subagent;
|
|
4787
|
+
return [name, value];
|
|
4788
|
+
})
|
|
4789
|
+
);
|
|
4790
|
+
}
|
|
4791
|
+
if (profile.resources) candidate.resources = freezeResources(profile.resources);
|
|
4792
|
+
if (profile.hooks && Object.values(profile.hooks).some((commands) => commands.length > 0)) {
|
|
4793
|
+
throw new Error(
|
|
4794
|
+
"generic AgentProfile hooks cannot be safely tokenized; use a candidate-profile source with executable/args"
|
|
4795
|
+
);
|
|
4796
|
+
}
|
|
4797
|
+
if (profile.hooks) candidate.hooks = profile.hooks;
|
|
4798
|
+
if (profile.modes) {
|
|
4799
|
+
candidate.modes = Object.fromEntries(
|
|
4800
|
+
Object.entries(profile.modes).map(([name, mode]) => {
|
|
4801
|
+
if (mode.metadata !== void 0) unsupportedProfileField(`modes.${name}.metadata`);
|
|
4802
|
+
const { metadata: _metadata, ...value } = mode;
|
|
4803
|
+
return [name, value];
|
|
4804
|
+
})
|
|
4805
|
+
);
|
|
4806
|
+
}
|
|
4807
|
+
const parsed = parseExactCandidateProfile(candidate);
|
|
4808
|
+
assertCandidateProfileBinding(profile, parsed);
|
|
4809
|
+
return parsed;
|
|
4810
|
+
}
|
|
4811
|
+
function assertCandidateProfileBinding(measuredInput, bundled) {
|
|
4812
|
+
const measured = parseExactAgentProfile(measuredInput, "proposal candidate profile");
|
|
4813
|
+
if (measured.connections || measured.metadata || measured.extensions) {
|
|
4814
|
+
throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
|
|
4815
|
+
}
|
|
4816
|
+
const normalized = candidateProfileAsAgentProfile(bundled);
|
|
4817
|
+
if (canonicalCandidateDigest(measured) !== canonicalCandidateDigest(normalized)) {
|
|
4818
|
+
throw new Error("proposal candidateProfile does not match candidateBundle.profile");
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
function parseExactAgentProfile(input, label) {
|
|
4822
|
+
const parsed = agentProfileSchema.parse(input);
|
|
4823
|
+
assertCanonicalParse(input, parsed, label);
|
|
4824
|
+
return parsed;
|
|
4825
|
+
}
|
|
4826
|
+
function parseExactCandidateProfile(input) {
|
|
4827
|
+
const parsed = agentCandidateProfileSchema.parse(input);
|
|
4828
|
+
assertCanonicalParse(input, parsed, "candidate profile");
|
|
4829
|
+
return parsed;
|
|
4830
|
+
}
|
|
4831
|
+
function candidateProfileAsAgentProfile(candidate) {
|
|
4832
|
+
const output = {};
|
|
4833
|
+
copyDirectProfileFields(output, candidate);
|
|
4834
|
+
if (candidate.model) output.model = { ...candidate.model };
|
|
4835
|
+
if (candidate.mcp) {
|
|
4836
|
+
output.mcp = Object.fromEntries(
|
|
4837
|
+
Object.entries(candidate.mcp).map(([name, server]) => [
|
|
4838
|
+
name,
|
|
4839
|
+
{
|
|
4840
|
+
...server,
|
|
4841
|
+
...server.args ? { args: server.args.map(publicValue) } : {},
|
|
4842
|
+
...server.env ? { env: mapPublicValues(server.env) } : {}
|
|
4843
|
+
}
|
|
4844
|
+
])
|
|
4845
|
+
);
|
|
4846
|
+
}
|
|
4847
|
+
if (candidate.subagents) output.subagents = cloneRecord(candidate.subagents);
|
|
4848
|
+
if (candidate.modes) output.modes = cloneRecord(candidate.modes);
|
|
4849
|
+
if (candidate.hooks) {
|
|
4850
|
+
output.hooks = Object.fromEntries(
|
|
4851
|
+
Object.entries(candidate.hooks).map(([event, hooks]) => [
|
|
4852
|
+
event,
|
|
4853
|
+
hooks.map(({ executable, args, env, ...hook }) => ({
|
|
4854
|
+
...hook,
|
|
4855
|
+
command: [executable, ...(args ?? []).map(publicValue)].map(shellQuote).join(" "),
|
|
4856
|
+
...env ? { env: mapPublicValues(env) } : {}
|
|
4857
|
+
}))
|
|
4858
|
+
])
|
|
4859
|
+
);
|
|
4860
|
+
}
|
|
4861
|
+
if (candidate.resources) {
|
|
4862
|
+
if (candidate.resources.failOnError !== true) {
|
|
4863
|
+
throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
|
|
4864
|
+
}
|
|
4865
|
+
output.resources = {
|
|
4866
|
+
failOnError: true,
|
|
4867
|
+
...candidate.resources.files ? {
|
|
4868
|
+
files: candidate.resources.files.map((file) => ({
|
|
4869
|
+
...file,
|
|
4870
|
+
resource: publicResource(file.resource)
|
|
4871
|
+
}))
|
|
4872
|
+
} : {},
|
|
4873
|
+
...candidate.resources.tools ? { tools: candidate.resources.tools.map(publicResource) } : {},
|
|
4874
|
+
...candidate.resources.skills ? { skills: candidate.resources.skills.map(publicResource) } : {},
|
|
4875
|
+
...candidate.resources.agents ? { agents: candidate.resources.agents.map(publicResource) } : {},
|
|
4876
|
+
...candidate.resources.commands ? { commands: candidate.resources.commands.map(publicResource) } : {},
|
|
4877
|
+
...candidate.resources.instructions !== void 0 ? {
|
|
4878
|
+
instructions: typeof candidate.resources.instructions === "string" ? candidate.resources.instructions : publicResource(candidate.resources.instructions)
|
|
4879
|
+
} : {}
|
|
4880
|
+
};
|
|
4881
|
+
}
|
|
4882
|
+
return output;
|
|
4883
|
+
}
|
|
4884
|
+
function freezeMcpServers(servers) {
|
|
4885
|
+
return Object.fromEntries(
|
|
4886
|
+
Object.entries(servers).map(([name, server]) => {
|
|
4887
|
+
if (server.transport !== void 0 && server.transport !== "stdio") {
|
|
4888
|
+
unsupportedProfileField(`mcp.${name}.transport=${server.transport}`);
|
|
4889
|
+
}
|
|
4890
|
+
if (server.url !== void 0) unsupportedProfileField(`mcp.${name}.url`);
|
|
4891
|
+
if (server.headers !== void 0) unsupportedProfileField(`mcp.${name}.headers`);
|
|
4892
|
+
if (server.metadata !== void 0) unsupportedProfileField(`mcp.${name}.metadata`);
|
|
4893
|
+
return [
|
|
4894
|
+
name,
|
|
4895
|
+
{
|
|
4896
|
+
...server.transport ? { transport: server.transport } : {},
|
|
4897
|
+
...server.command ? { command: server.command } : {},
|
|
4898
|
+
...server.args ? { args: server.args.map(candidatePublicValue) } : {},
|
|
4899
|
+
...server.env ? { env: mapCandidatePublicValues(server.env) } : {},
|
|
4900
|
+
...server.cwd ? { cwd: server.cwd } : {},
|
|
4901
|
+
...server.enabled === void 0 ? {} : { enabled: server.enabled }
|
|
4902
|
+
}
|
|
4903
|
+
];
|
|
4904
|
+
})
|
|
4905
|
+
);
|
|
4906
|
+
}
|
|
4907
|
+
function freezeResources(resources) {
|
|
4908
|
+
if (resources.failOnError !== true) {
|
|
4909
|
+
throw new Error("candidate profile resources require failOnError: true");
|
|
4910
|
+
}
|
|
4911
|
+
return {
|
|
4912
|
+
failOnError: true,
|
|
4913
|
+
...resources.files ? {
|
|
4914
|
+
files: resources.files.map((file) => ({
|
|
4915
|
+
...file,
|
|
4916
|
+
resource: freezeResource(file.resource)
|
|
4917
|
+
}))
|
|
4918
|
+
} : {},
|
|
4919
|
+
...resources.tools ? { tools: resources.tools.map(freezeResource) } : {},
|
|
4920
|
+
...resources.skills ? { skills: resources.skills.map(freezeResource) } : {},
|
|
4921
|
+
...resources.agents ? { agents: resources.agents.map(freezeResource) } : {},
|
|
4922
|
+
...resources.commands ? { commands: resources.commands.map(freezeResource) } : {},
|
|
4923
|
+
...resources.instructions === void 0 ? {} : {
|
|
4924
|
+
instructions: typeof resources.instructions === "string" ? resources.instructions : freezeResource(resources.instructions)
|
|
4925
|
+
}
|
|
4926
|
+
};
|
|
4927
|
+
}
|
|
4928
|
+
function freezeResource(resource) {
|
|
4929
|
+
if (resource.kind === "github") {
|
|
4930
|
+
throw new Error(
|
|
4931
|
+
"generic GitHub profile resources do not carry byte identity; use a candidate-profile source with a pinned commit, digest, and byte length"
|
|
4932
|
+
);
|
|
4933
|
+
}
|
|
4934
|
+
const bytes = Buffer.from(resource.content, "utf8");
|
|
4935
|
+
return {
|
|
4936
|
+
...resource,
|
|
4937
|
+
sha256: embeddedCandidateArtifact(bytes).sha256,
|
|
4938
|
+
byteLength: bytes.byteLength
|
|
4939
|
+
};
|
|
4940
|
+
}
|
|
4941
|
+
function copyDirectProfileFields(target, source) {
|
|
4942
|
+
for (const key of CANDIDATE_PROFILE_DIRECT_FIELDS) {
|
|
4943
|
+
if (source[key] !== void 0) target[key] = source[key];
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
function assertCanonicalParse(input, parsed, label) {
|
|
4947
|
+
if (!Buffer.from(canonicalCandidateBytes(input)).equals(canonicalCandidateBytes(parsed))) {
|
|
4948
|
+
throw new Error(`${label} contains unsupported or non-canonical fields`);
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
function publicResource(resource) {
|
|
4952
|
+
if (resource.kind === "inline") {
|
|
4953
|
+
return { kind: "inline", name: resource.name, content: resource.content };
|
|
4954
|
+
}
|
|
4955
|
+
return {
|
|
4956
|
+
kind: "github",
|
|
4957
|
+
repository: `${resource.repository.owner}/${resource.repository.repo}`,
|
|
4958
|
+
path: resource.path,
|
|
4959
|
+
ref: resource.commit,
|
|
4960
|
+
...resource.name ? { name: resource.name } : {}
|
|
4961
|
+
};
|
|
4962
|
+
}
|
|
4963
|
+
function candidatePublicValue(value) {
|
|
4964
|
+
return { kind: "public", value };
|
|
4965
|
+
}
|
|
4966
|
+
function mapCandidatePublicValues(values) {
|
|
4967
|
+
return Object.fromEntries(
|
|
4968
|
+
Object.entries(values).map(([name, value]) => [name, candidatePublicValue(value)])
|
|
4969
|
+
);
|
|
4970
|
+
}
|
|
4971
|
+
function publicValue(value) {
|
|
4972
|
+
return value.value;
|
|
4973
|
+
}
|
|
4974
|
+
function mapPublicValues(values) {
|
|
4975
|
+
return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, publicValue(value)]));
|
|
4976
|
+
}
|
|
4977
|
+
function cloneRecord(values) {
|
|
4978
|
+
return Object.fromEntries(
|
|
4979
|
+
Object.entries(values).map(([key, value]) => [key, { ...value }])
|
|
4980
|
+
);
|
|
4981
|
+
}
|
|
4982
|
+
function shellQuote(value) {
|
|
4983
|
+
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
4984
|
+
}
|
|
4985
|
+
function unsupportedProfileField(path) {
|
|
4986
|
+
throw new Error(
|
|
4987
|
+
`generic AgentProfile field ${path} is not representable in a sealed candidate profile`
|
|
4988
|
+
);
|
|
4989
|
+
}
|
|
4990
|
+
|
|
4742
4991
|
export {
|
|
4743
|
-
CLAIM_FORMAT_VERSION,
|
|
4744
|
-
PENDING_FORMAT_VERSION,
|
|
4745
|
-
TERMINAL_FORMAT_VERSION,
|
|
4746
|
-
PHASE_FORMAT_VERSION,
|
|
4747
4992
|
canonicalCandidateBytes,
|
|
4748
4993
|
canonicalCandidateDigest,
|
|
4749
4994
|
immutableCandidateValue,
|
|
4750
4995
|
canonicalCandidateDocument,
|
|
4996
|
+
embeddedCandidateArtifact,
|
|
4751
4997
|
omitTopLevelDigest,
|
|
4998
|
+
sealAgentCandidateBundle,
|
|
4999
|
+
freezeGenericAgentCandidateProfile,
|
|
5000
|
+
assertCandidateProfileBinding,
|
|
5001
|
+
parseExactAgentProfile,
|
|
5002
|
+
parseExactCandidateProfile,
|
|
5003
|
+
CLAIM_FORMAT_VERSION,
|
|
5004
|
+
PENDING_FORMAT_VERSION,
|
|
5005
|
+
TERMINAL_FORMAT_VERSION,
|
|
5006
|
+
PHASE_FORMAT_VERSION,
|
|
4752
5007
|
assertExactObjectKeys,
|
|
4753
5008
|
terminalRecord,
|
|
4754
5009
|
recoveredTerminalRecord,
|
|
@@ -4781,4 +5036,4 @@ export {
|
|
|
4781
5036
|
verifyAgentCandidateBundle,
|
|
4782
5037
|
prepareAgentCandidateExecution
|
|
4783
5038
|
};
|
|
4784
|
-
//# sourceMappingURL=chunk-
|
|
5039
|
+
//# sourceMappingURL=chunk-26WCEARH.js.map
|