@tangle-network/agent-runtime 0.89.0 → 0.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -18
- package/dist/agent.d.ts +53 -2
- package/dist/agent.js +168 -6
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/chunk-5QOB7H74.js +387 -0
- package/dist/chunk-5QOB7H74.js.map +1 -0
- package/dist/{chunk-4WXGK6GV.js → chunk-7ON74BQO.js} +2 -2
- package/dist/{chunk-7LO5GMAO.js → chunk-CMYMTRGA.js} +14 -5
- package/dist/chunk-CMYMTRGA.js.map +1 -0
- package/dist/{chunk-UD4BHQMI.js → chunk-IVGYLCFH.js} +2 -2
- package/dist/{chunk-UD4BHQMI.js.map → chunk-IVGYLCFH.js.map} +1 -1
- package/dist/{chunk-VNOOH22O.js → chunk-OOL3675H.js} +85 -4
- package/dist/chunk-OOL3675H.js.map +1 -0
- package/dist/{chunk-5AVV7KAH.js → chunk-QK4DV5PR.js} +2 -2
- package/dist/chunk-R2VAJGR3.js +214 -0
- package/dist/chunk-R2VAJGR3.js.map +1 -0
- package/dist/{chunk-N7EJV7N3.js → chunk-RYBVU4M3.js} +3592 -3562
- package/dist/chunk-RYBVU4M3.js.map +1 -0
- package/dist/{chunk-BQPFZE2C.js → chunk-WRUSWK4F.js} +5 -5
- package/dist/{chunk-PIPPLSOF.js → chunk-ZV4LXYCJ.js} +451 -24
- package/dist/chunk-ZV4LXYCJ.js.map +1 -0
- package/dist/{worktree-harness-CX_McRLp.d.ts → completion-gate-DkAnUmpb.d.ts} +45 -45
- package/dist/{coordination-CuDLO8wj.d.ts → coordination-rRj5hjJK.d.ts} +415 -227
- package/dist/environment-provider.d.ts +3 -3
- package/dist/index.d.ts +255 -16
- package/dist/index.js +463 -72
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +228 -84
- package/dist/intelligence.js +259 -166
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +120 -0
- package/dist/knowledge.js +28 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.js +2 -2
- package/dist/{local-harness-sI0S_XNA.d.ts → local-harness-dcD5WTTr.d.ts} +3 -0
- package/dist/{loop-runner-bin-hQDUL8Ld.d.ts → loop-runner-bin-DTbZVGfM.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +6 -6
- package/dist/loop-runner-bin.js +7 -7
- package/dist/loops.d.ts +34 -369
- package/dist/loops.js +31 -5
- package/dist/mcp/bin.js +5 -5
- package/dist/mcp/index.d.ts +10 -11
- package/dist/mcp/index.js +10 -10
- package/dist/{mcp-serve-verifier-FL7-ZEb_.d.ts → mcp-serve-verifier-XsX8rkB9.d.ts} +12 -1
- package/dist/{openai-tools-BnrOmGjN.d.ts → openai-tools-C4ZfUD4L.d.ts} +1 -1
- package/dist/profiles.d.ts +196 -5
- package/dist/profiles.js +8 -0
- package/dist/profiles.js.map +1 -1
- package/dist/{router-client-r8y_VFVM.d.ts → router-client-DJImUDlm.d.ts} +1 -1
- package/dist/structural-rollout-MwlpgQ-6.d.ts +446 -0
- package/dist/supervise-DPmYPk0j.d.ts +131 -0
- package/dist/{types-ESeMOj94.d.ts → types-SyuwunY_.d.ts} +1 -1
- package/dist/{types-Driepl87.d.ts → types-eMNgWgFi.d.ts} +2 -2
- package/dist/{worktree-fanout-D6xR2CIA.d.ts → worktree-fanout-BDFQIO-Y.d.ts} +234 -234
- package/package.json +12 -4
- package/skills/agent-runtime-adoption/SKILL.md +74 -24
- package/skills/build-with-agent-runtime/SKILL.md +23 -20
- package/skills/loop-writer/SKILL.md +6 -5
- package/skills/supervise/SKILL.md +2 -2
- package/dist/chunk-7LO5GMAO.js.map +0 -1
- package/dist/chunk-N7EJV7N3.js.map +0 -1
- package/dist/chunk-PIPPLSOF.js.map +0 -1
- package/dist/chunk-VNOOH22O.js.map +0 -1
- package/dist/otel-export-BKmNwiCb.d.ts +0 -180
- /package/dist/{chunk-4WXGK6GV.js.map → chunk-7ON74BQO.js.map} +0 -0
- /package/dist/{chunk-5AVV7KAH.js.map → chunk-QK4DV5PR.js.map} +0 -0
- /package/dist/{chunk-BQPFZE2C.js.map → chunk-WRUSWK4F.js.map} +0 -0
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
definePersona,
|
|
6
6
|
runPersonified,
|
|
7
7
|
worktreeFanout
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import {
|
|
10
|
-
createExecutorRegistry
|
|
11
|
-
} from "./chunk-N7EJV7N3.js";
|
|
8
|
+
} from "./chunk-ZV4LXYCJ.js";
|
|
12
9
|
import {
|
|
13
10
|
runAnalystLoop
|
|
14
11
|
} from "./chunk-ZQZX77MM.js";
|
|
12
|
+
import {
|
|
13
|
+
createExecutorRegistry
|
|
14
|
+
} from "./chunk-RYBVU4M3.js";
|
|
15
15
|
import {
|
|
16
16
|
ConfigError
|
|
17
17
|
} from "./chunk-YEJR7IXO.js";
|
|
@@ -196,4 +196,4 @@ export {
|
|
|
196
196
|
runLoopRunnerCli,
|
|
197
197
|
parseLoopRunnerArgv
|
|
198
198
|
};
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
199
|
+
//# sourceMappingURL=chunk-WRUSWK4F.js.map
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
settledToIteration,
|
|
16
16
|
supervise,
|
|
17
17
|
withDriverExecutor
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-RYBVU4M3.js";
|
|
19
19
|
import {
|
|
20
20
|
addTokenUsage,
|
|
21
21
|
isAbortError,
|
|
@@ -2738,20 +2738,29 @@ async function consultAnalyst(task, messages, instruction, opts) {
|
|
|
2738
2738
|
const trajectory = compactTrajectory(messages);
|
|
2739
2739
|
const analystModel = opts.analystModel ?? opts.model;
|
|
2740
2740
|
const chat = analystChat(opts, analystModel);
|
|
2741
|
+
const consultMessages = trajectory ? [
|
|
2742
|
+
{ role: "system", content: instruction },
|
|
2743
|
+
{
|
|
2744
|
+
role: "user",
|
|
2745
|
+
content: `TASK: ${task.userPrompt.slice(0, 1500)}
|
|
2746
|
+
|
|
2747
|
+
TRAJECTORY:
|
|
2748
|
+
${trajectory}`
|
|
2749
|
+
}
|
|
2750
|
+
] : [
|
|
2751
|
+
{
|
|
2752
|
+
role: "user",
|
|
2753
|
+
content: `${instruction}
|
|
2754
|
+
|
|
2755
|
+
TASK:
|
|
2756
|
+
${task.userPrompt.slice(0, 1500)}`
|
|
2757
|
+
}
|
|
2758
|
+
];
|
|
2741
2759
|
const res = await chat.chat({
|
|
2742
2760
|
model: analystModel,
|
|
2743
2761
|
temperature: 0.2,
|
|
2744
2762
|
maxTokens: 1024,
|
|
2745
|
-
messages:
|
|
2746
|
-
{ role: "system", content: instruction },
|
|
2747
|
-
{
|
|
2748
|
-
role: "user",
|
|
2749
|
-
content: `TASK: ${task.userPrompt.slice(0, 1500)}
|
|
2750
|
-
|
|
2751
|
-
TRAJECTORY:
|
|
2752
|
-
${trajectory}`
|
|
2753
|
-
}
|
|
2754
|
-
]
|
|
2763
|
+
messages: consultMessages
|
|
2755
2764
|
});
|
|
2756
2765
|
const usage = res.usage;
|
|
2757
2766
|
return {
|
|
@@ -2797,6 +2806,30 @@ async function analyze(task, messages, opts) {
|
|
|
2797
2806
|
const steer = obs.findings.map((f) => f.recommended_action).filter((a) => typeof a === "string" && a.trim().length > 0).join("\n").trim();
|
|
2798
2807
|
return { steer: steer || "COMPLETE", tokens };
|
|
2799
2808
|
}
|
|
2809
|
+
async function renderCorpusReadback(opts) {
|
|
2810
|
+
if (!opts.corpus || !opts.corpusReadback) return "";
|
|
2811
|
+
const maxFacts = opts.corpusReadback.maxFacts ?? 3;
|
|
2812
|
+
if (!Number.isInteger(maxFacts) || maxFacts < 0) {
|
|
2813
|
+
throw new Error(`corpusReadback.maxFacts must be a non-negative integer, got ${maxFacts}`);
|
|
2814
|
+
}
|
|
2815
|
+
if (maxFacts === 0) return "";
|
|
2816
|
+
const tags = [
|
|
2817
|
+
...opts.corpusTags ?? [],
|
|
2818
|
+
...opts.corpusReadback.tags ?? [],
|
|
2819
|
+
...opts.corpusReadback.includeOperatorFacts ? [] : ["audience:agent"]
|
|
2820
|
+
];
|
|
2821
|
+
const facts = await opts.corpus.query({
|
|
2822
|
+
...tags.length > 0 ? { tags } : {},
|
|
2823
|
+
minConfidence: opts.corpusReadback.minConfidence ?? 0.7,
|
|
2824
|
+
limit: maxFacts
|
|
2825
|
+
});
|
|
2826
|
+
if (facts.length === 0) return "";
|
|
2827
|
+
const rendered = facts.map(
|
|
2828
|
+
(fact) => fact.rationale ? `- ${fact.claim} (${fact.rationale})` : `- ${fact.claim}`
|
|
2829
|
+
);
|
|
2830
|
+
return `Relevant learned facts from prior attempts:
|
|
2831
|
+
${rendered.join("\n")}`;
|
|
2832
|
+
}
|
|
2800
2833
|
function shotExecutor(surface, opts) {
|
|
2801
2834
|
let artifact;
|
|
2802
2835
|
return {
|
|
@@ -2941,7 +2974,8 @@ function depthStrategy(surface, task, opts, cfg) {
|
|
|
2941
2974
|
try {
|
|
2942
2975
|
for (shots = 0; shots < cfg.maxShots; shots += 1) {
|
|
2943
2976
|
const child = leaf(`shot:${shots}`, "shot");
|
|
2944
|
-
const
|
|
2977
|
+
const memorySteer = await renderCorpusReadback(opts);
|
|
2978
|
+
const steer = [shots === 0 ? void 0 : pendingSteer, memorySteer].filter((part) => typeof part === "string" && part.trim().length > 0).join("\n\n");
|
|
2945
2979
|
const res = scope.spawn(child, { task, handle, messages, steer }, {
|
|
2946
2980
|
budget: perChild(innerTurns),
|
|
2947
2981
|
label: `shot:${shots}`
|
|
@@ -3536,6 +3570,11 @@ async function openSandboxRun(client, options, deliverable) {
|
|
|
3536
3570
|
options.promptOptions
|
|
3537
3571
|
);
|
|
3538
3572
|
handle = r.handle;
|
|
3573
|
+
await options.beforeStart?.({
|
|
3574
|
+
box: handle.box,
|
|
3575
|
+
sessionId: handle.sessionId,
|
|
3576
|
+
signal: options.signal
|
|
3577
|
+
});
|
|
3539
3578
|
const result = await settle2(handle.box, r.events);
|
|
3540
3579
|
turnCount += 1;
|
|
3541
3580
|
emit({
|
|
@@ -4999,6 +5038,381 @@ function deriveTurnSignal(callerSignal, timeoutMs) {
|
|
|
4999
5038
|
};
|
|
5000
5039
|
}
|
|
5001
5040
|
|
|
5041
|
+
// src/runtime/structural-rollout.ts
|
|
5042
|
+
import { randomBytes } from "crypto";
|
|
5043
|
+
var defaultStructuralRolloutPolicy = {
|
|
5044
|
+
k: 5,
|
|
5045
|
+
repairRounds: 2,
|
|
5046
|
+
testgen: 6
|
|
5047
|
+
};
|
|
5048
|
+
function resolvePolicy(overrides) {
|
|
5049
|
+
const policy = { ...defaultStructuralRolloutPolicy, ...overrides };
|
|
5050
|
+
if (!Number.isInteger(policy.k) || policy.k < 1) {
|
|
5051
|
+
throw new Error(`structuralRollout: policy.k must be an integer >= 1, got ${policy.k}`);
|
|
5052
|
+
}
|
|
5053
|
+
if (!Number.isInteger(policy.repairRounds) || policy.repairRounds < 0) {
|
|
5054
|
+
throw new Error(
|
|
5055
|
+
`structuralRollout: policy.repairRounds must be an integer >= 0, got ${policy.repairRounds}`
|
|
5056
|
+
);
|
|
5057
|
+
}
|
|
5058
|
+
if (!Number.isInteger(policy.testgen) || policy.testgen < 0) {
|
|
5059
|
+
throw new Error(
|
|
5060
|
+
`structuralRollout: policy.testgen must be an integer >= 0, got ${policy.testgen}`
|
|
5061
|
+
);
|
|
5062
|
+
}
|
|
5063
|
+
return policy;
|
|
5064
|
+
}
|
|
5065
|
+
var authorInstruction = (count, entry) => `Read the task below. Write exactly ${count} single-line assert statements that test the function \`${entry}\`, based ONLY on the behavior the task itself describes. Each assert must be one physical line of the form \`assert ${entry}(...) == expected\` (or a True/False check). Do NOT implement the function. Do NOT copy shown examples verbatim if you can test other cases too. Output ONLY the assert lines inside a single \`\`\`python code block.`;
|
|
5066
|
+
function filterAuthoredAsserts(reply, entrySymbol, count) {
|
|
5067
|
+
const fences = [...reply.matchAll(/```(?:python|py)?\s*\n([\s\S]*?)```/gi)].map(
|
|
5068
|
+
(m) => (m[1] ?? "").trim()
|
|
5069
|
+
);
|
|
5070
|
+
const block = fences.length > 0 ? fences.join("\n") : reply;
|
|
5071
|
+
const balanced = (s) => {
|
|
5072
|
+
let d = 0;
|
|
5073
|
+
for (const ch of s) {
|
|
5074
|
+
if (ch === "(" || ch === "[" || ch === "{") d += 1;
|
|
5075
|
+
else if (ch === ")" || ch === "]" || ch === "}") d -= 1;
|
|
5076
|
+
if (d < 0) return false;
|
|
5077
|
+
}
|
|
5078
|
+
return d === 0;
|
|
5079
|
+
};
|
|
5080
|
+
return block.split("\n").map((l) => l.trim()).filter((l) => l.startsWith("assert ") && l.includes(entrySymbol) && balanced(l)).slice(0, count);
|
|
5081
|
+
}
|
|
5082
|
+
function modelAuthoredChecks(overrides = {}) {
|
|
5083
|
+
return {
|
|
5084
|
+
async generate(_task, ctx) {
|
|
5085
|
+
const count = overrides.count ?? ctx.count;
|
|
5086
|
+
if (count <= 0 || !ctx.entrySymbol) return [];
|
|
5087
|
+
const entry = ctx.entrySymbol;
|
|
5088
|
+
const reply = await ctx.consult(authorInstruction(count, entry));
|
|
5089
|
+
if (!reply) return [];
|
|
5090
|
+
return filterAuthoredAsserts(reply, entry, count).map((code) => ({
|
|
5091
|
+
code,
|
|
5092
|
+
kind: "authored"
|
|
5093
|
+
}));
|
|
5094
|
+
}
|
|
5095
|
+
};
|
|
5096
|
+
}
|
|
5097
|
+
function officialChecksFromMeta(key = "visibleChecks") {
|
|
5098
|
+
return {
|
|
5099
|
+
async generate(task) {
|
|
5100
|
+
const raw = task.meta?.[key];
|
|
5101
|
+
if (!Array.isArray(raw)) return [];
|
|
5102
|
+
return raw.filter((c) => typeof c === "string" && c.trim().length > 0).map((code) => ({ code, kind: "official" }));
|
|
5103
|
+
}
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
function composeCheckSources(...sources) {
|
|
5107
|
+
return {
|
|
5108
|
+
async generate(task, ctx) {
|
|
5109
|
+
const all = [];
|
|
5110
|
+
for (const source of sources) all.push(...await source.generate(task, ctx));
|
|
5111
|
+
return all;
|
|
5112
|
+
}
|
|
5113
|
+
};
|
|
5114
|
+
}
|
|
5115
|
+
function resolveEntrySymbol(task) {
|
|
5116
|
+
const meta = task.meta?.entryPoint;
|
|
5117
|
+
if (typeof meta === "string" && meta.trim().length > 0) return meta.trim();
|
|
5118
|
+
const defs = [...task.userPrompt.matchAll(/(?:^|\n)\s*def\s+([A-Za-z_]\w*)\s*\(/g)];
|
|
5119
|
+
const last = defs[defs.length - 1];
|
|
5120
|
+
return last?.[1];
|
|
5121
|
+
}
|
|
5122
|
+
function buildCheckProgram(candidate, official, authored, nonce) {
|
|
5123
|
+
const officialB64 = Buffer.from(JSON.stringify(official), "utf8").toString("base64");
|
|
5124
|
+
const authoredB64 = Buffer.from(JSON.stringify(authored), "utf8").toString("base64");
|
|
5125
|
+
return `${candidate}
|
|
5126
|
+
|
|
5127
|
+
import base64 as _b64, json as _json, sys as _sys
|
|
5128
|
+
_official = _json.loads(_b64.b64decode("${officialB64}").decode("utf8"))
|
|
5129
|
+
_authored = _json.loads(_b64.b64decode("${authoredB64}").decode("utf8"))
|
|
5130
|
+
_lines = []
|
|
5131
|
+
def _run(_tests):
|
|
5132
|
+
_att, _fail = 0, 0
|
|
5133
|
+
for _t in _tests:
|
|
5134
|
+
_att += 1
|
|
5135
|
+
try:
|
|
5136
|
+
exec(_t, dict(globals()))
|
|
5137
|
+
except Exception as _e:
|
|
5138
|
+
_fail += 1
|
|
5139
|
+
_lines.append("CHECK FAILED: %s -> %s: %s" % (_t.strip()[:200], type(_e).__name__, str(_e)[:200]))
|
|
5140
|
+
return _att, _fail
|
|
5141
|
+
_o_att, _o_fail = _run(_official)
|
|
5142
|
+
_a_att, _a_fail = _run(_authored)
|
|
5143
|
+
print("SRCK-${nonce} official=%d/%d authored=%d/%d" % (_o_att - _o_fail, _o_att, _a_att - _a_fail, _a_att))
|
|
5144
|
+
_sys.stdout.write("\\n".join(_lines)[-1500:])
|
|
5145
|
+
_sys.exit(0 if (_o_fail + _a_fail) == 0 and (_o_att + _a_att) > 0 else 1)
|
|
5146
|
+
`;
|
|
5147
|
+
}
|
|
5148
|
+
function sandboxCheckRunner(options = {}) {
|
|
5149
|
+
const python = options.python ?? "python3";
|
|
5150
|
+
const timeoutMs = options.timeoutMs ?? 2e4;
|
|
5151
|
+
return {
|
|
5152
|
+
async run(candidate, checks, ctx) {
|
|
5153
|
+
if (checks.length === 0) {
|
|
5154
|
+
return {
|
|
5155
|
+
passedOfficial: 0,
|
|
5156
|
+
totalOfficial: 0,
|
|
5157
|
+
passedAuthored: 0,
|
|
5158
|
+
totalAuthored: 0,
|
|
5159
|
+
failureOutput: ""
|
|
5160
|
+
};
|
|
5161
|
+
}
|
|
5162
|
+
const box = ctx.box ?? options.box;
|
|
5163
|
+
if (!box) {
|
|
5164
|
+
throw new Error(
|
|
5165
|
+
"sandboxCheckRunner: no execution channel \u2014 bind one via sandboxCheckRunner({ box }) or CheckRunContext.box (ValidationCtx.box / a sandbox instance). Refusing to score without executing: a silent 0 would poison selection."
|
|
5166
|
+
);
|
|
5167
|
+
}
|
|
5168
|
+
const nonce = randomBytes(8).toString("hex");
|
|
5169
|
+
const official = checks.filter((c) => c.kind === "official").map((c) => c.code);
|
|
5170
|
+
const authored = checks.filter((c) => c.kind === "authored").map((c) => c.code);
|
|
5171
|
+
const program = buildCheckProgram(candidate, official, authored, nonce);
|
|
5172
|
+
const b64 = Buffer.from(program, "utf8").toString("base64");
|
|
5173
|
+
const r = await box.exec(`printf '%s' '${b64}' | base64 -d | ${python} -`, { timeoutMs });
|
|
5174
|
+
const summary = new RegExp(
|
|
5175
|
+
`SRCK-${nonce} official=(\\d+)/(\\d+) authored=(\\d+)/(\\d+)`
|
|
5176
|
+
).exec(r.stdout);
|
|
5177
|
+
if (!summary) {
|
|
5178
|
+
const detail = (r.stderr || r.stdout).slice(-1500) || "no output (crashed or timed out before the checks could run)";
|
|
5179
|
+
return {
|
|
5180
|
+
passedOfficial: 0,
|
|
5181
|
+
totalOfficial: 0,
|
|
5182
|
+
passedAuthored: 0,
|
|
5183
|
+
totalAuthored: 0,
|
|
5184
|
+
failureOutput: detail,
|
|
5185
|
+
crashed: true
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
const failureOutput = r.stdout.replace(summary[0], "").slice(-1500).trim();
|
|
5189
|
+
return {
|
|
5190
|
+
passedOfficial: Number(summary[1]),
|
|
5191
|
+
totalOfficial: Number(summary[2]),
|
|
5192
|
+
passedAuthored: Number(summary[3]),
|
|
5193
|
+
totalAuthored: Number(summary[4]),
|
|
5194
|
+
failureOutput
|
|
5195
|
+
};
|
|
5196
|
+
}
|
|
5197
|
+
};
|
|
5198
|
+
}
|
|
5199
|
+
var frac = (passed, total) => total > 0 ? passed / total : 0;
|
|
5200
|
+
function compareCheckOutcomes(a, b) {
|
|
5201
|
+
const aCrashed = a.crashed === true;
|
|
5202
|
+
const bCrashed = b.crashed === true;
|
|
5203
|
+
if (aCrashed !== bCrashed) return aCrashed ? -1 : 1;
|
|
5204
|
+
if (aCrashed) return 0;
|
|
5205
|
+
const official = frac(a.passedOfficial, a.totalOfficial) - frac(b.passedOfficial, b.totalOfficial);
|
|
5206
|
+
if (official !== 0) return official;
|
|
5207
|
+
return frac(a.passedAuthored, a.totalAuthored) - frac(b.passedAuthored, b.totalAuthored);
|
|
5208
|
+
}
|
|
5209
|
+
function visibleCheckScore(o) {
|
|
5210
|
+
if (o.crashed) return -1;
|
|
5211
|
+
return frac(o.passedOfficial, o.totalOfficial) + 1e-3 * frac(o.passedAuthored, o.totalAuthored);
|
|
5212
|
+
}
|
|
5213
|
+
function selectBestIndex(outcomes) {
|
|
5214
|
+
let best = 0;
|
|
5215
|
+
for (let i = 1; i < outcomes.length; i += 1) {
|
|
5216
|
+
if (compareCheckOutcomes(outcomes[i], outcomes[best]) > 0) {
|
|
5217
|
+
best = i;
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
return best;
|
|
5221
|
+
}
|
|
5222
|
+
function canDisplace(challenger, incumbent) {
|
|
5223
|
+
if (challenger.crashed === true) return false;
|
|
5224
|
+
if (challenger.passedOfficial < incumbent.passedOfficial) return false;
|
|
5225
|
+
return compareCheckOutcomes(challenger, incumbent) > 0;
|
|
5226
|
+
}
|
|
5227
|
+
var totalChecks = (o) => o.totalOfficial + o.totalAuthored;
|
|
5228
|
+
var passesAllChecks = (o) => o.crashed !== true && totalChecks(o) > 0 && o.passedOfficial === o.totalOfficial && o.passedAuthored === o.totalAuthored;
|
|
5229
|
+
function defaultExtractCandidate(messages) {
|
|
5230
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
5231
|
+
const calls = messages[i]?.tool_calls;
|
|
5232
|
+
if (!calls) continue;
|
|
5233
|
+
for (let j = calls.length - 1; j >= 0; j -= 1) {
|
|
5234
|
+
const call = calls[j];
|
|
5235
|
+
if (call?.function?.name !== "submit_answer") continue;
|
|
5236
|
+
try {
|
|
5237
|
+
const args = JSON.parse(call.function.arguments ?? "{}");
|
|
5238
|
+
if (typeof args.answer === "string" && args.answer.trim()) return args.answer.trim();
|
|
5239
|
+
} catch {
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
const contents = [];
|
|
5244
|
+
for (const m of messages) {
|
|
5245
|
+
if (m.role === "assistant" && typeof m.content === "string" && m.content.trim()) {
|
|
5246
|
+
contents.push(m.content);
|
|
5247
|
+
}
|
|
5248
|
+
}
|
|
5249
|
+
const fencesOf = (text) => [...text.matchAll(/```(?:python|py)?\s*\n([\s\S]*?)```/gi)].map((m) => (m[1] ?? "").trim());
|
|
5250
|
+
for (let i = contents.length - 1; i >= 0; i -= 1) {
|
|
5251
|
+
const fences = fencesOf(contents[i]);
|
|
5252
|
+
for (let j = fences.length - 1; j >= 0; j -= 1) {
|
|
5253
|
+
if (/(^|\n)\s*def\s+\w+/.test(fences[j])) return fences[j];
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
for (let i = contents.length - 1; i >= 0; i -= 1) {
|
|
5257
|
+
const fences = fencesOf(contents[i]);
|
|
5258
|
+
if (fences.length > 0) return fences[fences.length - 1];
|
|
5259
|
+
}
|
|
5260
|
+
return (contents[contents.length - 1] ?? "").trim();
|
|
5261
|
+
}
|
|
5262
|
+
var DIVERSE_LENSES = [
|
|
5263
|
+
"Answer directly and decisively from what you already know. State the single best answer without hedging.",
|
|
5264
|
+
"Decompose the question into the sub-facts it depends on. Establish each sub-fact explicitly, then compose them into the answer.",
|
|
5265
|
+
"Reason from first principles. Ignore the most obvious or popular guess; derive the answer from underlying facts and relationships.",
|
|
5266
|
+
"Name the most plausible WRONG answer and the trap that makes it tempting. Rule it out, then commit to the answer that survives."
|
|
5267
|
+
];
|
|
5268
|
+
function slotLens(slot) {
|
|
5269
|
+
const lens = DIVERSE_LENSES[slot % DIVERSE_LENSES.length];
|
|
5270
|
+
const tag = slot < DIVERSE_LENSES.length ? "" : ` (variant ${Math.floor(slot / DIVERSE_LENSES.length) + 1})`;
|
|
5271
|
+
return `${lens}${tag}`;
|
|
5272
|
+
}
|
|
5273
|
+
function repairSteer(outcome) {
|
|
5274
|
+
return [
|
|
5275
|
+
"Your latest solution failed some of the task-visible checks.",
|
|
5276
|
+
"Result of running the visible checks against it:",
|
|
5277
|
+
"```",
|
|
5278
|
+
outcome.failureOutput.trim() || "(the code crashed before the checks could run)",
|
|
5279
|
+
"```",
|
|
5280
|
+
"Fix the solution so the visible checks pass. Provide the COMPLETE corrected solution the",
|
|
5281
|
+
"same way you provided the original (same tool or format) \u2014 not a fragment or a diff."
|
|
5282
|
+
].join("\n");
|
|
5283
|
+
}
|
|
5284
|
+
function describeOutcome(label, o) {
|
|
5285
|
+
if (o.crashed) return `${label}: crashed before the checks could run`;
|
|
5286
|
+
return `${label}: official ${o.passedOfficial}/${o.totalOfficial}, authored ${o.passedAuthored}/${o.totalAuthored}`;
|
|
5287
|
+
}
|
|
5288
|
+
function structuralRollout(config = {}) {
|
|
5289
|
+
const policy = resolvePolicy(config.policy);
|
|
5290
|
+
const checkSource = config.checkSource ?? composeCheckSources(officialChecksFromMeta(), modelAuthoredChecks());
|
|
5291
|
+
const checkRunner = config.checkRunner ?? sandboxCheckRunner();
|
|
5292
|
+
const extract = config.extractCandidate ?? defaultExtractCandidate;
|
|
5293
|
+
const inner = defineStrategy(
|
|
5294
|
+
"structuralRollout",
|
|
5295
|
+
async (ctx) => {
|
|
5296
|
+
const { task, shot } = ctx;
|
|
5297
|
+
const progression = [];
|
|
5298
|
+
const receipts = [];
|
|
5299
|
+
let completions = 0;
|
|
5300
|
+
let shots = 0;
|
|
5301
|
+
const consult = async (instruction) => {
|
|
5302
|
+
const reply = await ctx.consult([], instruction);
|
|
5303
|
+
completions += 1;
|
|
5304
|
+
return reply;
|
|
5305
|
+
};
|
|
5306
|
+
const entrySymbol = resolveEntrySymbol(task);
|
|
5307
|
+
const checks = await checkSource.generate(task, {
|
|
5308
|
+
count: policy.testgen,
|
|
5309
|
+
...entrySymbol ? { entrySymbol } : {},
|
|
5310
|
+
consult
|
|
5311
|
+
});
|
|
5312
|
+
const officialChecks = checks.filter((c) => c.kind === "official").length;
|
|
5313
|
+
const authoredChecks = checks.length - officialChecks;
|
|
5314
|
+
const runCtx = { task, ...config.box ? { box: config.box } : {} };
|
|
5315
|
+
const candidates = [];
|
|
5316
|
+
for (let i = 0; i < policy.k; i += 1) {
|
|
5317
|
+
const out = await shot(policy.diverse ? { steer: slotLens(i) } : void 0);
|
|
5318
|
+
if (!out) break;
|
|
5319
|
+
shots += 1;
|
|
5320
|
+
completions += out.completions;
|
|
5321
|
+
progression.push(out.score);
|
|
5322
|
+
const outcome = await checkRunner.run(extract(out.messages), checks, runCtx);
|
|
5323
|
+
candidates.push({
|
|
5324
|
+
index: candidates.length,
|
|
5325
|
+
messages: out.messages,
|
|
5326
|
+
outcome,
|
|
5327
|
+
shotScore: out.score,
|
|
5328
|
+
shotResolved: out.total > 0 && out.passes === out.total
|
|
5329
|
+
});
|
|
5330
|
+
}
|
|
5331
|
+
if (candidates.length === 0) {
|
|
5332
|
+
return {
|
|
5333
|
+
score: 0,
|
|
5334
|
+
resolved: false,
|
|
5335
|
+
completions,
|
|
5336
|
+
progression,
|
|
5337
|
+
shots,
|
|
5338
|
+
selection: receipts,
|
|
5339
|
+
repairStop: "no-candidates",
|
|
5340
|
+
officialChecks,
|
|
5341
|
+
authoredChecks
|
|
5342
|
+
};
|
|
5343
|
+
}
|
|
5344
|
+
let best = candidates[selectBestIndex(candidates.map((c) => c.outcome))];
|
|
5345
|
+
for (const c of candidates) {
|
|
5346
|
+
receipts.push({
|
|
5347
|
+
candidateIndex: c.index,
|
|
5348
|
+
selected: false,
|
|
5349
|
+
score: visibleCheckScore(c.outcome),
|
|
5350
|
+
reason: describeOutcome("sample", c.outcome),
|
|
5351
|
+
selector: "driver"
|
|
5352
|
+
});
|
|
5353
|
+
}
|
|
5354
|
+
let seq = candidates.length;
|
|
5355
|
+
let repairStop = "already-passing";
|
|
5356
|
+
if (!passesAllChecks(best.outcome)) {
|
|
5357
|
+
if (best.outcome.crashed !== true && totalChecks(best.outcome) === 0) {
|
|
5358
|
+
repairStop = "no-signal";
|
|
5359
|
+
} else {
|
|
5360
|
+
repairStop = "rounds-exhausted";
|
|
5361
|
+
for (let r = 0; r < policy.repairRounds; r += 1) {
|
|
5362
|
+
const out = await shot({ messages: best.messages, steer: repairSteer(best.outcome) });
|
|
5363
|
+
if (!out) break;
|
|
5364
|
+
shots += 1;
|
|
5365
|
+
completions += out.completions;
|
|
5366
|
+
progression.push(out.score);
|
|
5367
|
+
const outcome = await checkRunner.run(extract(out.messages), checks, runCtx);
|
|
5368
|
+
const displaced = canDisplace(outcome, best.outcome);
|
|
5369
|
+
const label = displaced ? "repair (displaced the incumbent)" : outcome.crashed !== true && outcome.passedOfficial < best.outcome.passedOfficial ? "repair (held out: passes fewer official checks than the incumbent)" : "repair (held out: no improvement)";
|
|
5370
|
+
receipts.push({
|
|
5371
|
+
candidateIndex: seq,
|
|
5372
|
+
selected: false,
|
|
5373
|
+
score: visibleCheckScore(outcome),
|
|
5374
|
+
reason: describeOutcome(label, outcome),
|
|
5375
|
+
selector: "driver"
|
|
5376
|
+
});
|
|
5377
|
+
if (displaced) {
|
|
5378
|
+
best = {
|
|
5379
|
+
index: seq,
|
|
5380
|
+
messages: out.messages,
|
|
5381
|
+
outcome,
|
|
5382
|
+
shotScore: out.score,
|
|
5383
|
+
shotResolved: out.total > 0 && out.passes === out.total
|
|
5384
|
+
};
|
|
5385
|
+
}
|
|
5386
|
+
seq += 1;
|
|
5387
|
+
if (passesAllChecks(best.outcome)) {
|
|
5388
|
+
repairStop = "repaired-pass";
|
|
5389
|
+
break;
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
const winner = receipts.find((r) => r.candidateIndex === best.index);
|
|
5395
|
+
if (winner) winner.selected = true;
|
|
5396
|
+
return {
|
|
5397
|
+
score: best.shotScore,
|
|
5398
|
+
resolved: best.shotResolved,
|
|
5399
|
+
completions,
|
|
5400
|
+
progression,
|
|
5401
|
+
shots,
|
|
5402
|
+
selection: receipts,
|
|
5403
|
+
repairStop,
|
|
5404
|
+
officialChecks,
|
|
5405
|
+
authoredChecks
|
|
5406
|
+
};
|
|
5407
|
+
}
|
|
5408
|
+
);
|
|
5409
|
+
if (policy.temperature === void 0) return inner;
|
|
5410
|
+
return {
|
|
5411
|
+
name: inner.name,
|
|
5412
|
+
driver: (surface, task, opts, budget) => inner.driver(surface, task, { ...opts, temperature: policy.temperature }, budget)
|
|
5413
|
+
};
|
|
5414
|
+
}
|
|
5415
|
+
|
|
5002
5416
|
// src/runtime/supervise/detector-monitor.ts
|
|
5003
5417
|
import {
|
|
5004
5418
|
argHash,
|
|
@@ -5815,6 +6229,30 @@ export {
|
|
|
5815
6229
|
createSandboxPromptBackend,
|
|
5816
6230
|
createOpenAICompatibleBackend,
|
|
5817
6231
|
normalizeBackendStreamEvent,
|
|
6232
|
+
defaultAnalystInstruction,
|
|
6233
|
+
observe,
|
|
6234
|
+
renderReport,
|
|
6235
|
+
depthStrategy,
|
|
6236
|
+
breadthStrategy,
|
|
6237
|
+
sample,
|
|
6238
|
+
refine,
|
|
6239
|
+
defineStrategy,
|
|
6240
|
+
adaptiveRefine,
|
|
6241
|
+
sampleThenRefine,
|
|
6242
|
+
runAgentic,
|
|
6243
|
+
defaultStructuralRolloutPolicy,
|
|
6244
|
+
filterAuthoredAsserts,
|
|
6245
|
+
modelAuthoredChecks,
|
|
6246
|
+
officialChecksFromMeta,
|
|
6247
|
+
composeCheckSources,
|
|
6248
|
+
resolveEntrySymbol,
|
|
6249
|
+
sandboxCheckRunner,
|
|
6250
|
+
compareCheckOutcomes,
|
|
6251
|
+
visibleCheckScore,
|
|
6252
|
+
selectBestIndex,
|
|
6253
|
+
canDisplace,
|
|
6254
|
+
defaultExtractCandidate,
|
|
6255
|
+
structuralRollout,
|
|
5818
6256
|
anytimeReport,
|
|
5819
6257
|
renderAnytimeTable,
|
|
5820
6258
|
defaultAuditorInstruction,
|
|
@@ -5837,9 +6275,6 @@ export {
|
|
|
5837
6275
|
naiveDriver,
|
|
5838
6276
|
dumbDriver,
|
|
5839
6277
|
defineLeaderboard,
|
|
5840
|
-
defaultAnalystInstruction,
|
|
5841
|
-
observe,
|
|
5842
|
-
renderReport,
|
|
5843
6278
|
harvestCorpus,
|
|
5844
6279
|
inProcessSandboxClient,
|
|
5845
6280
|
createMcpEnvironment,
|
|
@@ -5866,14 +6301,6 @@ export {
|
|
|
5866
6301
|
trajectoryReport,
|
|
5867
6302
|
equalKOnCost,
|
|
5868
6303
|
promotionGate,
|
|
5869
|
-
depthStrategy,
|
|
5870
|
-
breadthStrategy,
|
|
5871
|
-
sample,
|
|
5872
|
-
refine,
|
|
5873
|
-
defineStrategy,
|
|
5874
|
-
adaptiveRefine,
|
|
5875
|
-
sampleThenRefine,
|
|
5876
|
-
runAgentic,
|
|
5877
6304
|
runBenchmark,
|
|
5878
6305
|
printBenchmarkReport,
|
|
5879
6306
|
SandboxRunAbortError,
|
|
@@ -5907,4 +6334,4 @@ export {
|
|
|
5907
6334
|
computeFindingId,
|
|
5908
6335
|
makeFinding2 as makeFinding
|
|
5909
6336
|
};
|
|
5910
|
-
//# sourceMappingURL=chunk-
|
|
6337
|
+
//# sourceMappingURL=chunk-ZV4LXYCJ.js.map
|