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