@tangle-network/agent-runtime 0.101.0 → 0.102.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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/agent.js +4 -3
  3. package/dist/agent.js.map +1 -1
  4. package/dist/candidate-execution/index.d.ts +13 -2
  5. package/dist/candidate-execution/index.js +7 -3
  6. package/dist/{chunk-LV6WCT43.js → chunk-23Z7N5IG.js} +5 -5
  7. package/dist/chunk-2VZYRB55.js +834 -0
  8. package/dist/chunk-2VZYRB55.js.map +1 -0
  9. package/dist/{chunk-VOPHC4LB.js → chunk-4AMAFNUD.js} +32 -192
  10. package/dist/chunk-4AMAFNUD.js.map +1 -0
  11. package/dist/{chunk-BXZ7GPL4.js → chunk-AIBIRAJ6.js} +2 -2
  12. package/dist/{chunk-Y3SRWZMP.js → chunk-AYU35OTU.js} +2 -2
  13. package/dist/{chunk-U4PRAATQ.js → chunk-DA7YL6I4.js} +3 -3
  14. package/dist/{chunk-HZDEXTSL.js → chunk-IKGCKPDX.js} +2 -833
  15. package/dist/chunk-IKGCKPDX.js.map +1 -0
  16. package/dist/{chunk-WYC2XJF2.js → chunk-KSBUSEUA.js} +2 -2
  17. package/dist/{chunk-UQ6PNNXM.js → chunk-KVJQV342.js} +5 -3
  18. package/dist/{chunk-UQ6PNNXM.js.map → chunk-KVJQV342.js.map} +1 -1
  19. package/dist/chunk-LKKIM5QD.js +200 -0
  20. package/dist/chunk-LKKIM5QD.js.map +1 -0
  21. package/dist/{chunk-FXF2OL34.js → chunk-MAONWP4R.js} +2 -2
  22. package/dist/{chunk-SGQ4YIQW.js → chunk-N2CEE5Q3.js} +3 -3
  23. package/dist/chunk-SPCD4IQQ.js +578 -0
  24. package/dist/chunk-SPCD4IQQ.js.map +1 -0
  25. package/dist/{chunk-HGSHPVJ6.js → chunk-TGDHHHH4.js} +189 -189
  26. package/dist/{chunk-HGSHPVJ6.js.map → chunk-TGDHHHH4.js.map} +1 -1
  27. package/dist/{improve-g75IE2Cx.d.ts → improve-CIml6hT3.d.ts} +7 -0
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +16 -10
  30. package/dist/index.js.map +1 -1
  31. package/dist/intelligence.d.ts +60 -59
  32. package/dist/intelligence.js +65 -473
  33. package/dist/intelligence.js.map +1 -1
  34. package/dist/knowledge.js +8 -6
  35. package/dist/loop-runner-bin.js +5 -4
  36. package/dist/loops.js +4 -3
  37. package/dist/mcp/bin.js +4 -3
  38. package/dist/mcp/bin.js.map +1 -1
  39. package/dist/mcp/index.js +6 -5
  40. package/dist/mcp/index.js.map +1 -1
  41. package/dist/testing.d.ts +6 -0
  42. package/dist/testing.js +2638 -0
  43. package/dist/testing.js.map +1 -0
  44. package/package.json +11 -4
  45. package/dist/chunk-HZDEXTSL.js.map +0 -1
  46. package/dist/chunk-VOPHC4LB.js.map +0 -1
  47. /package/dist/{chunk-LV6WCT43.js.map → chunk-23Z7N5IG.js.map} +0 -0
  48. /package/dist/{chunk-BXZ7GPL4.js.map → chunk-AIBIRAJ6.js.map} +0 -0
  49. /package/dist/{chunk-Y3SRWZMP.js.map → chunk-AYU35OTU.js.map} +0 -0
  50. /package/dist/{chunk-U4PRAATQ.js.map → chunk-DA7YL6I4.js.map} +0 -0
  51. /package/dist/{chunk-WYC2XJF2.js.map → chunk-KSBUSEUA.js.map} +0 -0
  52. /package/dist/{chunk-FXF2OL34.js.map → chunk-MAONWP4R.js.map} +0 -0
  53. /package/dist/{chunk-SGQ4YIQW.js.map → chunk-N2CEE5Q3.js.map} +0 -0
@@ -1,3 +1,11 @@
1
+ import {
2
+ exactProcessProviderAsCandidateExecutor
3
+ } from "./chunk-SPCD4IQQ.js";
4
+ import {
5
+ createAgentImprovementActivationResult,
6
+ executeAgentImprovementActivation,
7
+ verifyAgentImprovementActivationResult
8
+ } from "./chunk-LKKIM5QD.js";
1
9
  import {
2
10
  AGENT_IMPROVEMENT_PROFILE_SURFACES,
3
11
  AgentCandidateExperimentCellExecutionError,
@@ -6,40 +14,37 @@ import {
6
14
  agentImprovementTargetProfileDiffs,
7
15
  buildAgentImprovementActivationTargets,
8
16
  createAgentImprovementActivation,
9
- createAgentImprovementActivationResult,
10
17
  createAgentImprovementMeasuredComparison,
11
18
  createAgentImprovementProposal,
12
19
  executeAgentCandidateExperimentCell,
13
- executeAgentImprovementActivation,
14
20
  isAgentImprovementProfileSurface,
15
21
  proposeAgentImprovement,
16
22
  reviewAgentImprovementProposal,
17
23
  runAgentCandidateExperiment,
18
24
  verifyAgentImprovementActivation,
19
- verifyAgentImprovementActivationResult,
20
25
  verifyAgentImprovementProposal,
21
26
  verifyAgentImprovementReview,
22
27
  verifyCandidateExecutionEvidence
23
- } from "./chunk-VOPHC4LB.js";
28
+ } from "./chunk-4AMAFNUD.js";
24
29
  import {
25
30
  AGENT_CANDIDATE_EXECUTION_SUPPORT,
26
- CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV,
27
- CANDIDATE_KNOWLEDGE_ROOT_ENV,
28
31
  applyExactAgentProfileDiff,
29
- candidateKnowledgeExecutionPaths,
30
- canonicalCandidateBytes,
31
32
  immutableCandidateValue,
32
33
  omitUndefinedObjectFields,
33
34
  parseAgentCandidateProfileActivation,
34
35
  parseExactAgentProfile
35
- } from "./chunk-HGSHPVJ6.js";
36
+ } from "./chunk-TGDHHHH4.js";
36
37
  import {
37
38
  buildLoopOtelSpans,
38
39
  buildRuntimeEventOtelSpans,
39
40
  createOtelExporter,
40
41
  flatOtelSpan
41
- } from "./chunk-HZDEXTSL.js";
42
+ } from "./chunk-2VZYRB55.js";
43
+ import "./chunk-IKGCKPDX.js";
42
44
  import "./chunk-IMSNJSXH.js";
45
+ import {
46
+ resolveAgentEnvironmentProvider
47
+ } from "./chunk-M6MD6JBS.js";
43
48
  import "./chunk-3MDZX7YU.js";
44
49
  import "./chunk-FD2MBMOH.js";
45
50
  import "./chunk-M22PL4GH.js";
@@ -428,6 +433,54 @@ function isJsonSchema(v) {
428
433
  return typeof v === "object" && v !== null && !Array.isArray(v);
429
434
  }
430
435
 
436
+ // src/intelligence/exact-process-candidate.ts
437
+ var exactProcessCandidateExperimentExecutionSupport = Object.freeze({
438
+ outcomes: Object.freeze(["output"]),
439
+ outputMediaTypes: Object.freeze(["text/*", "application/json", "*+json"]),
440
+ code: Object.freeze(["disabled"]),
441
+ memory: Object.freeze(["disabled"]),
442
+ knowledge: true,
443
+ profile: AGENT_CANDIDATE_EXECUTION_SUPPORT.profile,
444
+ isolation: Object.freeze({
445
+ freshEnvironment: true,
446
+ exactProcess: true,
447
+ egress: Object.freeze(["blocked", "strict"])
448
+ })
449
+ });
450
+ function createExactProcessCandidateExperimentExecutor(options) {
451
+ const provider = resolveAgentEnvironmentProvider(options.provider, options.providerRegistry);
452
+ const executor = exactProcessProviderAsCandidateExecutor({
453
+ provider,
454
+ resources: options.resources,
455
+ ...options.providerOptions ? { providerOptions: options.providerOptions } : {},
456
+ ...options.provisionTimeoutMs === void 0 ? {} : { provisionTimeoutMs: options.provisionTimeoutMs },
457
+ ...options.recoveryRetentionMs === void 0 ? {} : { recoveryRetentionMs: options.recoveryRetentionMs }
458
+ });
459
+ return Object.freeze({
460
+ executor,
461
+ async execute(input) {
462
+ return await executeAgentCandidateExperimentCell({
463
+ ...input,
464
+ attempt: input.attempt ?? 1,
465
+ executionId: input.executionId,
466
+ executionRoots: input.executionRoots,
467
+ stagingRoots: input.stagingRoots,
468
+ ports: options.ports,
469
+ ...input.preparation ? { preparation: input.preparation } : {},
470
+ execution: {
471
+ executor,
472
+ grader: options.grader,
473
+ outputArtifacts: options.outputArtifacts,
474
+ traceStore: options.traceStore,
475
+ claimStore: options.claimStore,
476
+ ...options.cleanupTimeoutMs === void 0 ? {} : { cleanupTimeoutMs: options.cleanupTimeoutMs },
477
+ ...options.resultTimeoutMs === void 0 ? {} : { resultTimeoutMs: options.resultTimeoutMs }
478
+ }
479
+ });
480
+ }
481
+ });
482
+ }
483
+
431
484
  // src/intelligence/profile-activation.ts
432
485
  function prepareAgentImprovementProfileActivation(input) {
433
486
  const targetKeys = input.targets.map((target) => `${target.identity}\0${target.surface}`);
@@ -880,467 +933,6 @@ async function composeCertifiedProfileFromWire(base, profile, ctx = {}) {
880
933
  return composeCertifiedProfile(base, manifestFromProfile(profile), ctx);
881
934
  }
882
935
 
883
- // src/intelligence/sandbox-approved-candidate.ts
884
- import { posix } from "path";
885
- var sandboxCandidateExperimentExecutionSupport = Object.freeze({
886
- outcomes: Object.freeze(["output"]),
887
- outputMediaTypes: Object.freeze(["text/*", "application/json", "*+json"]),
888
- code: Object.freeze(["disabled"]),
889
- memory: Object.freeze(["disabled"]),
890
- knowledge: true,
891
- profile: AGENT_CANDIDATE_EXECUTION_SUPPORT.profile,
892
- isolation: Object.freeze({
893
- freshSandbox: true,
894
- exactProcess: true,
895
- egress: Object.freeze(["blocked", "strict"])
896
- })
897
- });
898
- function createSandboxCandidateExperimentExecutor(options) {
899
- const executor = new SandboxAgentCandidateExecutor(
900
- options.client,
901
- options.sandbox,
902
- options.resultTimeoutMs
903
- );
904
- return Object.freeze({
905
- executor,
906
- async execute(input) {
907
- return await executeAgentCandidateExperimentCell({
908
- ...input,
909
- attempt: input.attempt ?? 1,
910
- executionId: input.executionId,
911
- executionRoots: input.executionRoots,
912
- stagingRoots: input.stagingRoots,
913
- ports: options.ports,
914
- ...input.preparation ? { preparation: input.preparation } : {},
915
- execution: {
916
- executor,
917
- grader: options.grader,
918
- outputArtifacts: options.outputArtifacts,
919
- traceStore: options.traceStore,
920
- claimStore: options.claimStore,
921
- ...options.cleanupTimeoutMs === void 0 ? {} : { cleanupTimeoutMs: options.cleanupTimeoutMs },
922
- ...options.resultTimeoutMs === void 0 ? {} : { resultTimeoutMs: options.resultTimeoutMs }
923
- }
924
- });
925
- }
926
- });
927
- }
928
- var SandboxAgentCandidateExecutor = class {
929
- constructor(client, options = {}, captureTimeoutMs = 12e4) {
930
- this.client = client;
931
- this.options = options;
932
- this.captureTimeoutMs = captureTimeoutMs;
933
- }
934
- client;
935
- options;
936
- captureTimeoutMs;
937
- states = /* @__PURE__ */ new Map();
938
- async execute(request, context) {
939
- assertSupportedRequest(request);
940
- const outcome = request.benchmark.task.outcome;
941
- if (outcome.kind !== "output") throw new Error("sandbox executor requires an output task");
942
- const key = executionKey(request.executionId, request.executionPlan.value.digest);
943
- const sandbox = await this.client.create(sandboxCreateOptions(request, this.options), {
944
- signal: context.signal,
945
- timeoutMs: this.options.createTimeoutMs ?? 12e4
946
- });
947
- const state = { sandbox };
948
- this.states.set(key, state);
949
- if ((await sandbox.process.list()).length !== 0) {
950
- throw new Error("fresh candidate sandbox already contains a process");
951
- }
952
- await materializeRequest(sandbox, request);
953
- const launch = exactLaunch(request);
954
- const startedAt = Date.now();
955
- state.trace = {
956
- runId: request.trace.runId,
957
- scenarioId: request.benchmark.task.scenario.id,
958
- startedAt,
959
- deadlineAtMs: context.deadlineAtMs,
960
- timeoutMs: request.hardLimits.timeoutMs,
961
- tags: { ...request.trace.tags, sandboxId: sandbox.id },
962
- written: false
963
- };
964
- const process2 = await sandbox.process.spawnExact(launch.executable, launch.args, {
965
- cwd: request.launch.cwd,
966
- env: { ...request.launch.env },
967
- ...launch.stdin === void 0 ? {} : { stdin: launch.stdin },
968
- timeoutMs: request.hardLimits.timeoutMs
969
- });
970
- const outputPromise = collectOutput(process2, outcome.maxBytes);
971
- let cancellation;
972
- let cancellationTermination;
973
- let processExited = false;
974
- const cancel = () => {
975
- if (processExited) return;
976
- cancellationTermination = Date.now() >= context.deadlineAtMs ? { kind: "timeout", timeoutMs: request.hardLimits.timeoutMs } : { kind: "cancelled" };
977
- cancellation ??= killProcess(process2);
978
- };
979
- context.signal.addEventListener("abort", cancel, { once: true });
980
- if (context.signal.aborted) cancel();
981
- try {
982
- const waitedExitCode = await process2.wait();
983
- processExited = true;
984
- context.signal.removeEventListener("abort", cancel);
985
- if (cancellation) await cancellation;
986
- const status = await process2.status();
987
- if (status.running || status.exitCode !== waitedExitCode) {
988
- throw new Error("sandbox process returned an inconsistent terminal status");
989
- }
990
- state.output = await awaitOutput(outputPromise, context.signal, context.deadlineAtMs);
991
- state.termination = cancellationTermination ?? processTermination(status);
992
- await appendSandboxTrace(state, context.traceStore, status);
993
- return { executionId: request.executionId, termination: state.termination };
994
- } finally {
995
- context.signal.removeEventListener("abort", cancel);
996
- void outputPromise.catch(() => void 0);
997
- }
998
- }
999
- async stop(request, context) {
1000
- context.signal.throwIfAborted();
1001
- const sandbox = await this.resolve(request, true);
1002
- if (!sandbox) return { stopped: true };
1003
- const statuses = await sandbox.process.list();
1004
- if (statuses.length > 1) throw new Error("candidate sandbox contains more than one process");
1005
- const status = statuses[0];
1006
- if (status?.running) {
1007
- const process2 = await sandbox.process.get(status.pid);
1008
- if (!process2) throw new Error("candidate sandbox lost its running process handle");
1009
- await killProcess(process2);
1010
- }
1011
- context.signal.throwIfAborted();
1012
- const remaining = await sandbox.process.list();
1013
- if (remaining.some((entry) => entry.running)) {
1014
- throw new Error("candidate sandbox process termination is not proven");
1015
- }
1016
- const state = this.states.get(executionKey(request.executionId, request.executionPlanDigest));
1017
- if (state) {
1018
- if (context.reason === "timeout") {
1019
- state.termination = { kind: "timeout", timeoutMs: state.trace?.timeoutMs ?? 0 };
1020
- }
1021
- await appendSandboxTrace(state, context.traceStore, remaining[0]);
1022
- }
1023
- return { stopped: true };
1024
- }
1025
- async capture(request, context) {
1026
- context.signal.throwIfAborted();
1027
- const sandbox = await this.resolve(request, false);
1028
- const statuses = await sandbox.process.list();
1029
- if (statuses.length > 1 || statuses.some((entry) => entry.running)) {
1030
- throw new Error("candidate sandbox must contain one stopped process before capture");
1031
- }
1032
- const state = this.states.get(executionKey(request.executionId, request.executionPlanDigest));
1033
- let output = state?.output;
1034
- let termination = state?.termination;
1035
- const status = statuses[0];
1036
- if (status && !output) {
1037
- const process2 = await sandbox.process.get(status.pid);
1038
- if (!process2) throw new Error("candidate sandbox lost its captured process handle");
1039
- const expected = sandboxOutputSpec(sandbox);
1040
- output = await awaitOutput(
1041
- collectOutput(process2, expected.maxBytes),
1042
- context.signal,
1043
- Date.now() + this.captureTimeoutMs
1044
- );
1045
- }
1046
- if (status && !termination) {
1047
- termination = processTermination(status);
1048
- }
1049
- context.signal.throwIfAborted();
1050
- const evidence = canonicalCandidateBytes({
1051
- kind: "sandbox-agent-candidate-capture",
1052
- sandboxId: sandbox.id,
1053
- executionId: request.executionId,
1054
- executionPlanDigest: request.executionPlanDigest,
1055
- ...status ? {
1056
- process: {
1057
- pid: status.pid,
1058
- exitCode: status.exitCode,
1059
- ...status.exitSignal ? { exitSignal: status.exitSignal } : {}
1060
- }
1061
- } : {},
1062
- ...termination ? { termination } : {}
1063
- });
1064
- return {
1065
- ...output ? { taskOutcome: { kind: "output", bytes: output } } : {},
1066
- evidence
1067
- };
1068
- }
1069
- async dispose(request, context) {
1070
- context.signal.throwIfAborted();
1071
- const sandbox = await this.resolve(request, true);
1072
- if (!sandbox) return { disposed: true };
1073
- try {
1074
- await sandbox.delete();
1075
- } catch (error) {
1076
- if (await this.client.get(sandbox.id)) throw error;
1077
- }
1078
- context.signal.throwIfAborted();
1079
- this.states.delete(executionKey(request.executionId, request.executionPlanDigest));
1080
- return { disposed: true };
1081
- }
1082
- async resolve(request, missingIsDeleted) {
1083
- const key = executionKey(request.executionId, request.executionPlanDigest);
1084
- const active = this.states.get(key)?.sandbox;
1085
- if (active) return active;
1086
- const matches = [];
1087
- const scope = this.options.teamId ? `team:${this.options.teamId}` : "personal";
1088
- for (let offset = 0; ; offset += 100) {
1089
- const page = await this.client.list({ scope, limit: 100, offset });
1090
- for (const candidate of page) {
1091
- if (matchesExecution(candidate, request)) matches.push(candidate);
1092
- }
1093
- if (page.length < 100) break;
1094
- }
1095
- if (matches.length === 1) return matches[0];
1096
- if (matches.length > 1) throw new Error("multiple sandboxes match one candidate execution");
1097
- if (missingIsDeleted) return void 0;
1098
- throw new Error("candidate sandbox evidence is unavailable");
1099
- }
1100
- };
1101
- async function appendSandboxTrace(state, traceStore, status) {
1102
- const trace = state.trace;
1103
- if (!trace || trace.written) return;
1104
- const endedAt = Math.max(trace.startedAt, Math.min(Date.now(), trace.deadlineAtMs));
1105
- await traceStore.appendRun({
1106
- runId: trace.runId,
1107
- scenarioId: trace.scenarioId,
1108
- startedAt: trace.startedAt,
1109
- endedAt,
1110
- status: state.termination?.kind !== "timeout" && status?.running === false && status.exitCode === 0 ? "completed" : "failed",
1111
- tags: trace.tags
1112
- });
1113
- trace.written = true;
1114
- }
1115
- function assertSupportedRequest(request) {
1116
- if (request.benchmark.task.outcome.kind !== "output") {
1117
- throw new Error("sandbox candidate executor does not support workspace outcomes; use Pier");
1118
- }
1119
- if (request.executionPlan.value.material.codeKind !== "disabled" || request.inputs.candidate) {
1120
- throw new Error("sandbox candidate executor does not support code workspaces; use Pier");
1121
- }
1122
- if (request.memory.mode !== "disabled") {
1123
- throw new Error("sandbox candidate executor does not support isolated memory");
1124
- }
1125
- const mediaType = request.benchmark.task.outcome.mediaType.toLowerCase();
1126
- if (!(mediaType.startsWith("text/") || mediaType === "application/json" || mediaType.endsWith("+json"))) {
1127
- throw new Error("sandbox candidate executor supports only UTF-8 text and JSON outputs");
1128
- }
1129
- }
1130
- function sandboxCreateOptions(request, options = {}) {
1131
- const material = request.executionPlan.value.material;
1132
- const retentionSeconds = options.evidenceRetentionSeconds ?? 900;
1133
- if (!Number.isSafeInteger(retentionSeconds) || retentionSeconds < 60) {
1134
- throw new Error("sandbox evidence retention must be at least 60 seconds");
1135
- }
1136
- const maxLifetimeSeconds = Math.ceil(request.hardLimits.timeoutMs / 1e3) + retentionSeconds;
1137
- const network = material.model.access.network;
1138
- const egressPolicy = network.mode === "disabled" ? { mode: "blocked" } : {
1139
- mode: "strict",
1140
- allowDomains: [...network.domains],
1141
- includeImplicitDomains: false
1142
- };
1143
- const value = {
1144
- image: exactImage(material.container.image, material.container.manifestDigest),
1145
- bare: true,
1146
- publicEdge: false,
1147
- ephemeral: true,
1148
- sshEnabled: false,
1149
- webTerminalEnabled: false,
1150
- secrets: [],
1151
- capabilities: [],
1152
- egressPolicy,
1153
- maxLifetimeSeconds,
1154
- idempotencyKey: `candidate-${request.executionPlan.value.digest.slice("sha256:".length)}`,
1155
- metadata: {
1156
- kind: "agent-candidate-execution",
1157
- executionId: request.executionId,
1158
- executionPlanDigest: request.executionPlan.value.digest,
1159
- outputMediaType: request.benchmark.task.outcome.kind === "output" ? request.benchmark.task.outcome.mediaType : "",
1160
- outputMaxBytes: request.benchmark.task.outcome.kind === "output" ? request.benchmark.task.outcome.maxBytes : 0
1161
- },
1162
- ...options.teamId ? { teamId: options.teamId } : {},
1163
- ...options.resources ? { resources: options.resources } : {}
1164
- };
1165
- return value;
1166
- }
1167
- async function materializeRequest(sandbox, request) {
1168
- const knowledgePaths = assertKnowledgeExecutionBinding(request);
1169
- for (const file of request.inputs.task.files) {
1170
- await writeExactFile(sandbox, beneath(request.roots.taskRoot, file.path), file.bytes, file.mode);
1171
- }
1172
- const profileRoot = request.executionPlan.value.material.profile.targetWorkspace === "task" ? request.roots.taskRoot : request.roots.candidateRoot;
1173
- if (!profileRoot) throw new Error("candidate profile targets a missing workspace");
1174
- for (const file of request.profileActivation.files) {
1175
- await writeExactFile(
1176
- sandbox,
1177
- beneath(profileRoot, file.path),
1178
- Buffer.from(file.content, "utf8"),
1179
- file.mode
1180
- );
1181
- }
1182
- if (request.knowledge && knowledgePaths) {
1183
- for (const file of request.knowledge.files) {
1184
- await writeExactFile(sandbox, beneath(knowledgePaths.root, file.path), file.bytes, file.mode);
1185
- }
1186
- if (request.knowledge.retrievalConfig && knowledgePaths.retrievalConfig) {
1187
- await writeExactFile(
1188
- sandbox,
1189
- knowledgePaths.retrievalConfig,
1190
- request.knowledge.retrievalConfig,
1191
- 420
1192
- );
1193
- }
1194
- }
1195
- if (request.instruction.delivery.kind === "utf8-file") {
1196
- await writeExactFile(
1197
- sandbox,
1198
- request.instruction.delivery.path,
1199
- request.instruction.bytes,
1200
- 420
1201
- );
1202
- }
1203
- }
1204
- function assertKnowledgeExecutionBinding(request) {
1205
- const knowledge = request.knowledge;
1206
- if (!knowledge) {
1207
- if (request.launch.env[CANDIDATE_KNOWLEDGE_ROOT_ENV] !== void 0 || request.launch.env[CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV] !== void 0) {
1208
- throw new Error("candidate launch declares knowledge paths without verified knowledge");
1209
- }
1210
- return void 0;
1211
- }
1212
- const paths = candidateKnowledgeExecutionPaths(
1213
- request.roots.taskRoot,
1214
- knowledge.retrievalConfig !== void 0
1215
- );
1216
- if (request.launch.env[CANDIDATE_KNOWLEDGE_ROOT_ENV] !== paths.root || request.launch.env[CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV] !== paths.retrievalConfig) {
1217
- throw new Error("candidate knowledge paths do not match the signed launch environment");
1218
- }
1219
- const reserved = [paths.root, paths.retrievalConfig].filter(
1220
- (value) => value !== void 0
1221
- );
1222
- const profileRoot = request.executionPlan.value.material.profile.targetWorkspace === "task" ? request.roots.taskRoot : request.roots.candidateRoot;
1223
- const otherFiles = [
1224
- ...request.inputs.task.files.map((file) => beneath(request.roots.taskRoot, file.path)),
1225
- ...profileRoot ? request.profileActivation.files.map((file) => beneath(profileRoot, file.path)) : [],
1226
- ...request.instruction.delivery.kind === "utf8-file" ? [request.instruction.delivery.path] : []
1227
- ];
1228
- if (otherFiles.some(
1229
- (path) => reserved.some(
1230
- (reservedPath) => path === reservedPath || path.startsWith(`${reservedPath}/`) || reservedPath.startsWith(`${path}/`)
1231
- )
1232
- )) {
1233
- throw new Error("candidate knowledge paths overlap other execution inputs");
1234
- }
1235
- return paths;
1236
- }
1237
- function exactLaunch(request) {
1238
- const instruction = new TextDecoder("utf-8", { fatal: true }).decode(request.instruction.bytes);
1239
- switch (request.instruction.delivery.kind) {
1240
- case "argv-append":
1241
- return { executable: request.launch.executable, args: [...request.launch.args, instruction] };
1242
- case "stdin-utf8":
1243
- return {
1244
- executable: request.launch.executable,
1245
- args: request.launch.args,
1246
- stdin: instruction
1247
- };
1248
- case "utf8-file":
1249
- return { executable: request.launch.executable, args: request.launch.args };
1250
- }
1251
- }
1252
- async function writeExactFile(sandbox, path, bytes, mode) {
1253
- await sandbox.fs.write(path, Buffer.from(bytes).toString("base64"), {
1254
- encoding: "base64",
1255
- mode
1256
- });
1257
- }
1258
- async function collectOutput(process2, maxBytes) {
1259
- const chunks = [];
1260
- let byteLength = 0;
1261
- for await (const chunk of process2.stdout()) {
1262
- const bytes = Buffer.from(chunk, "utf8");
1263
- byteLength += bytes.byteLength;
1264
- if (byteLength > maxBytes) {
1265
- await killProcess(process2);
1266
- throw new Error(`sandbox candidate output exceeds its ${maxBytes}-byte maximum`);
1267
- }
1268
- chunks.push(bytes);
1269
- }
1270
- return Uint8Array.from(Buffer.concat(chunks, byteLength));
1271
- }
1272
- async function awaitOutput(output, signal, deadlineAtMs) {
1273
- signal.throwIfAborted();
1274
- const remainingMs = deadlineAtMs - Date.now();
1275
- if (remainingMs <= 0) throw new Error("sandbox candidate output deadline expired");
1276
- let timer;
1277
- let onAbort;
1278
- try {
1279
- return await Promise.race([
1280
- output,
1281
- new Promise((_resolve, reject) => {
1282
- onAbort = () => reject(signal.reason ?? new Error("sandbox candidate output cancelled"));
1283
- signal.addEventListener("abort", onAbort, { once: true });
1284
- timer = setTimeout(
1285
- () => reject(new Error("sandbox candidate output deadline expired")),
1286
- remainingMs
1287
- );
1288
- })
1289
- ]);
1290
- } finally {
1291
- if (onAbort) signal.removeEventListener("abort", onAbort);
1292
- if (timer) clearTimeout(timer);
1293
- }
1294
- }
1295
- async function killProcess(process2) {
1296
- const before = await process2.status();
1297
- if (!before.running) return;
1298
- try {
1299
- await process2.kill("SIGKILL", { tree: true });
1300
- } catch (error) {
1301
- if ((await process2.status()).running) throw error;
1302
- }
1303
- }
1304
- function processTermination(status) {
1305
- if (status.running) throw new Error("candidate process is still running");
1306
- if (status.exitSignal) {
1307
- if (!/^SIG[A-Z0-9]+$/.test(status.exitSignal)) {
1308
- throw new Error("sandbox returned an invalid process signal");
1309
- }
1310
- return { kind: "signal", signal: status.exitSignal };
1311
- }
1312
- return { kind: "exit", exitCode: status.exitCode };
1313
- }
1314
- function matchesExecution(sandbox, request) {
1315
- return sandbox.metadata?.kind === "agent-candidate-execution" && sandbox.metadata.executionId === request.executionId && sandbox.metadata.executionPlanDigest === request.executionPlanDigest;
1316
- }
1317
- function sandboxOutputSpec(sandbox) {
1318
- const maxBytes = sandbox.metadata?.outputMaxBytes;
1319
- if (!Number.isSafeInteger(maxBytes) || Number(maxBytes) < 1) {
1320
- throw new Error("candidate sandbox output bound is unavailable");
1321
- }
1322
- return { maxBytes: Number(maxBytes) };
1323
- }
1324
- function executionKey(executionId, executionPlanDigest) {
1325
- return `${executionId}\0${executionPlanDigest}`;
1326
- }
1327
- function exactImage(image, manifestDigest) {
1328
- const marker = image.lastIndexOf("@");
1329
- if (marker < 0) return `${image}@${manifestDigest}`;
1330
- if (image.slice(marker + 1) !== manifestDigest) {
1331
- throw new Error("candidate container image conflicts with its resolved manifest");
1332
- }
1333
- return image;
1334
- }
1335
- function beneath(root, relativePath) {
1336
- if (posix.isAbsolute(relativePath)) throw new Error("candidate input path must be relative");
1337
- const path = posix.normalize(relativePath);
1338
- if (path === ".." || path.startsWith("../")) {
1339
- throw new Error("candidate input path escapes its execution root");
1340
- }
1341
- return posix.join(root, path);
1342
- }
1343
-
1344
936
  // src/intelligence/with-intelligence.ts
1345
937
  import { applyAgentProfileDiff } from "@tangle-network/agent-interface";
1346
938
  function summarizeRuntimeEvents(events) {
@@ -1785,10 +1377,11 @@ export {
1785
1377
  createAgentImprovementMeasuredComparison,
1786
1378
  createAgentImprovementProposal,
1787
1379
  createCertifiedPromptSource,
1380
+ createExactProcessCandidateExperimentExecutor,
1788
1381
  createIntelligenceClient,
1789
- createSandboxCandidateExperimentExecutor,
1790
1382
  defaultEffortTier,
1791
1383
  defaultRedactor,
1384
+ exactProcessCandidateExperimentExecutionSupport,
1792
1385
  executeAgentCandidateExperimentCell,
1793
1386
  executeAgentImprovementActivation,
1794
1387
  isAgentImprovementProfileSurface,
@@ -1804,7 +1397,6 @@ export {
1804
1397
  resolveRedactor,
1805
1398
  reviewAgentImprovementProposal,
1806
1399
  runAgentCandidateExperiment,
1807
- sandboxCandidateExperimentExecutionSupport,
1808
1400
  verifyAgentImprovementActivation,
1809
1401
  verifyAgentImprovementActivationResult,
1810
1402
  verifyAgentImprovementProposal,