@tangle-network/agent-runtime 0.88.0 → 0.90.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 +51 -18
- package/dist/agent.d.ts +53 -2
- package/dist/agent.js +166 -4
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-22HPUH77.js → chunk-4IBAMGBE.js} +170 -269
- package/dist/chunk-4IBAMGBE.js.map +1 -0
- package/dist/chunk-5QOB7H74.js +387 -0
- package/dist/chunk-5QOB7H74.js.map +1 -0
- package/dist/chunk-74SBMDTO.js +214 -0
- package/dist/chunk-74SBMDTO.js.map +1 -0
- package/dist/{chunk-HBE77SWV.js → chunk-MHK62APK.js} +5 -5
- package/dist/{chunk-LRNRPJAV.js → chunk-QSNSMJSZ.js} +2622 -2842
- package/dist/chunk-QSNSMJSZ.js.map +1 -0
- package/dist/{chunk-VNOOH22O.js → chunk-XMOU4WEY.js} +74 -3
- package/dist/chunk-XMOU4WEY.js.map +1 -0
- package/dist/{chunk-JHULWWQD.js → chunk-XQEISTK2.js} +2 -2
- package/dist/{worktree-harness-CX_McRLp.d.ts → completion-gate-BDaBP8dd.d.ts} +44 -44
- package/dist/{coordination-CuDLO8wj.d.ts → coordination-DxHduZg7.d.ts} +414 -226
- package/dist/environment-provider.d.ts +3 -3
- package/dist/index.d.ts +156 -13
- package/dist/index.js +316 -70
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +2 -2
- package/dist/knowledge.d.ts +120 -0
- package/dist/knowledge.js +28 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lifecycle.js +1 -1
- package/dist/{loop-runner-bin-hQDUL8Ld.d.ts → loop-runner-bin-D3GmB2Ru.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +5 -5
- package/dist/loops.d.ts +46 -324
- package/dist/loops.js +3 -15
- package/dist/mcp/bin.js +2 -2
- package/dist/mcp/index.d.ts +8 -9
- package/dist/mcp/index.js +7 -7
- package/dist/{openai-tools-BnrOmGjN.d.ts → openai-tools-D0xmzo0y.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/supervise-BpCdssu0.d.ts +131 -0
- package/dist/{types-Driepl87.d.ts → types-DAJQRIUD.d.ts} +2 -2
- package/dist/{types-ESeMOj94.d.ts → types-Dnk189QA.d.ts} +1 -1
- package/dist/{worktree-fanout-D6xR2CIA.d.ts → worktree-fanout-CfRXYmgV.d.ts} +3 -3
- package/package.json +12 -4
- package/skills/agent-runtime-adoption/SKILL.md +74 -24
- package/skills/build-with-agent-runtime/SKILL.md +3 -9
- package/skills/loop-writer/SKILL.md +6 -78
- package/skills/supervise/SKILL.md +2 -2
- package/dist/chunk-22HPUH77.js.map +0 -1
- package/dist/chunk-LRNRPJAV.js.map +0 -1
- package/dist/chunk-VNOOH22O.js.map +0 -1
- package/dist/otel-export-BKmNwiCb.d.ts +0 -180
- /package/dist/{chunk-HBE77SWV.js.map → chunk-MHK62APK.js.map} +0 -0
- /package/dist/{chunk-JHULWWQD.js.map → chunk-XQEISTK2.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mcpToolsForRuntimeMcp,
|
|
3
3
|
mcpToolsForRuntimeMcpSubset
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XQEISTK2.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_ROUTER_BASE_URL,
|
|
7
7
|
cleanModelId,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
runLoopRunnerCli,
|
|
21
21
|
selfImproveLoopRunner,
|
|
22
22
|
worktreeLoopRunner
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-MHK62APK.js";
|
|
24
24
|
import "./chunk-SGKPNBXE.js";
|
|
25
25
|
import {
|
|
26
26
|
InMemoryRuntimeSessionStore,
|
|
@@ -31,14 +31,33 @@ import {
|
|
|
31
31
|
normalizeBackendStreamEvent,
|
|
32
32
|
nowIso,
|
|
33
33
|
touchSession
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-4IBAMGBE.js";
|
|
35
|
+
import "./chunk-ZQZX77MM.js";
|
|
36
|
+
import {
|
|
37
|
+
agenticGenerator,
|
|
38
|
+
commandVerifier,
|
|
39
|
+
mcpBuildPrompt,
|
|
40
|
+
mcpServeVerifier,
|
|
41
|
+
toolBuildPrompt
|
|
42
|
+
} from "./chunk-XMOU4WEY.js";
|
|
43
|
+
import {
|
|
44
|
+
RESEARCH_SUPERVISOR_SYSTEM_PROMPT,
|
|
45
|
+
createAgentKnowledgeReadinessCheck,
|
|
46
|
+
createSupervisedKnowledgeUpdater,
|
|
47
|
+
formatSupervisedKnowledgeTask,
|
|
48
|
+
knowledgeReadinessDeliverable,
|
|
49
|
+
runKnowledgeImprovementJob,
|
|
50
|
+
runSupervisedKnowledgeUpdate
|
|
51
|
+
} from "./chunk-74SBMDTO.js";
|
|
52
|
+
import "./chunk-5QOB7H74.js";
|
|
35
53
|
import {
|
|
36
54
|
assertModelAllowed,
|
|
37
55
|
composeRuntimeHooks,
|
|
38
56
|
defineRuntimeHooks,
|
|
39
57
|
notifyRuntimeDecisionPoint,
|
|
40
58
|
notifyRuntimeHookEvent
|
|
41
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-QSNSMJSZ.js";
|
|
60
|
+
import "./chunk-DPEUKJRO.js";
|
|
42
61
|
import {
|
|
43
62
|
INTELLIGENCE_WIRE_VERSION,
|
|
44
63
|
buildLoopOtelSpans,
|
|
@@ -48,15 +67,7 @@ import {
|
|
|
48
67
|
loopEventToOtelSpan
|
|
49
68
|
} from "./chunk-UD4BHQMI.js";
|
|
50
69
|
import "./chunk-BZF3KQ6G.js";
|
|
51
|
-
import "./chunk-ZQZX77MM.js";
|
|
52
70
|
import "./chunk-FVJ7M3DA.js";
|
|
53
|
-
import {
|
|
54
|
-
agenticGenerator,
|
|
55
|
-
commandVerifier,
|
|
56
|
-
mcpBuildPrompt,
|
|
57
|
-
mcpServeVerifier,
|
|
58
|
-
toolBuildPrompt
|
|
59
|
-
} from "./chunk-VNOOH22O.js";
|
|
60
71
|
import "./chunk-7LO5GMAO.js";
|
|
61
72
|
import {
|
|
62
73
|
AgentEvalError,
|
|
@@ -69,7 +80,6 @@ import {
|
|
|
69
80
|
SessionMismatchError,
|
|
70
81
|
ValidationError
|
|
71
82
|
} from "./chunk-YEJR7IXO.js";
|
|
72
|
-
import "./chunk-DPEUKJRO.js";
|
|
73
83
|
import "./chunk-DGUM43GV.js";
|
|
74
84
|
|
|
75
85
|
// src/conversation/call-policy.ts
|
|
@@ -171,7 +181,7 @@ function computeBackoff(spec, attempt) {
|
|
|
171
181
|
return Math.max(0, spec);
|
|
172
182
|
}
|
|
173
183
|
function sleep(ms) {
|
|
174
|
-
return new Promise((
|
|
184
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
175
185
|
}
|
|
176
186
|
|
|
177
187
|
// src/conversation/headers.ts
|
|
@@ -1272,10 +1282,233 @@ function deriveExecutionId(input) {
|
|
|
1272
1282
|
}
|
|
1273
1283
|
|
|
1274
1284
|
// src/improvement/improve.ts
|
|
1275
|
-
import {
|
|
1285
|
+
import {
|
|
1286
|
+
gepaProposer,
|
|
1287
|
+
gitWorktreeAdapter,
|
|
1288
|
+
skillOptProposer
|
|
1289
|
+
} from "@tangle-network/agent-eval/campaign";
|
|
1276
1290
|
import {
|
|
1277
1291
|
selfImprove
|
|
1278
1292
|
} from "@tangle-network/agent-eval/contract";
|
|
1293
|
+
|
|
1294
|
+
// src/improvement/improvement-driver.ts
|
|
1295
|
+
function improvementDriver(opts) {
|
|
1296
|
+
const baseRef = opts.baseRef ?? "main";
|
|
1297
|
+
return {
|
|
1298
|
+
kind: `improvement:${opts.generator.kind}`,
|
|
1299
|
+
async propose(ctx) {
|
|
1300
|
+
const findings = resolveFindings(ctx);
|
|
1301
|
+
if (findings.length === 0 && ctx.report === void 0) return [];
|
|
1302
|
+
const surfaces = [];
|
|
1303
|
+
for (let i = 0; i < ctx.populationSize; i++) {
|
|
1304
|
+
if (ctx.signal.aborted) break;
|
|
1305
|
+
const wt = await opts.worktree.create({
|
|
1306
|
+
baseRef,
|
|
1307
|
+
label: `${opts.generator.kind}-gen${ctx.generation}-cand${i}`
|
|
1308
|
+
});
|
|
1309
|
+
try {
|
|
1310
|
+
const { applied, summary } = await opts.generator.generate({
|
|
1311
|
+
worktreePath: wt.path,
|
|
1312
|
+
report: ctx.report,
|
|
1313
|
+
findings,
|
|
1314
|
+
dataset: ctx.dataset,
|
|
1315
|
+
maxShots: ctx.maxImprovementShots ?? 1,
|
|
1316
|
+
signal: ctx.signal
|
|
1317
|
+
});
|
|
1318
|
+
if (!applied) {
|
|
1319
|
+
await opts.worktree.discard(wt);
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
surfaces.push(await opts.worktree.finalize(wt, summary));
|
|
1323
|
+
} catch (err) {
|
|
1324
|
+
await opts.worktree.discard(wt).catch(() => {
|
|
1325
|
+
});
|
|
1326
|
+
throw err;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
return surfaces;
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
function resolveFindings(ctx) {
|
|
1334
|
+
const report = ctx.report;
|
|
1335
|
+
if (report && typeof report === "object" && "findings" in report) {
|
|
1336
|
+
const f = report.findings;
|
|
1337
|
+
if (Array.isArray(f) && f.length > 0) return f;
|
|
1338
|
+
}
|
|
1339
|
+
return ctx.findings;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// src/improvement/raw-trace-distiller.ts
|
|
1343
|
+
import { existsSync, readdirSync } from "fs";
|
|
1344
|
+
import { basename, join, resolve } from "path";
|
|
1345
|
+
import { makeFinding } from "@tangle-network/agent-eval";
|
|
1346
|
+
var ANALYST_ID = "raw-trace-distiller";
|
|
1347
|
+
var PASS_THRESHOLD = 0.999;
|
|
1348
|
+
function rawTraceDistiller(options = {}) {
|
|
1349
|
+
const maxCandidates = options.maxCandidates ?? 12;
|
|
1350
|
+
const maxCellsPerCandidate = options.maxCellsPerCandidate ?? 8;
|
|
1351
|
+
const maxFilesPerCell = options.maxFilesPerCell ?? 24;
|
|
1352
|
+
return async (input) => {
|
|
1353
|
+
const genRoot = absoluteRunDir(options.runDir ?? input.runDir);
|
|
1354
|
+
const durable = isDurable(genRoot);
|
|
1355
|
+
const ranked = [...input.candidates].map((c) => ({
|
|
1356
|
+
surfaceHash: c.surfaceHash,
|
|
1357
|
+
composite: c.composite,
|
|
1358
|
+
campaignDir: absoluteRunDir(c.campaign.runDir),
|
|
1359
|
+
cells: failingCells(c.campaign, maxCellsPerCandidate, maxFilesPerCell)
|
|
1360
|
+
})).sort((a, b) => a.composite - b.composite).slice(0, maxCandidates);
|
|
1361
|
+
const totalFailingCells = ranked.reduce((n, c) => n + c.cells.length, 0);
|
|
1362
|
+
if (totalFailingCells === 0) {
|
|
1363
|
+
return options.fallbackFindings ?? [
|
|
1364
|
+
makeFinding({
|
|
1365
|
+
analyst_id: ANALYST_ID,
|
|
1366
|
+
severity: "info",
|
|
1367
|
+
area: "raw-trace-context",
|
|
1368
|
+
confidence: 1,
|
|
1369
|
+
claim: `Generation ${input.generation} had no failing cells. The full raw run traces are on disk under ${genRoot}.`,
|
|
1370
|
+
recommended_action: `To keep improving, grep/cat the raw traces under ${genRoot} (per-cell spans.jsonl + cached-result.json) to find the weakest passing runs, then make a targeted harness-code edit.`,
|
|
1371
|
+
evidence_refs: [{ kind: "artifact", uri: genRoot }],
|
|
1372
|
+
metadata: { generation: input.generation, runDir: genRoot, failingCells: 0 }
|
|
1373
|
+
})
|
|
1374
|
+
];
|
|
1375
|
+
}
|
|
1376
|
+
const findings = [];
|
|
1377
|
+
findings.push(
|
|
1378
|
+
makeFinding({
|
|
1379
|
+
analyst_id: ANALYST_ID,
|
|
1380
|
+
severity: "high",
|
|
1381
|
+
area: "raw-trace-context",
|
|
1382
|
+
confidence: 1,
|
|
1383
|
+
claim: `Generation ${input.generation} produced ${totalFailingCells} failing/low-scoring cell(s) across ${ranked.length} candidate(s). Their FULL RAW run traces are on disk under ${genRoot} \u2014 the actual event logs (spans.jsonl), scores (cached-result.json), and artifacts, not a summary.${durable ? "" : " (WARNING: this run root does not exist on disk \u2014 it looks like an in-memory run; pass a real runDir to improve() to get raw-trace context.)"}`,
|
|
1384
|
+
recommended_action: `Do NOT rely on a pre-summarized finding. Before editing, DIAGNOSE from the raw traces: run \`grep\`/\`cat\`/\`ls\` over the trace files and directories named in the following findings to see exactly what each failing run did and why it scored low, then make the smallest harness-code edit that fixes the dominant failure. Start with \`grep -rIn "error" ${genRoot}\` then \`cat\` the spans.jsonl of the worst cell.`,
|
|
1385
|
+
evidence_refs: [{ kind: "artifact", uri: genRoot }],
|
|
1386
|
+
metadata: {
|
|
1387
|
+
generation: input.generation,
|
|
1388
|
+
runDir: genRoot,
|
|
1389
|
+
failingCells: totalFailingCells,
|
|
1390
|
+
candidates: ranked.length
|
|
1391
|
+
}
|
|
1392
|
+
})
|
|
1393
|
+
);
|
|
1394
|
+
for (const cand of ranked) {
|
|
1395
|
+
if (cand.cells.length === 0) continue;
|
|
1396
|
+
const scenarioList = cand.cells.map((c) => c.scenarioId).join(", ");
|
|
1397
|
+
const fileLines = cand.cells.map((c) => {
|
|
1398
|
+
const header = ` cell ${c.scenarioId} (composite ${c.composite.toFixed(3)}${c.error ? `, error: ${truncate(c.error, 160)}` : ""}) \u2014 dir ${c.cellDir}`;
|
|
1399
|
+
const files = c.files.map((f) => ` - ${f}`).join("\n");
|
|
1400
|
+
const more = c.truncatedFiles ? `
|
|
1401
|
+
- \u2026(ls ${c.cellDir} for the rest)` : "";
|
|
1402
|
+
return c.files.length > 0 ? `${header}
|
|
1403
|
+
${files}${more}` : header;
|
|
1404
|
+
}).join("\n");
|
|
1405
|
+
findings.push(
|
|
1406
|
+
makeFinding({
|
|
1407
|
+
analyst_id: ANALYST_ID,
|
|
1408
|
+
severity: cand.composite < 0.5 ? "critical" : "high",
|
|
1409
|
+
area: "raw-trace-context",
|
|
1410
|
+
confidence: 1,
|
|
1411
|
+
subject: cand.surfaceHash,
|
|
1412
|
+
claim: `Candidate ${cand.surfaceHash} scored composite ${cand.composite.toFixed(3)} with ${cand.cells.length} failing cell(s) [${scenarioList}]. Its raw traces are under ${cand.campaignDir}.`,
|
|
1413
|
+
recommended_action: `grep/cat these raw trace files to diagnose WHY this candidate failed before editing:
|
|
1414
|
+
${fileLines}
|
|
1415
|
+
Or scan the whole candidate at once: \`grep -rIn . ${cand.campaignDir}\` and \`ls -R ${cand.campaignDir}\`.`,
|
|
1416
|
+
evidence_refs: [
|
|
1417
|
+
{ kind: "artifact", uri: cand.campaignDir },
|
|
1418
|
+
...cand.cells.flatMap(
|
|
1419
|
+
(c) => c.files.map((f) => ({ kind: "artifact", uri: f }))
|
|
1420
|
+
)
|
|
1421
|
+
],
|
|
1422
|
+
metadata: {
|
|
1423
|
+
surfaceHash: cand.surfaceHash,
|
|
1424
|
+
composite: cand.composite,
|
|
1425
|
+
campaignDir: cand.campaignDir,
|
|
1426
|
+
cells: cand.cells.map((c) => ({
|
|
1427
|
+
scenarioId: c.scenarioId,
|
|
1428
|
+
composite: c.composite,
|
|
1429
|
+
cellDir: c.cellDir,
|
|
1430
|
+
files: c.files,
|
|
1431
|
+
...c.error ? { error: c.error } : {}
|
|
1432
|
+
}))
|
|
1433
|
+
}
|
|
1434
|
+
})
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
return findings;
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
function failingCells(campaign, maxCells, maxFiles) {
|
|
1441
|
+
const campaignDir = absoluteRunDir(campaign.runDir);
|
|
1442
|
+
const durable = isDurable(campaignDir);
|
|
1443
|
+
const out = [];
|
|
1444
|
+
for (const cell of campaign.cells) {
|
|
1445
|
+
const scores = Object.values(cell.judgeScores ?? {});
|
|
1446
|
+
const composite = scores.length === 0 ? 0 : scores.reduce((sum, s) => sum + (s.composite ?? 0), 0) / scores.length;
|
|
1447
|
+
if (!cell.error && composite >= PASS_THRESHOLD) continue;
|
|
1448
|
+
const cellDir = join(campaignDir, sanitizeCellId(cell.cellId));
|
|
1449
|
+
const artifactPaths = artifactPathsForCell(campaign.artifactsByPath, cell.cellId);
|
|
1450
|
+
const discovered = durable ? listTraceFiles(cellDir) : [];
|
|
1451
|
+
const canonical = [join(cellDir, "spans.jsonl"), join(cellDir, "cached-result.json")];
|
|
1452
|
+
const files = dedupeSorted([...discovered, ...artifactPaths, ...canonical]);
|
|
1453
|
+
out.push({
|
|
1454
|
+
scenarioId: cell.scenarioId,
|
|
1455
|
+
composite: Number(composite.toFixed(3)),
|
|
1456
|
+
...cell.error ? { error: cell.error } : {},
|
|
1457
|
+
cellDir,
|
|
1458
|
+
files: files.slice(0, maxFiles),
|
|
1459
|
+
truncatedFiles: files.length > maxFiles
|
|
1460
|
+
});
|
|
1461
|
+
if (out.length >= maxCells) break;
|
|
1462
|
+
}
|
|
1463
|
+
return out;
|
|
1464
|
+
}
|
|
1465
|
+
function artifactPathsForCell(artifactsByPath, cellId) {
|
|
1466
|
+
if (!artifactsByPath) return [];
|
|
1467
|
+
const prefix = `${cellId}/`;
|
|
1468
|
+
return Object.entries(artifactsByPath).filter(([key]) => key.startsWith(prefix)).map(([, absPath]) => resolve(absPath));
|
|
1469
|
+
}
|
|
1470
|
+
function listTraceFiles(dir) {
|
|
1471
|
+
const out = [];
|
|
1472
|
+
for (const entry of safeReadDir(dir)) {
|
|
1473
|
+
const full = join(dir, entry.name);
|
|
1474
|
+
if (entry.isFile()) {
|
|
1475
|
+
out.push(full);
|
|
1476
|
+
} else if (!entry.isSymbolicLink() && entry.isDirectory()) {
|
|
1477
|
+
for (const sub of safeReadDir(full)) {
|
|
1478
|
+
if (sub.isFile()) out.push(join(full, sub.name));
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return out;
|
|
1483
|
+
}
|
|
1484
|
+
function safeReadDir(dir) {
|
|
1485
|
+
try {
|
|
1486
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
1487
|
+
} catch {
|
|
1488
|
+
return [];
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
function sanitizeCellId(cellId) {
|
|
1492
|
+
return cellId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1493
|
+
}
|
|
1494
|
+
function isDurable(runDir) {
|
|
1495
|
+
return !runDir.startsWith("mem://") && existsSync(runDir);
|
|
1496
|
+
}
|
|
1497
|
+
function absoluteRunDir(runDir) {
|
|
1498
|
+
return runDir.startsWith("mem://") ? runDir : resolve(runDir);
|
|
1499
|
+
}
|
|
1500
|
+
function dedupeSorted(paths) {
|
|
1501
|
+
return [...new Set(paths)].sort((a, b) => {
|
|
1502
|
+
const da = a.slice(0, a.length - basename(a).length);
|
|
1503
|
+
const db = b.slice(0, b.length - basename(b).length);
|
|
1504
|
+
return da === db ? basename(a).localeCompare(basename(b)) : da.localeCompare(db);
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
function truncate(s, n) {
|
|
1508
|
+
return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// src/improvement/improve.ts
|
|
1279
1512
|
var defaultReflectionModel = "deepseek-v4-flash";
|
|
1280
1513
|
function llmClientOptions(llm) {
|
|
1281
1514
|
return { baseUrl: llm?.baseUrl, apiKey: llm?.apiKey };
|
|
@@ -1291,12 +1524,12 @@ function defaultGeneratorFor(surface, llm) {
|
|
|
1291
1524
|
return void 0;
|
|
1292
1525
|
}
|
|
1293
1526
|
}
|
|
1294
|
-
function baselineSurfaceFor(profile, surface) {
|
|
1527
|
+
function baselineSurfaceFor(profile, surface, skills) {
|
|
1295
1528
|
switch (surface) {
|
|
1296
1529
|
case "prompt":
|
|
1297
1530
|
return profile.prompt?.systemPrompt ?? "";
|
|
1298
1531
|
case "skills":
|
|
1299
|
-
return JSON.stringify(profile.resources?.skills ?? []);
|
|
1532
|
+
return skills?.document ?? JSON.stringify(profile.resources?.skills ?? []);
|
|
1300
1533
|
case "tools":
|
|
1301
1534
|
return JSON.stringify(profile.tools ?? {});
|
|
1302
1535
|
case "mcp":
|
|
@@ -1307,6 +1540,50 @@ function baselineSurfaceFor(profile, surface) {
|
|
|
1307
1540
|
return "";
|
|
1308
1541
|
}
|
|
1309
1542
|
}
|
|
1543
|
+
function generationFailureDistiller(staticFindings) {
|
|
1544
|
+
const CAP = 12;
|
|
1545
|
+
return async (input) => {
|
|
1546
|
+
const failures = [];
|
|
1547
|
+
for (const candidate of input.candidates) {
|
|
1548
|
+
for (const rawCell of candidate.campaign.cells) {
|
|
1549
|
+
const cell = rawCell;
|
|
1550
|
+
const scenario = String(cell.scenarioId ?? "unknown");
|
|
1551
|
+
const error = typeof cell.error === "string" ? cell.error : void 0;
|
|
1552
|
+
const judgeScores = cell.judgeScores && typeof cell.judgeScores === "object" ? Object.values(
|
|
1553
|
+
cell.judgeScores
|
|
1554
|
+
) : [];
|
|
1555
|
+
const composite = judgeScores.length === 0 ? 0 : judgeScores.reduce((sum, j) => sum + (j.composite ?? 0), 0) / judgeScores.length;
|
|
1556
|
+
if (!error && composite >= 0.999) continue;
|
|
1557
|
+
const notes = judgeScores.map((j) => j.notes).filter((n) => typeof n === "string" && n.length > 0).join("; ").slice(0, 400);
|
|
1558
|
+
failures.push({
|
|
1559
|
+
scenario,
|
|
1560
|
+
composite: Number(composite.toFixed(3)),
|
|
1561
|
+
notes,
|
|
1562
|
+
...error ? { error: error.slice(0, 200) } : {}
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
if (failures.length === 0) return staticFindings;
|
|
1567
|
+
failures.sort((a, b) => a.composite - b.composite);
|
|
1568
|
+
return failures.slice(0, CAP);
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
function codeProposerFor(surface, code) {
|
|
1572
|
+
if (surface !== "code" || !code) return void 0;
|
|
1573
|
+
const generator = code.generator ?? agenticGenerator({
|
|
1574
|
+
...code.harness ? { harness: code.harness } : {},
|
|
1575
|
+
...code.verify ? { verify: code.verify } : {},
|
|
1576
|
+
...code.timeoutMs ? { timeoutMs: code.timeoutMs } : {}
|
|
1577
|
+
});
|
|
1578
|
+
return improvementDriver({
|
|
1579
|
+
worktree: gitWorktreeAdapter({
|
|
1580
|
+
repoRoot: code.repoRoot,
|
|
1581
|
+
...code.worktreeDir ? { worktreeDir: code.worktreeDir } : {}
|
|
1582
|
+
}),
|
|
1583
|
+
generator,
|
|
1584
|
+
...code.baseRef ? { baseRef: code.baseRef } : {}
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1310
1587
|
function parseWinnerJson(winner, surface) {
|
|
1311
1588
|
try {
|
|
1312
1589
|
return JSON.parse(winner);
|
|
@@ -1340,10 +1617,10 @@ async function improve(profile, findings, opts) {
|
|
|
1340
1617
|
const surface = opts.surface ?? "prompt";
|
|
1341
1618
|
const gate = opts.gate ?? "holdout";
|
|
1342
1619
|
assertModelAllowed(opts.llm?.model ?? defaultReflectionModel, opts.allowedModels);
|
|
1343
|
-
const proposer = opts.generator ?? defaultGeneratorFor(surface, opts.llm);
|
|
1620
|
+
const proposer = opts.generator ?? defaultGeneratorFor(surface, opts.llm) ?? codeProposerFor(surface, opts.code);
|
|
1344
1621
|
if (!proposer) {
|
|
1345
1622
|
throw new ConfigError(
|
|
1346
|
-
`improve(): surface '${surface}' has no default generator \u2014 pass opts.generator (a SurfaceProposer) explicitly`
|
|
1623
|
+
surface === "code" ? `improve(): surface 'code' needs either opts.generator or opts.code ({ repoRoot, ... }) \u2014 there is no safe zero-config repo to invent` : `improve(): surface '${surface}' has no default generator \u2014 pass opts.generator (a SurfaceProposer) explicitly`
|
|
1347
1624
|
);
|
|
1348
1625
|
}
|
|
1349
1626
|
const budget = gate === "none" ? { ...opts.budget, generations: 0 } : { ...opts.budget };
|
|
@@ -1351,63 +1628,24 @@ async function improve(profile, findings, opts) {
|
|
|
1351
1628
|
agent: opts.agent,
|
|
1352
1629
|
scenarios: opts.scenarios,
|
|
1353
1630
|
judge: opts.judge,
|
|
1354
|
-
baselineSurface: baselineSurfaceFor(profile, surface),
|
|
1631
|
+
baselineSurface: baselineSurfaceFor(profile, surface, opts.skills),
|
|
1355
1632
|
proposer,
|
|
1356
1633
|
budget,
|
|
1357
1634
|
llm: opts.llm,
|
|
1358
|
-
findings
|
|
1635
|
+
findings,
|
|
1636
|
+
...opts.runDir !== void 0 ? { runDir: opts.runDir } : {},
|
|
1637
|
+
...opts.storage !== void 0 ? { storage: opts.storage } : {},
|
|
1638
|
+
...opts.analyzeGeneration === null ? {} : {
|
|
1639
|
+
analyzeGeneration: opts.analyzeGeneration ?? (opts.rawTraceContext ? rawTraceDistiller({ fallbackFindings: findings }) : generationFailureDistiller(findings))
|
|
1640
|
+
}
|
|
1359
1641
|
});
|
|
1360
1642
|
const shipped = raw.gateDecision === "ship";
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
// src/improvement/improvement-driver.ts
|
|
1366
|
-
function improvementDriver(opts) {
|
|
1367
|
-
const baseRef = opts.baseRef ?? "main";
|
|
1368
|
-
return {
|
|
1369
|
-
kind: `improvement:${opts.generator.kind}`,
|
|
1370
|
-
async propose(ctx) {
|
|
1371
|
-
const findings = resolveFindings(ctx);
|
|
1372
|
-
if (findings.length === 0 && ctx.report === void 0) return [];
|
|
1373
|
-
const surfaces = [];
|
|
1374
|
-
for (let i = 0; i < ctx.populationSize; i++) {
|
|
1375
|
-
if (ctx.signal.aborted) break;
|
|
1376
|
-
const wt = await opts.worktree.create({
|
|
1377
|
-
baseRef,
|
|
1378
|
-
label: `${opts.generator.kind}-gen${ctx.generation}-cand${i}`
|
|
1379
|
-
});
|
|
1380
|
-
try {
|
|
1381
|
-
const { applied, summary } = await opts.generator.generate({
|
|
1382
|
-
worktreePath: wt.path,
|
|
1383
|
-
report: ctx.report,
|
|
1384
|
-
findings,
|
|
1385
|
-
dataset: ctx.dataset,
|
|
1386
|
-
maxShots: ctx.maxImprovementShots ?? 1,
|
|
1387
|
-
signal: ctx.signal
|
|
1388
|
-
});
|
|
1389
|
-
if (!applied) {
|
|
1390
|
-
await opts.worktree.discard(wt);
|
|
1391
|
-
continue;
|
|
1392
|
-
}
|
|
1393
|
-
surfaces.push(await opts.worktree.finalize(wt, summary));
|
|
1394
|
-
} catch (err) {
|
|
1395
|
-
await opts.worktree.discard(wt).catch(() => {
|
|
1396
|
-
});
|
|
1397
|
-
throw err;
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
return surfaces;
|
|
1401
|
-
}
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
function resolveFindings(ctx) {
|
|
1405
|
-
const report = ctx.report;
|
|
1406
|
-
if (report && typeof report === "object" && "findings" in report) {
|
|
1407
|
-
const f = report.findings;
|
|
1408
|
-
if (Array.isArray(f) && f.length > 0) return f;
|
|
1643
|
+
const usedSkillDocument = surface === "skills" && opts.skills !== void 0;
|
|
1644
|
+
if (shipped && usedSkillDocument && typeof raw.winner.surface === "string") {
|
|
1645
|
+
opts.skills?.writeBack?.(raw.winner.surface);
|
|
1409
1646
|
}
|
|
1410
|
-
|
|
1647
|
+
const nextProfile = shipped && !usedSkillDocument ? applyWinnerToProfile(profile, surface, raw.winner.surface) : profile;
|
|
1648
|
+
return { profile: nextProfile, shipped, lift: raw.lift, gateDecision: raw.gateDecision, raw };
|
|
1411
1649
|
}
|
|
1412
1650
|
|
|
1413
1651
|
// src/improvement/reflective-generator.ts
|
|
@@ -2888,6 +3126,7 @@ export {
|
|
|
2888
3126
|
JudgeError,
|
|
2889
3127
|
NotFoundError,
|
|
2890
3128
|
PlannerError,
|
|
3129
|
+
RESEARCH_SUPERVISOR_SYSTEM_PROMPT,
|
|
2891
3130
|
RuntimeRunStateError,
|
|
2892
3131
|
SqlConversationJournal,
|
|
2893
3132
|
ValidationError,
|
|
@@ -2901,6 +3140,7 @@ export {
|
|
|
2901
3140
|
commandVerifier,
|
|
2902
3141
|
composeRuntimeHooks,
|
|
2903
3142
|
computeBackoff,
|
|
3143
|
+
createAgentKnowledgeReadinessCheck,
|
|
2904
3144
|
createConversationBackend,
|
|
2905
3145
|
createIterableBackend,
|
|
2906
3146
|
createOpenAICompatibleBackend,
|
|
@@ -2908,6 +3148,7 @@ export {
|
|
|
2908
3148
|
createRuntimeEventCollector,
|
|
2909
3149
|
createRuntimeStreamEventCollector,
|
|
2910
3150
|
createSandboxPromptBackend,
|
|
3151
|
+
createSupervisedKnowledgeUpdater,
|
|
2911
3152
|
d1ToSqlAdapter,
|
|
2912
3153
|
decideKnowledgeReadiness,
|
|
2913
3154
|
defaultIsRetryable,
|
|
@@ -2915,12 +3156,14 @@ export {
|
|
|
2915
3156
|
defineRuntimeHooks,
|
|
2916
3157
|
deriveExecutionId,
|
|
2917
3158
|
exportEvalRuns,
|
|
3159
|
+
formatSupervisedKnowledgeTask,
|
|
2918
3160
|
getModels,
|
|
2919
3161
|
handleChatTurn,
|
|
2920
3162
|
improve,
|
|
2921
3163
|
improvementDriver,
|
|
2922
3164
|
isDelegatedLoopMode,
|
|
2923
3165
|
isDepthExceeded,
|
|
3166
|
+
knowledgeReadinessDeliverable,
|
|
2924
3167
|
loopEventToOtelSpan,
|
|
2925
3168
|
makePerAttemptSignal,
|
|
2926
3169
|
mcpBuildPrompt,
|
|
@@ -2930,6 +3173,7 @@ export {
|
|
|
2930
3173
|
notifyRuntimeDecisionPoint,
|
|
2931
3174
|
notifyRuntimeHookEvent,
|
|
2932
3175
|
parseLoopRunnerArgv,
|
|
3176
|
+
rawTraceDistiller,
|
|
2933
3177
|
readDepth,
|
|
2934
3178
|
readinessServerSentEvent,
|
|
2935
3179
|
reflectiveGenerator,
|
|
@@ -2942,9 +3186,11 @@ export {
|
|
|
2942
3186
|
runConversation,
|
|
2943
3187
|
runConversationStream,
|
|
2944
3188
|
runDelegatedLoop,
|
|
3189
|
+
runKnowledgeImprovementJob,
|
|
2945
3190
|
runLoopRunnerCli,
|
|
2946
3191
|
runPersonaConversation,
|
|
2947
3192
|
runPersonaDispatch,
|
|
3193
|
+
runSupervisedKnowledgeUpdate,
|
|
2948
3194
|
runToolLoop,
|
|
2949
3195
|
runtimeStreamServerSentEvent,
|
|
2950
3196
|
sanitizeAgentRuntimeEvent,
|