@tangle-network/agent-runtime 0.173.0 → 0.174.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/{activation-DkZiIzqK.js → activation-CsdJWRXX.js} +2 -2
- package/dist/{activation-DkZiIzqK.js.map → activation-CsdJWRXX.js.map} +1 -1
- package/dist/agent.js +2 -2
- package/dist/{authoring-B4aR-Tea.js → authoring-DsLNInAz.js} +2 -2
- package/dist/{authoring-B4aR-Tea.js.map → authoring-DsLNInAz.js.map} +1 -1
- package/dist/durable.js +1 -1
- package/dist/{graph-CoSt0kup.js → graph-BbeHgLXH.js} +2 -2
- package/dist/{graph-CoSt0kup.js.map → graph-BbeHgLXH.js.map} +1 -1
- package/dist/graph.js +9 -4
- package/dist/graph.js.map +1 -1
- package/dist/{improvement-cycle-lP-F7B60.js → improvement-cycle-DKGDCukL.js} +155 -8
- package/dist/improvement-cycle-DKGDCukL.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/intelligence.d.ts +1 -1
- package/dist/intelligence.js +3 -3
- package/dist/kernel.js +6 -6
- package/dist/{knowledge-DCepYOlH.js → knowledge-BaAX0HVu.js} +3 -3
- package/dist/{knowledge-DCepYOlH.js.map → knowledge-BaAX0HVu.js.map} +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-CTCi_rSV.js → loop-runner-bin-D63Tytdk.js} +3 -3
- package/dist/{loop-runner-bin-CTCi_rSV.js.map → loop-runner-bin-D63Tytdk.js.map} +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-B4BPplKi.js → openai-tools-BBgjWYNw.js} +2 -2
- package/dist/{openai-tools-B4BPplKi.js.map → openai-tools-BBgjWYNw.js.map} +1 -1
- package/dist/{redact-6S20u4Ii.d.ts → redact-DvLf4x1m.d.ts} +49 -5
- package/dist/{runtime-l9Q9-Dal.js → runtime-CojgP-hr.js} +6 -6
- package/dist/{runtime-l9Q9-Dal.js.map → runtime-CojgP-hr.js.map} +1 -1
- package/dist/{structural-rollout-CIK7nvSH.js → structural-rollout-BUYA61iV.js} +2 -2
- package/dist/{structural-rollout-CIK7nvSH.js.map → structural-rollout-BUYA61iV.js.map} +1 -1
- package/dist/{supervise-Dq_D3QbE.js → supervise-Ci0RfWQF.js} +2 -2
- package/dist/{supervise-Dq_D3QbE.js.map → supervise-Ci0RfWQF.js.map} +1 -1
- package/dist/{supervisor-cAFpYJWF.js → supervisor-Bt1XLCVq.js} +2 -2
- package/dist/{supervisor-cAFpYJWF.js.map → supervisor-Bt1XLCVq.js.map} +1 -1
- package/dist/testing.js +11 -11
- package/package.json +1 -1
- package/dist/improvement-cycle-lP-F7B60.js.map +0 -1
|
@@ -3,8 +3,8 @@ import { n as streamAgentTurn, t as collectAgentTurn } from "./stream-agent-turn
|
|
|
3
3
|
import { n as detachedSnapshot } from "./snapshot-CTAf4uuA.js";
|
|
4
4
|
import { $ as parseAgentCandidateProfileActivation, J as assertCandidateProfileBinding, K as agentCandidateProfileAsAgentProfile, Q as omitUndefinedObjectFields, Y as createAgentCandidateProfileActivation, Z as materializeAgentCandidateProfilePlan, at as canonicalCandidateDocument, ct as immutableCandidateValue, d as verifiedResourceTextByDigest, dt as verifyCanonicalCandidateDocument, et as parseExactAgentProfile, f as verifyAgentCandidateBundle, it as canonicalCandidateDigest$1, lt as omitTopLevelDigest, n as executePreparedAgentCandidate, q as applyExactAgentProfileDiff, rt as canonicalCandidateBytes, t as prepareAgentCandidateExecution } from "./prepare-BAyaNoZu.js";
|
|
5
5
|
import { a as concreteProfileModel, t as assertExecutableAgentProfile } from "./model-policy-Sw4ywhtL.js";
|
|
6
|
-
import { Qt as runSettledCommand, U as createExecutor } from "./supervisor-
|
|
7
|
-
import { D as optimizerMethod, a as defaultStructuralRolloutPolicy } from "./structural-rollout-
|
|
6
|
+
import { Qt as runSettledCommand, U as createExecutor } from "./supervisor-Bt1XLCVq.js";
|
|
7
|
+
import { D as optimizerMethod, a as defaultStructuralRolloutPolicy } from "./structural-rollout-BUYA61iV.js";
|
|
8
8
|
import { t as runAnalystLoop } from "./analyst-loop-Bouu53-l.js";
|
|
9
9
|
import { AGENT_IMPROVEMENT_SOURCE_METADATA_KEY, agentCandidateMaterializationReceiptSchema, agentCandidateRunReceiptSchema, agentImprovementActivationSchema, agentImprovementProposalSchema, agentImprovementReviewSchema, agentImprovementSourceMetadata, agentImprovementSourceSchema, agentProfileDiffSchema, agentProfileImprovementArmSchema, agentProfileImprovementExecutionRefSchema, agentProfileModelHintsSchema, agentProfileSchema, applyAgentProfileDiff, candidateExecutionEvidenceSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, changedProfileImprovementSurfaces, defineAgentProfileDiff, diffAgentProfiles, numbersApproximatelyEqual, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
10
10
|
import { CostLedger, canonicalJson, makeProposalFinding } from "@tangle-network/agent-eval";
|
|
@@ -12,11 +12,78 @@ import { campaignScenarioIdentity, campaignSplitDigestFromIdentities, compareOpt
|
|
|
12
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
13
|
import { basename, join, resolve } from "node:path";
|
|
14
14
|
import { realpath } from "node:fs/promises";
|
|
15
|
-
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
15
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync } from "node:fs";
|
|
16
16
|
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
17
18
|
import { isDeepStrictEqual } from "node:util";
|
|
18
19
|
import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
|
|
19
20
|
import { measuredComparisonFromAgentProfileImprovementExperiment, measuredComparisonFromCandidateExperiment, runAgentProfileImprovementExperiment, runCandidateExperiment, sealAgentProfileImprovementExperiment, sealAgentProfileImprovementSuite, sealAgentProfileImprovementTask, sealCandidateExperiment, selfImprove, verifyAgentProfileImprovementExperimentComparison, verifyCandidateExperiment, verifyCandidateExperimentComparison } from "@tangle-network/agent-eval/contract";
|
|
21
|
+
//#region src/improvement/worktree-tree.ts
|
|
22
|
+
/**
|
|
23
|
+
* The exact content of a candidate worktree, as a Git tree object.
|
|
24
|
+
*
|
|
25
|
+
* A multi-shot candidate edits ONE directory in place, so the tree a shot
|
|
26
|
+
* produced is gone as soon as the next shot writes over it. Writing that
|
|
27
|
+
* content into the object store is what makes an earlier tree recoverable:
|
|
28
|
+
* `agenticGenerator` snapshots a tree that verified, and puts it back when a
|
|
29
|
+
* later shot ends the budget on a worse one.
|
|
30
|
+
*
|
|
31
|
+
* The snapshot stages into a PRIVATE index file, so the index the driver later
|
|
32
|
+
* commits from is untouched.
|
|
33
|
+
*/
|
|
34
|
+
/** Write the worktree's current content into the object store and return its tree id. */
|
|
35
|
+
function snapshotWorktreeTree(worktreePath) {
|
|
36
|
+
const scratch = mkdtempSync(join(tmpdir(), "agentic-generator-tree-"));
|
|
37
|
+
const indexFile = join(scratch, "index");
|
|
38
|
+
try {
|
|
39
|
+
git(worktreePath, ["read-tree", "HEAD"], indexFile);
|
|
40
|
+
git(worktreePath, ["add", "--all"], indexFile);
|
|
41
|
+
return git(worktreePath, ["write-tree"], indexFile);
|
|
42
|
+
} finally {
|
|
43
|
+
rmSync(scratch, {
|
|
44
|
+
recursive: true,
|
|
45
|
+
force: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Put a snapshotted tree back into the worktree, then prove the directory
|
|
51
|
+
* holds exactly that tree.
|
|
52
|
+
*
|
|
53
|
+
* The proof is not ceremony: a restore that lands the wrong bytes ships the
|
|
54
|
+
* wrong candidate, and every artifact downstream still reads as though the
|
|
55
|
+
* best tree shipped.
|
|
56
|
+
*/
|
|
57
|
+
function restoreWorktreeTree(worktreePath, tree) {
|
|
58
|
+
git(worktreePath, [
|
|
59
|
+
"read-tree",
|
|
60
|
+
"-u",
|
|
61
|
+
"--reset",
|
|
62
|
+
tree
|
|
63
|
+
]);
|
|
64
|
+
git(worktreePath, [
|
|
65
|
+
"clean",
|
|
66
|
+
"--force",
|
|
67
|
+
"-d",
|
|
68
|
+
"--quiet"
|
|
69
|
+
]);
|
|
70
|
+
const restored = snapshotWorktreeTree(worktreePath);
|
|
71
|
+
if (restored !== tree) throw new Error(`agenticGenerator: restoring tree ${tree} into ${worktreePath} produced ${restored}`);
|
|
72
|
+
}
|
|
73
|
+
function git(cwd, args, indexFile) {
|
|
74
|
+
const env = { ...process.env };
|
|
75
|
+
if (indexFile) env.GIT_INDEX_FILE = indexFile;
|
|
76
|
+
else delete env.GIT_INDEX_FILE;
|
|
77
|
+
const result = spawnSync("git", args, {
|
|
78
|
+
cwd,
|
|
79
|
+
encoding: "utf-8",
|
|
80
|
+
env
|
|
81
|
+
});
|
|
82
|
+
if (result.error) throw new Error(`agenticGenerator: git ${args[0]} failed to spawn in ${cwd}: ${result.error.message}`);
|
|
83
|
+
if (result.status !== 0) throw new Error(`agenticGenerator: git ${args[0]} exited ${result.status} in ${cwd}: ${result.stderr.trim()}`);
|
|
84
|
+
return result.stdout.trim();
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
20
87
|
//#region src/improvement/agentic-generator.ts
|
|
21
88
|
/**
|
|
22
89
|
*
|
|
@@ -43,10 +110,20 @@ import { measuredComparisonFromAgentProfileImprovementExperiment, measuredCompar
|
|
|
43
110
|
* (the worktree persists, so the harness RESUMES atop its own failing
|
|
44
111
|
* edits with the error in hand — no session-specific retry path needed)
|
|
45
112
|
* - dirty + `verify` ok (or no verifier configured) → return the candidate
|
|
113
|
+
* - dirty + `verify` ok + `keepGoing` → bank the tree and spend the next shot
|
|
46
114
|
* A candidate that never verifies within `maxShots` is discarded (`applied:
|
|
47
115
|
* false`), never shipped — if you configured a verifier, a non-passing tree is
|
|
48
116
|
* not a candidate. With no verifier, the first dirty shot is the candidate.
|
|
49
117
|
*
|
|
118
|
+
* BEST-OF-N is the `keepGoing` path, and the loop owns it end to end. A
|
|
119
|
+
* verifier that passes a tree and asks for another shot has its tree
|
|
120
|
+
* snapshotted as a Git tree object; when the budget ends, the highest-`score`
|
|
121
|
+
* tree is RESTORED into the worktree and returned as the candidate. So the
|
|
122
|
+
* caller ranks and the loop moves the bytes — a caller never has to write a
|
|
123
|
+
* passing tree back itself. The budget ends on the last shot, or earlier on a
|
|
124
|
+
* `keepGoing`-less pass, and a last shot that broke or reverted the change does
|
|
125
|
+
* not cost the candidate the verified tree an earlier shot produced.
|
|
126
|
+
*
|
|
50
127
|
* @stable
|
|
51
128
|
*/
|
|
52
129
|
const RAW_TRACE_ANALYST_ID = "raw-trace-distiller";
|
|
@@ -77,8 +154,31 @@ function agenticGenerator(opts) {
|
|
|
77
154
|
const needsRawTraceEvidence = requiresRawTraceEvidence(findings);
|
|
78
155
|
const shots = Math.max(1, maxShots);
|
|
79
156
|
let attemptNote = "";
|
|
157
|
+
let best = null;
|
|
158
|
+
let scored = null;
|
|
159
|
+
let lastReceipt = null;
|
|
160
|
+
/** Ship the best tree this candidate produced, restoring it when a later
|
|
161
|
+
* shot wrote over it. */
|
|
162
|
+
const shipBankedTree = async (receipt, banked) => {
|
|
163
|
+
const restoredFromShot = banked.onDisk ? null : banked.shot;
|
|
164
|
+
if (!banked.onDisk) {
|
|
165
|
+
if (banked.tree === null) throw new Error(`agenticGenerator: shot ${banked.shot} produced the best tree but it was never snapshotted`);
|
|
166
|
+
restoreWorktreeTree(worktreePath, banked.tree);
|
|
167
|
+
banked.onDisk = true;
|
|
168
|
+
}
|
|
169
|
+
signal.throwIfAborted();
|
|
170
|
+
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
171
|
+
kind: "accepted",
|
|
172
|
+
worktreePath,
|
|
173
|
+
verified: true,
|
|
174
|
+
restoredFromShot
|
|
175
|
+
});
|
|
176
|
+
signal.throwIfAborted();
|
|
177
|
+
return acceptedCandidate(findings);
|
|
178
|
+
};
|
|
80
179
|
for (let shot = 0; shot < shots; shot++) {
|
|
81
180
|
signal.throwIfAborted();
|
|
181
|
+
if (best) best.onDisk = false;
|
|
82
182
|
const taskPrompt = attemptNote ? `${basePrompt}\n\n${attemptNote}` : basePrompt;
|
|
83
183
|
const startedAt = /* @__PURE__ */ new Date();
|
|
84
184
|
let turn = null;
|
|
@@ -144,6 +244,7 @@ function agenticGenerator(opts) {
|
|
|
144
244
|
costReceipt,
|
|
145
245
|
error: shotError
|
|
146
246
|
});
|
|
247
|
+
lastReceipt = receipt;
|
|
147
248
|
await emitShotReceipt(opts.onShotCompleted, receipt, execution, shotError);
|
|
148
249
|
signal.throwIfAborted();
|
|
149
250
|
if (!execution) throw new Error("agenticGenerator: author shot completed without a Runtime turn");
|
|
@@ -190,7 +291,8 @@ function agenticGenerator(opts) {
|
|
|
190
291
|
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
191
292
|
kind: "accepted",
|
|
192
293
|
worktreePath,
|
|
193
|
-
verified: false
|
|
294
|
+
verified: false,
|
|
295
|
+
restoredFromShot: null
|
|
194
296
|
});
|
|
195
297
|
signal.throwIfAborted();
|
|
196
298
|
return acceptedCandidate(findings);
|
|
@@ -205,14 +307,35 @@ function agenticGenerator(opts) {
|
|
|
205
307
|
return rethrowShotSetupError(opts.onShotDisposition, receipt, worktreePath, "verification", cause);
|
|
206
308
|
}
|
|
207
309
|
if (result.ok) {
|
|
310
|
+
const score = admittedScore(result, scored, shot);
|
|
311
|
+
scored = score !== null;
|
|
312
|
+
const previousBest = best;
|
|
313
|
+
let banked;
|
|
314
|
+
if (previousBest === null || (score ?? 0) >= (previousBest.score ?? 0)) banked = {
|
|
315
|
+
shot: shot + 1,
|
|
316
|
+
score,
|
|
317
|
+
tree: null,
|
|
318
|
+
onDisk: true
|
|
319
|
+
};
|
|
320
|
+
else banked = previousBest;
|
|
321
|
+
const becomesBest = banked !== previousBest;
|
|
322
|
+
best = banked;
|
|
323
|
+
if (result.keepGoing !== true) {
|
|
324
|
+
signal.throwIfAborted();
|
|
325
|
+
return await shipBankedTree(receipt, banked);
|
|
326
|
+
}
|
|
327
|
+
if (becomesBest && shot < shots - 1) banked.tree = snapshotWorktreeTree(worktreePath);
|
|
208
328
|
signal.throwIfAborted();
|
|
209
329
|
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
210
|
-
kind: "
|
|
330
|
+
kind: "kept",
|
|
211
331
|
worktreePath,
|
|
212
|
-
|
|
332
|
+
score,
|
|
333
|
+
best: becomesBest,
|
|
334
|
+
feedback: result.feedback ?? null
|
|
213
335
|
});
|
|
214
336
|
signal.throwIfAborted();
|
|
215
|
-
|
|
337
|
+
attemptNote = keptNote(result.feedback);
|
|
338
|
+
continue;
|
|
216
339
|
}
|
|
217
340
|
signal.throwIfAborted();
|
|
218
341
|
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
@@ -224,6 +347,10 @@ function agenticGenerator(opts) {
|
|
|
224
347
|
signal.throwIfAborted();
|
|
225
348
|
attemptNote = failureNote(result.feedback);
|
|
226
349
|
}
|
|
350
|
+
if (best !== null) {
|
|
351
|
+
if (!lastReceipt) throw new Error("agenticGenerator: a tree was banked without a shot receipt");
|
|
352
|
+
return await shipBankedTree(lastReceipt, best);
|
|
353
|
+
}
|
|
227
354
|
return {
|
|
228
355
|
applied: false,
|
|
229
356
|
summary: ""
|
|
@@ -231,6 +358,14 @@ function agenticGenerator(opts) {
|
|
|
231
358
|
}
|
|
232
359
|
};
|
|
233
360
|
}
|
|
361
|
+
/** The rank a passing tree carries, refusing a set of trees that cannot be ordered. */
|
|
362
|
+
function admittedScore(result, scored, shot) {
|
|
363
|
+
const has = result.score !== void 0;
|
|
364
|
+
if (scored !== null && has !== scored) throw new Error(`agenticGenerator: verify ${has ? "scored" : "did not score"} the tree from shot ${shot + 1} and ${scored ? "scored" : "did not score"} an earlier passing tree; a scored tree cannot be ranked against an unscored one`);
|
|
365
|
+
if (!has) return null;
|
|
366
|
+
if (typeof result.score !== "number" || !Number.isFinite(result.score)) throw new Error(`agenticGenerator: verify returned a non-finite score (${String(result.score)}) for shot ${shot + 1}`);
|
|
367
|
+
return result.score;
|
|
368
|
+
}
|
|
234
369
|
async function emitShotReceipt(callback, receipt, execution, primaryError) {
|
|
235
370
|
try {
|
|
236
371
|
await callback?.(receipt, execution);
|
|
@@ -373,6 +508,18 @@ function failureNote(feedback) {
|
|
|
373
508
|
detail ? `Verifier output:\n${truncate$1(detail, 4e3)}` : "No verifier detail was captured."
|
|
374
509
|
].join("\n");
|
|
375
510
|
}
|
|
511
|
+
/** Next-shot feedback when the worktree PASSED and the verifier asked for
|
|
512
|
+
* another shot. The passing tree is banked, so the author is told to improve
|
|
513
|
+
* it rather than protect it — a worse tree cannot cost it the candidate. */
|
|
514
|
+
function keptNote(feedback) {
|
|
515
|
+
const detail = feedback?.trim();
|
|
516
|
+
return [
|
|
517
|
+
"NOTE: your edits are in the working tree and verification PASSED.",
|
|
518
|
+
"Shots remain in this budget — keep improving the change in place, do not revert it.",
|
|
519
|
+
"The best version you produce is the one that ships.",
|
|
520
|
+
detail ? `Verifier output:\n${truncate$1(detail, 4e3)}` : "No verifier detail was captured."
|
|
521
|
+
].join("\n");
|
|
522
|
+
}
|
|
376
523
|
function rawTraceEvidenceProblem(worktreePath, findings) {
|
|
377
524
|
if (worktreeChangedPaths(worktreePath).filter((path) => path !== RAW_TRACE_DIAGNOSIS_PATH).length === 0) return [`NOTE: raw-trace mode requires a real code/config edit in addition to ${RAW_TRACE_DIAGNOSIS_PATH}.`, "Your previous attempt only changed the diagnosis artifact. Inspect the cited traces and make the causal code change."].join("\n");
|
|
378
525
|
const diagnosisPath = join(worktreePath, RAW_TRACE_DIAGNOSIS_PATH);
|
|
@@ -3080,4 +3227,4 @@ function sameOrderedValues(left, right) {
|
|
|
3080
3227
|
//#endregion
|
|
3081
3228
|
export { agentImprovementTargetInput as A, ROLLOUT_POLICY_EXTENSION as B, optimizationActivationReceiptFromMetadata as C, agentImprovementProfileSurfaceDigest as D, agentImprovementProfileDiffs as E, isAgentImprovementProfileSurface as F, structuralRolloutPolicyFromProfile as G, normalizeRolloutPolicy as H, isAgentProfileMeasuredSurface as I, defaultBuildPrompt as J, agenticGenerator as K, improve as L, agentProfileImprovementStateDigest as M, assertProfileImprovementTargetsShareIdentity as N, agentImprovementProfileSurfaceInput as O, buildAgentImprovementActivationTargets as P, withMethodRuntimeControls as R, createOptimizationActivationReceipt as S, AGENT_PROFILE_MEASURED_SURFACES as T, parseRolloutPolicy as U, applyRolloutPolicyToProfile as V, serializeRolloutPolicy as W, profilePolicyWithBudget as _, executeAgentCandidateExperimentCell as a, profileTaskScenarioIdentity as b, requireSealedCandidateExperiment as c, verifyAgentImprovementActivation as d, verifyAgentImprovementProposal as f, profileImprovementMetadata as g, createProfileImprovementCostLedger as h, createAgentImprovementProposal as i, agentImprovementTargetProfileDiffs as j, agentImprovementTargetDigest as k, reviewAgentImprovementProposal as l, verifyCandidateExecutionEvidence as m, createAgentImprovementActivation as n, proposeAgentImprovement as o, verifyAgentImprovementReview as p, commandVerifier as q, createAgentImprovementMeasuredComparison as r, proposeAgentProfileImprovement as s, AgentCandidateExperimentCellExecutionError as t, runAgentCandidateExperiment as u, profilePreparationAccounting as v, AGENT_IMPROVEMENT_PROFILE_SURFACES as w, sealProfileImprovementBenchmark as x, profileStateDigest as y, rawTraceDistiller as z };
|
|
3082
3229
|
|
|
3083
|
-
//# sourceMappingURL=improvement-cycle-
|
|
3230
|
+
//# sourceMappingURL=improvement-cycle-DKGDCukL.js.map
|