@tangle-network/agent-runtime 0.95.0 → 0.96.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 +64 -15
- package/dist/activation-B0ZD7nfX.d.ts +63 -0
- package/dist/agent.d.ts +5 -169
- package/dist/agent.js +8 -229
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +6 -9
- package/dist/analyst-loop.js +1 -2
- package/dist/candidate-execution/index.js +6 -7
- package/dist/chunk-3XKSBI2U.js +474 -0
- package/dist/chunk-3XKSBI2U.js.map +1 -0
- package/dist/{chunk-6YBA64Z2.js → chunk-6XKPVJAZ.js} +5 -18
- package/dist/chunk-6XKPVJAZ.js.map +1 -0
- package/dist/{chunk-MKGRLDWB.js → chunk-BLQIYRVR.js} +17 -2
- package/dist/chunk-BLQIYRVR.js.map +1 -0
- package/dist/{chunk-QDSOD7RC.js → chunk-FD2MBMOH.js} +13 -101
- package/dist/chunk-FD2MBMOH.js.map +1 -0
- package/dist/{chunk-YLUOTX6U.js → chunk-FXF2OL34.js} +7 -7
- package/dist/{chunk-EP6RVHMX.js → chunk-HZDEXTSL.js} +848 -2
- package/dist/chunk-HZDEXTSL.js.map +1 -0
- package/dist/chunk-PSOCBNM3.js +2069 -0
- package/dist/chunk-PSOCBNM3.js.map +1 -0
- package/dist/{chunk-BPGXIKK7.js → chunk-SGQ4YIQW.js} +4 -4
- package/dist/{chunk-IADLKE7I.js → chunk-UQ6PNNXM.js} +5 -7
- package/dist/{chunk-IADLKE7I.js.map → chunk-UQ6PNNXM.js.map} +1 -1
- package/dist/{chunk-Z5I642SY.js → chunk-WYC2XJF2.js} +2 -2
- package/dist/{chunk-ZEYAT33L.js → chunk-Y3SRWZMP.js} +2 -2
- package/dist/{chunk-WTZ37EQY.js → chunk-YOLKCWRV.js} +197 -90
- package/dist/chunk-YOLKCWRV.js.map +1 -0
- package/dist/conversation.js +0 -1
- package/dist/environment-provider.js +0 -1
- package/dist/{agentic-generator-hCaQRAes.d.ts → improve-g75IE2Cx.d.ts} +152 -3
- package/dist/{improvement-adapter-BieWeK5J.d.ts → improvement-adapter-HAZz-7vK.d.ts} +8 -31
- package/dist/index.d.ts +41 -11
- package/dist/index.js +180 -51
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +16 -9
- package/dist/intelligence.js +13 -8
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +30 -13
- package/dist/knowledge.js +11 -10
- package/dist/{loop-runner-bin-BIQldFS8.d.ts → loop-runner-bin-Cn1N2rRo.d.ts} +1 -1
- package/dist/loop-runner-bin.d.ts +2 -2
- package/dist/loop-runner-bin.js +6 -8
- package/dist/loops.d.ts +1 -1
- package/dist/loops.js +4 -6
- package/dist/mcp/bin.js +3 -5
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.js +10 -12
- package/dist/mcp/index.js.map +1 -1
- package/dist/platform.js +0 -2
- package/dist/platform.js.map +1 -1
- package/dist/primeintellect/index.js +0 -1
- package/dist/primeintellect/index.js.map +1 -1
- package/dist/profiles.js +0 -1
- package/dist/profiles.js.map +1 -1
- package/dist/{types-BC3bZpH0.d.ts → types-CmYCMbFT.d.ts} +12 -54
- package/package.json +7 -12
- package/skills/build-with-agent-runtime/SKILL.md +122 -213
- package/dist/chunk-6O73TRHW.js +0 -142
- package/dist/chunk-6O73TRHW.js.map +0 -1
- package/dist/chunk-6YBA64Z2.js.map +0 -1
- package/dist/chunk-AP7CPGMZ.js +0 -334
- package/dist/chunk-AP7CPGMZ.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-DHCHL6OG.js +0 -625
- package/dist/chunk-DHCHL6OG.js.map +0 -1
- package/dist/chunk-EP6RVHMX.js.map +0 -1
- package/dist/chunk-G55QE4IQ.js +0 -1137
- package/dist/chunk-G55QE4IQ.js.map +0 -1
- package/dist/chunk-ISTDY47H.js +0 -849
- package/dist/chunk-ISTDY47H.js.map +0 -1
- package/dist/chunk-MKGRLDWB.js.map +0 -1
- package/dist/chunk-QDSOD7RC.js.map +0 -1
- package/dist/chunk-WTZ37EQY.js.map +0 -1
- package/dist/generator-YkAQrOoD.d.ts +0 -382
- package/dist/improve-B-UYaEH5.d.ts +0 -172
- package/dist/lifecycle.d.ts +0 -870
- package/dist/lifecycle.js +0 -981
- package/dist/lifecycle.js.map +0 -1
- package/dist/mcp-serve-verifier-Bs_n0xPc.d.ts +0 -34
- package/skills/agent-runtime-adoption/SKILL.md +0 -246
- /package/dist/{chunk-YLUOTX6U.js.map → chunk-FXF2OL34.js.map} +0 -0
- /package/dist/{chunk-BPGXIKK7.js.map → chunk-SGQ4YIQW.js.map} +0 -0
- /package/dist/{chunk-Z5I642SY.js.map → chunk-WYC2XJF2.js.map} +0 -0
- /package/dist/{chunk-ZEYAT33L.js.map → chunk-Y3SRWZMP.js.map} +0 -0
package/dist/chunk-DHCHL6OG.js
DELETED
|
@@ -1,625 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
harnessInvocation,
|
|
3
|
-
runLocalHarness
|
|
4
|
-
} from "./chunk-EP6RVHMX.js";
|
|
5
|
-
|
|
6
|
-
// src/improvement/agentic-generator.ts
|
|
7
|
-
import { spawnSync } from "child_process";
|
|
8
|
-
import { createHash } from "crypto";
|
|
9
|
-
import { existsSync, readFileSync, rmSync } from "fs";
|
|
10
|
-
import { join, resolve, sep } from "path";
|
|
11
|
-
import {
|
|
12
|
-
applyWorkspacePlan,
|
|
13
|
-
materializeProfile
|
|
14
|
-
} from "@tangle-network/agent-profile-materialize";
|
|
15
|
-
var RAW_TRACE_ANALYST_ID = "raw-trace-distiller";
|
|
16
|
-
var RAW_TRACE_AREA = "raw-trace-context";
|
|
17
|
-
var RAW_TRACE_DIAGNOSIS_PATH = ".improve/raw-trace-diagnosis.md";
|
|
18
|
-
var AGENTIC_PROFILE_RESOURCE_ROOT = ".agent-runtime-profile-resources";
|
|
19
|
-
function agenticGenerator(opts = {}) {
|
|
20
|
-
const harness = opts.harness ?? "claude";
|
|
21
|
-
if (opts.codexReproducible && harness !== "codex") {
|
|
22
|
-
throw new Error("agenticGenerator: codexReproducible requires harness 'codex'");
|
|
23
|
-
}
|
|
24
|
-
if (opts.codexReproducible && !opts.profile) {
|
|
25
|
-
throw new Error("agenticGenerator: codexReproducible requires an explicit author profile");
|
|
26
|
-
}
|
|
27
|
-
if (opts.codexReadDeniedPaths && !opts.codexReproducible) {
|
|
28
|
-
throw new Error("agenticGenerator: codexReadDeniedPaths requires codexReproducible");
|
|
29
|
-
}
|
|
30
|
-
if (opts.maximumCharge && !opts.codexReproducible) {
|
|
31
|
-
throw new Error("agenticGenerator: maximumCharge requires codexReproducible");
|
|
32
|
-
}
|
|
33
|
-
const profileResourcePlan = opts.codexReproducible ? authorProfileResourcePlan(opts.profile) : null;
|
|
34
|
-
const buildPrompt = opts.buildPrompt ?? defaultBuildPrompt;
|
|
35
|
-
const run = opts.runHarness ?? runLocalHarness;
|
|
36
|
-
const dirty = opts.isDirty ?? worktreeDirty;
|
|
37
|
-
const verify = opts.verify;
|
|
38
|
-
return {
|
|
39
|
-
kind: `agentic:${harness}`,
|
|
40
|
-
// The seed repo + (in rawTraceContext mode) the raw-trace filesystem context
|
|
41
|
-
// are the change signal — an agentic coder proposes from them even when the
|
|
42
|
-
// distiller yielded zero findings. Without this, the improvementDriver's
|
|
43
|
-
// empty-findings guard short-circuits and generates ZERO candidates on the
|
|
44
|
-
// first (and, for a single-generation run, only) proposal round.
|
|
45
|
-
proposesWithoutFindings: true,
|
|
46
|
-
async generate({
|
|
47
|
-
worktreePath,
|
|
48
|
-
report,
|
|
49
|
-
findings,
|
|
50
|
-
maxShots,
|
|
51
|
-
signal,
|
|
52
|
-
generation,
|
|
53
|
-
candidateIndex,
|
|
54
|
-
costLedger,
|
|
55
|
-
costPhase
|
|
56
|
-
}) {
|
|
57
|
-
let reproducibleCostLedger;
|
|
58
|
-
if (opts.codexReproducible) {
|
|
59
|
-
if (!costLedger) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
"agenticGenerator: reproducible Codex requires the run-wide CostLedger supplied by agent-eval"
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
reproducibleCostLedger = costLedger;
|
|
65
|
-
}
|
|
66
|
-
const basePrompt = appendProfileResourcePaths(
|
|
67
|
-
buildPrompt({ report, findings }),
|
|
68
|
-
profileResourcePlan
|
|
69
|
-
);
|
|
70
|
-
const needsRawTraceEvidence = requiresRawTraceEvidence(findings);
|
|
71
|
-
const shots = Math.max(1, maxShots);
|
|
72
|
-
let attemptNote = "";
|
|
73
|
-
for (let shot = 0; shot < shots; shot++) {
|
|
74
|
-
if (signal.aborted) break;
|
|
75
|
-
const taskPrompt = attemptNote ? `${basePrompt}
|
|
76
|
-
|
|
77
|
-
${attemptNote}` : basePrompt;
|
|
78
|
-
const invocation = opts.profile ? harnessInvocation(harness, opts.profile, taskPrompt, {
|
|
79
|
-
dangerouslySkipPermissions: harness === "claude",
|
|
80
|
-
...opts.codexReproducible ? { codexReproducible: true } : {}
|
|
81
|
-
}) : void 0;
|
|
82
|
-
const exactPrompt = invocation?.prompt ?? taskPrompt;
|
|
83
|
-
const readDeniedPaths = typeof opts.codexReadDeniedPaths === "function" ? opts.codexReadDeniedPaths(worktreePath) : opts.codexReadDeniedPaths;
|
|
84
|
-
const startedAt = /* @__PURE__ */ new Date();
|
|
85
|
-
let harnessResult = null;
|
|
86
|
-
let profileWorkspaceReceipt = null;
|
|
87
|
-
let costReceipt = null;
|
|
88
|
-
let costCallId = null;
|
|
89
|
-
let shotError = null;
|
|
90
|
-
try {
|
|
91
|
-
const execute = async (executionSignal) => {
|
|
92
|
-
harnessResult = await withAuthorProfileResources(
|
|
93
|
-
profileResourcePlan,
|
|
94
|
-
worktreePath,
|
|
95
|
-
async (receipt2) => {
|
|
96
|
-
profileWorkspaceReceipt = receipt2;
|
|
97
|
-
const result2 = await run({
|
|
98
|
-
harness,
|
|
99
|
-
cwd: worktreePath,
|
|
100
|
-
taskPrompt,
|
|
101
|
-
...invocation ? { invocation: { command: invocation.command, args: invocation.args } } : {},
|
|
102
|
-
// The candidate worktree is isolated and must be editable without an
|
|
103
|
-
// interactive permission prompt. Other runLocalHarness callers remain
|
|
104
|
-
// permission-safe by default.
|
|
105
|
-
dangerouslySkipPermissions: harness === "claude",
|
|
106
|
-
...opts.codexReproducible ? { codexReproducible: true } : {},
|
|
107
|
-
...readDeniedPaths ? { codexReadDeniedPaths: readDeniedPaths } : {},
|
|
108
|
-
timeoutMs: opts.timeoutMs,
|
|
109
|
-
signal: executionSignal
|
|
110
|
-
});
|
|
111
|
-
harnessResult = result2;
|
|
112
|
-
return result2;
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
const failure = shotFailure(harnessResult, exactPrompt, opts.codexReproducible === true);
|
|
116
|
-
if (failure) throw failure;
|
|
117
|
-
return harnessResult;
|
|
118
|
-
};
|
|
119
|
-
if (reproducibleCostLedger) {
|
|
120
|
-
const model = opts.profile?.model?.default;
|
|
121
|
-
if (!model) {
|
|
122
|
-
throw new Error("agenticGenerator: reproducible Codex requires profile.model.default");
|
|
123
|
-
}
|
|
124
|
-
const paid = await reproducibleCostLedger.runPaidCall({
|
|
125
|
-
channel: "driver",
|
|
126
|
-
phase: costPhase ?? "search.proposal",
|
|
127
|
-
actor: `agentic-generator:${harness}`,
|
|
128
|
-
model,
|
|
129
|
-
tags: {
|
|
130
|
-
generation: String(generation ?? -1),
|
|
131
|
-
candidateIndex: String(candidateIndex ?? -1),
|
|
132
|
-
shot: String(shot + 1)
|
|
133
|
-
},
|
|
134
|
-
signal,
|
|
135
|
-
...opts.maximumCharge ? { maximumCharge: opts.maximumCharge } : {},
|
|
136
|
-
execute,
|
|
137
|
-
receipt: (result2) => costReceiptFromHarness(result2, model),
|
|
138
|
-
receiptFromError: () => harnessResult?.usage ? costReceiptFromHarness(harnessResult, model) : void 0
|
|
139
|
-
});
|
|
140
|
-
costCallId = paid.callId ?? null;
|
|
141
|
-
costReceipt = paid.receipt ?? null;
|
|
142
|
-
if (!paid.succeeded) throw paid.error;
|
|
143
|
-
harnessResult = paid.value;
|
|
144
|
-
} else {
|
|
145
|
-
harnessResult = await execute(signal);
|
|
146
|
-
}
|
|
147
|
-
} catch (cause) {
|
|
148
|
-
shotError = cause instanceof Error ? cause : new Error(String(cause));
|
|
149
|
-
}
|
|
150
|
-
const execution = shotExecutionSnapshot(harnessResult);
|
|
151
|
-
const receipt = shotReceipt({
|
|
152
|
-
generation,
|
|
153
|
-
candidateIndex,
|
|
154
|
-
shot,
|
|
155
|
-
maxShots: shots,
|
|
156
|
-
harness,
|
|
157
|
-
profile: opts.profile,
|
|
158
|
-
prompt: exactPrompt,
|
|
159
|
-
startedAt,
|
|
160
|
-
completedAt: /* @__PURE__ */ new Date(),
|
|
161
|
-
result: execution,
|
|
162
|
-
profileWorkspaceReceipt,
|
|
163
|
-
costCallId,
|
|
164
|
-
costReceipt,
|
|
165
|
-
error: shotError
|
|
166
|
-
});
|
|
167
|
-
await emitShotReceipt(opts.onShotCompleted, receipt, execution, shotError);
|
|
168
|
-
if (!execution) {
|
|
169
|
-
throw new Error("agenticGenerator: author shot completed without a harness result");
|
|
170
|
-
}
|
|
171
|
-
let worktreeChanged;
|
|
172
|
-
try {
|
|
173
|
-
worktreeChanged = dirty(worktreePath);
|
|
174
|
-
} catch (cause) {
|
|
175
|
-
return rethrowShotSetupError(
|
|
176
|
-
opts.onShotDisposition,
|
|
177
|
-
receipt,
|
|
178
|
-
worktreePath,
|
|
179
|
-
"worktree-inspection",
|
|
180
|
-
cause
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
if (!worktreeChanged) {
|
|
184
|
-
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
185
|
-
kind: "clean",
|
|
186
|
-
worktreePath
|
|
187
|
-
});
|
|
188
|
-
attemptNote = EMPTY_TREE_NOTE;
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (needsRawTraceEvidence) {
|
|
192
|
-
let problem;
|
|
193
|
-
try {
|
|
194
|
-
problem = rawTraceEvidenceProblem(worktreePath, findings);
|
|
195
|
-
} catch (cause) {
|
|
196
|
-
return rethrowShotSetupError(
|
|
197
|
-
opts.onShotDisposition,
|
|
198
|
-
receipt,
|
|
199
|
-
worktreePath,
|
|
200
|
-
"raw-trace-evidence",
|
|
201
|
-
cause
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
if (problem) {
|
|
205
|
-
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
206
|
-
kind: "rejected",
|
|
207
|
-
worktreePath,
|
|
208
|
-
stage: "raw-trace-evidence",
|
|
209
|
-
feedback: problem
|
|
210
|
-
});
|
|
211
|
-
attemptNote = problem;
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (!verify) {
|
|
216
|
-
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
217
|
-
kind: "accepted",
|
|
218
|
-
worktreePath,
|
|
219
|
-
verified: false
|
|
220
|
-
});
|
|
221
|
-
return { applied: true, summary: summarize(findings) };
|
|
222
|
-
}
|
|
223
|
-
let result;
|
|
224
|
-
try {
|
|
225
|
-
result = await verify(worktreePath);
|
|
226
|
-
} catch (cause) {
|
|
227
|
-
return rethrowShotSetupError(
|
|
228
|
-
opts.onShotDisposition,
|
|
229
|
-
receipt,
|
|
230
|
-
worktreePath,
|
|
231
|
-
"verification",
|
|
232
|
-
cause
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (result.ok) {
|
|
236
|
-
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
237
|
-
kind: "accepted",
|
|
238
|
-
worktreePath,
|
|
239
|
-
verified: true
|
|
240
|
-
});
|
|
241
|
-
return { applied: true, summary: summarize(findings) };
|
|
242
|
-
}
|
|
243
|
-
await emitShotDisposition(opts.onShotDisposition, receipt, {
|
|
244
|
-
kind: "rejected",
|
|
245
|
-
worktreePath,
|
|
246
|
-
stage: "verification",
|
|
247
|
-
feedback: result.feedback ?? null
|
|
248
|
-
});
|
|
249
|
-
attemptNote = failureNote(result.feedback);
|
|
250
|
-
}
|
|
251
|
-
return { applied: false, summary: "" };
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
function authorProfileResourcePlan(profile) {
|
|
256
|
-
const resources = profile.resources;
|
|
257
|
-
if (!resources) return null;
|
|
258
|
-
const unsupportedKinds = [
|
|
259
|
-
resources.tools?.length ? "tools" : null,
|
|
260
|
-
resources.skills?.length ? "skills" : null,
|
|
261
|
-
resources.agents?.length ? "agents" : null
|
|
262
|
-
].filter((kind) => kind !== null);
|
|
263
|
-
if (unsupportedKinds.length > 0) {
|
|
264
|
-
throw new Error(
|
|
265
|
-
`agenticGenerator: reproducible Codex author resources support files only; unsupported: ${unsupportedKinds.join(", ")}`
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
if (!resources.files || resources.files.length === 0) return null;
|
|
269
|
-
const plan = materializeProfile(
|
|
270
|
-
{
|
|
271
|
-
name: profile.name,
|
|
272
|
-
resources: { files: resources.files }
|
|
273
|
-
},
|
|
274
|
-
"codex"
|
|
275
|
-
);
|
|
276
|
-
if (plan.unsupported.length > 0) {
|
|
277
|
-
throw new Error(
|
|
278
|
-
`agenticGenerator: author profile files could not be materialized: ${plan.unsupported.map((item) => item.reason).join("; ")}`
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
if (Object.keys(plan.env).length > 0 || plan.flags.length > 0) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
"agenticGenerator: generic author profile files unexpectedly changed spawn values"
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
const virtualRoot = resolve("/", AGENTIC_PROFILE_RESOURCE_ROOT);
|
|
287
|
-
const seen = /* @__PURE__ */ new Set();
|
|
288
|
-
for (const file of plan.files) {
|
|
289
|
-
const target = resolve("/", file.relPath);
|
|
290
|
-
if (!target.startsWith(`${virtualRoot}${sep}`)) {
|
|
291
|
-
throw new Error(
|
|
292
|
-
`agenticGenerator: author profile file must be below ${AGENTIC_PROFILE_RESOURCE_ROOT}: ${file.relPath}`
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
if (seen.has(target)) {
|
|
296
|
-
throw new Error(`agenticGenerator: duplicate author profile file path: ${file.relPath}`);
|
|
297
|
-
}
|
|
298
|
-
seen.add(target);
|
|
299
|
-
}
|
|
300
|
-
return plan;
|
|
301
|
-
}
|
|
302
|
-
function appendProfileResourcePaths(prompt, plan) {
|
|
303
|
-
if (!plan) return prompt;
|
|
304
|
-
return [
|
|
305
|
-
prompt,
|
|
306
|
-
"",
|
|
307
|
-
"Profile resource files available for this shot:",
|
|
308
|
-
...plan.files.map((file) => `- ${file.relPath}`)
|
|
309
|
-
].join("\n");
|
|
310
|
-
}
|
|
311
|
-
async function withAuthorProfileResources(plan, worktreePath, run) {
|
|
312
|
-
if (!plan) return run(null);
|
|
313
|
-
const rootPath = resolve(worktreePath, AGENTIC_PROFILE_RESOURCE_ROOT);
|
|
314
|
-
if (existsSync(rootPath)) {
|
|
315
|
-
throw new Error(
|
|
316
|
-
`agenticGenerator: ephemeral author profile root already exists: ${AGENTIC_PROFILE_RESOURCE_ROOT}`
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
let value;
|
|
320
|
-
let primaryError;
|
|
321
|
-
try {
|
|
322
|
-
const receipt = applyWorkspacePlan(plan, worktreePath);
|
|
323
|
-
value = await run(receipt);
|
|
324
|
-
} catch (cause) {
|
|
325
|
-
primaryError = cause;
|
|
326
|
-
}
|
|
327
|
-
let cleanupError;
|
|
328
|
-
try {
|
|
329
|
-
rmSync(rootPath, { recursive: true, force: true });
|
|
330
|
-
if (existsSync(rootPath)) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
`agenticGenerator: ephemeral author profile root survived cleanup: ${AGENTIC_PROFILE_RESOURCE_ROOT}`
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
} catch (cause) {
|
|
336
|
-
cleanupError = cause;
|
|
337
|
-
}
|
|
338
|
-
if (primaryError !== void 0 && cleanupError !== void 0) {
|
|
339
|
-
throw new AggregateError(
|
|
340
|
-
[primaryError, cleanupError],
|
|
341
|
-
"agenticGenerator: author shot and profile resource cleanup both failed"
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
if (primaryError !== void 0) throw primaryError;
|
|
345
|
-
if (cleanupError !== void 0) throw cleanupError;
|
|
346
|
-
return value;
|
|
347
|
-
}
|
|
348
|
-
async function emitShotReceipt(callback, receipt, execution, primaryError) {
|
|
349
|
-
try {
|
|
350
|
-
await callback?.(receipt, execution);
|
|
351
|
-
} catch (callbackError) {
|
|
352
|
-
if (primaryError !== null) {
|
|
353
|
-
throw new AggregateError(
|
|
354
|
-
[primaryError, callbackError],
|
|
355
|
-
"agenticGenerator: author shot failed and its receipt could not be persisted"
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
throw callbackError;
|
|
359
|
-
}
|
|
360
|
-
if (primaryError !== null) throw primaryError;
|
|
361
|
-
}
|
|
362
|
-
async function emitShotDisposition(callback, receipt, disposition) {
|
|
363
|
-
await callback?.(receipt, disposition);
|
|
364
|
-
}
|
|
365
|
-
async function rethrowShotSetupError(callback, receipt, worktreePath, stage, cause) {
|
|
366
|
-
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
367
|
-
try {
|
|
368
|
-
await emitShotDisposition(callback, receipt, {
|
|
369
|
-
kind: "setup-error",
|
|
370
|
-
worktreePath,
|
|
371
|
-
stage,
|
|
372
|
-
error: { name: error.name, message: error.message }
|
|
373
|
-
});
|
|
374
|
-
} catch (callbackError) {
|
|
375
|
-
throw new AggregateError(
|
|
376
|
-
[cause, callbackError],
|
|
377
|
-
"agenticGenerator: shot processing failed and its worktree disposition could not be persisted"
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
throw cause;
|
|
381
|
-
}
|
|
382
|
-
function shotExecutionSnapshot(result) {
|
|
383
|
-
if (result === null) return null;
|
|
384
|
-
const usage = result.usage ? Object.freeze({ ...result.usage }) : void 0;
|
|
385
|
-
const evidence = result.evidence ? Object.freeze({
|
|
386
|
-
...result.evidence,
|
|
387
|
-
readDeniedPaths: Object.freeze([...result.evidence.readDeniedPaths]),
|
|
388
|
-
policy: Object.freeze({ ...result.evidence.policy })
|
|
389
|
-
}) : void 0;
|
|
390
|
-
return Object.freeze({
|
|
391
|
-
exitCode: result.exitCode,
|
|
392
|
-
stdout: result.stdout,
|
|
393
|
-
stderr: result.stderr,
|
|
394
|
-
killedBySignal: result.killedBySignal,
|
|
395
|
-
durationMs: result.durationMs,
|
|
396
|
-
timedOut: result.timedOut,
|
|
397
|
-
...usage ? { usage } : {},
|
|
398
|
-
...evidence ? { evidence } : {}
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
function shotReceipt(input) {
|
|
402
|
-
const error = input.error ? {
|
|
403
|
-
name: input.error instanceof Error ? input.error.name : "Error",
|
|
404
|
-
message: input.error instanceof Error ? input.error.message : String(input.error)
|
|
405
|
-
} : null;
|
|
406
|
-
const result = input.result;
|
|
407
|
-
const costBasis = costBasisFor(input.costReceipt);
|
|
408
|
-
return {
|
|
409
|
-
generation: input.generation ?? null,
|
|
410
|
-
candidateIndex: input.candidateIndex ?? null,
|
|
411
|
-
shot: input.shot + 1,
|
|
412
|
-
maxShots: input.maxShots,
|
|
413
|
-
harness: input.harness,
|
|
414
|
-
model: input.profile?.model?.default ?? null,
|
|
415
|
-
reasoningEffort: input.profile?.model?.reasoningEffort ?? null,
|
|
416
|
-
promptSha256: sha256(input.prompt),
|
|
417
|
-
startedAt: input.startedAt.toISOString(),
|
|
418
|
-
completedAt: input.completedAt.toISOString(),
|
|
419
|
-
durationMs: result?.durationMs ?? input.completedAt.getTime() - input.startedAt.getTime(),
|
|
420
|
-
exitCode: result?.exitCode ?? null,
|
|
421
|
-
timedOut: result?.timedOut ?? false,
|
|
422
|
-
killedBySignal: result?.killedBySignal ?? null,
|
|
423
|
-
stdoutBytes: result ? Buffer.byteLength(result.stdout) : null,
|
|
424
|
-
stdoutSha256: result ? sha256(result.stdout) : null,
|
|
425
|
-
stderrBytes: result ? Buffer.byteLength(result.stderr) : null,
|
|
426
|
-
stderrSha256: result ? sha256(result.stderr) : null,
|
|
427
|
-
usage: result?.usage ? { ...result.usage } : null,
|
|
428
|
-
profileWorkspacePlanDigest: input.profileWorkspaceReceipt?.workspacePlanDigest ?? null,
|
|
429
|
-
profileWorkspaceFileCount: input.profileWorkspaceReceipt?.written.length ?? 0,
|
|
430
|
-
costCallId: input.costCallId,
|
|
431
|
-
costBasis,
|
|
432
|
-
costUsd: costBasis === "unknown" ? null : input.costReceipt?.costUsd ?? null,
|
|
433
|
-
costUsdKnown: costBasis === "provider-reported",
|
|
434
|
-
evidence: result?.evidence ? {
|
|
435
|
-
...result.evidence,
|
|
436
|
-
readDeniedPaths: [...result.evidence.readDeniedPaths],
|
|
437
|
-
policy: { ...result.evidence.policy }
|
|
438
|
-
} : null,
|
|
439
|
-
error
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function costBasisFor(receipt) {
|
|
443
|
-
if (receipt === null || receipt.costUnknown) return "unknown";
|
|
444
|
-
return receipt.actualCostUsd === void 0 ? "estimated-pricing" : "provider-reported";
|
|
445
|
-
}
|
|
446
|
-
function shotFailure(result, exactPrompt, codexReproducible) {
|
|
447
|
-
if (result.timedOut) {
|
|
448
|
-
return new Error("agenticGenerator: author shot timed out");
|
|
449
|
-
}
|
|
450
|
-
if (result.killedBySignal) {
|
|
451
|
-
return new Error(`agenticGenerator: author shot was killed by ${result.killedBySignal}`);
|
|
452
|
-
}
|
|
453
|
-
if (result.exitCode !== 0) {
|
|
454
|
-
return new Error(`agenticGenerator: author shot exited with code ${String(result.exitCode)}`);
|
|
455
|
-
}
|
|
456
|
-
if (!codexReproducible) return null;
|
|
457
|
-
if (!result.usage || !result.evidence) {
|
|
458
|
-
return new Error(
|
|
459
|
-
"agenticGenerator: reproducible Codex shot completed without usage or execution evidence"
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
const expectedPromptSha256 = sha256(exactPrompt).slice("sha256:".length);
|
|
463
|
-
if (result.evidence.requestedPromptSha256 !== expectedPromptSha256) {
|
|
464
|
-
return new Error(
|
|
465
|
-
"agenticGenerator: reproducible Codex prompt evidence does not match the exact authored prompt"
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
return null;
|
|
469
|
-
}
|
|
470
|
-
function costReceiptFromHarness(result, model) {
|
|
471
|
-
if (!result.usage) {
|
|
472
|
-
throw new Error("agenticGenerator: author shot did not report terminal token usage");
|
|
473
|
-
}
|
|
474
|
-
return {
|
|
475
|
-
model,
|
|
476
|
-
inputTokens: result.usage.inputTokens - result.usage.cachedInputTokens,
|
|
477
|
-
outputTokens: result.usage.outputTokens,
|
|
478
|
-
...result.usage.cachedInputTokens > 0 ? { cachedTokens: result.usage.cachedInputTokens } : {}
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
function sha256(value) {
|
|
482
|
-
return `sha256:${createHash("sha256").update(value).digest("hex")}`;
|
|
483
|
-
}
|
|
484
|
-
function defaultBuildPrompt(args) {
|
|
485
|
-
const lines = [
|
|
486
|
-
"You are improving this codebase based on an evaluation analysis.",
|
|
487
|
-
"Make the smallest set of edits that addresses the findings below, then stop.",
|
|
488
|
-
"Do not change unrelated code. Do not commit \u2014 leave changes in the working tree.",
|
|
489
|
-
"",
|
|
490
|
-
"Findings:"
|
|
491
|
-
];
|
|
492
|
-
for (const f of args.findings) {
|
|
493
|
-
const where = f.subject ? ` [${f.subject}]` : "";
|
|
494
|
-
lines.push(`- (${f.severity})${where} ${f.claim}`);
|
|
495
|
-
if (f.recommended_action) lines.push(` \u2192 ${f.recommended_action}`);
|
|
496
|
-
}
|
|
497
|
-
if (requiresRawTraceEvidence(args.findings)) {
|
|
498
|
-
lines.push(
|
|
499
|
-
"",
|
|
500
|
-
"Raw trace evidence requirement:",
|
|
501
|
-
`- Inspect at least one raw trace path named above before editing.`,
|
|
502
|
-
`- Write ${RAW_TRACE_DIAGNOSIS_PATH} in this worktree.`,
|
|
503
|
-
"- Include the exact trace path(s) inspected, the failure mechanism, and the code change made.",
|
|
504
|
-
"- A candidate without this file, or with only this file changed, is discarded."
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
return lines.join("\n");
|
|
508
|
-
}
|
|
509
|
-
var EMPTY_TREE_NOTE = "NOTE: your previous attempt left the working tree unchanged. Make the concrete file edits now.";
|
|
510
|
-
function failureNote(feedback) {
|
|
511
|
-
const detail = feedback?.trim();
|
|
512
|
-
return [
|
|
513
|
-
"NOTE: your edits are in the working tree but verification FAILED.",
|
|
514
|
-
"Fix the problem in place \u2014 build on your existing edits, do not revert them.",
|
|
515
|
-
detail ? `Verifier output:
|
|
516
|
-
${truncate(detail, 4e3)}` : "No verifier detail was captured."
|
|
517
|
-
].join("\n");
|
|
518
|
-
}
|
|
519
|
-
function rawTraceEvidenceProblem(worktreePath, findings) {
|
|
520
|
-
const changedPaths = worktreeChangedPaths(worktreePath);
|
|
521
|
-
const substantive = changedPaths.filter((path) => path !== RAW_TRACE_DIAGNOSIS_PATH);
|
|
522
|
-
if (substantive.length === 0) {
|
|
523
|
-
return [
|
|
524
|
-
`NOTE: raw-trace mode requires a real code/config edit in addition to ${RAW_TRACE_DIAGNOSIS_PATH}.`,
|
|
525
|
-
"Your previous attempt only changed the diagnosis artifact. Inspect the cited traces and make the causal code change."
|
|
526
|
-
].join("\n");
|
|
527
|
-
}
|
|
528
|
-
const diagnosisPath = join(worktreePath, RAW_TRACE_DIAGNOSIS_PATH);
|
|
529
|
-
if (!existsSync(diagnosisPath)) {
|
|
530
|
-
return [
|
|
531
|
-
`NOTE: raw-trace mode requires ${RAW_TRACE_DIAGNOSIS_PATH}.`,
|
|
532
|
-
"Before retrying, inspect at least one cited spans.jsonl/cached-result.json/artifact path, then write the diagnosis file with the exact path, failure mechanism, and code change."
|
|
533
|
-
].join("\n");
|
|
534
|
-
}
|
|
535
|
-
const body = readFileSync(diagnosisPath, "utf8");
|
|
536
|
-
const evidencePaths = traceEvidencePaths(findings);
|
|
537
|
-
if (evidencePaths.length > 0 && !evidencePaths.some((path) => body.includes(path))) {
|
|
538
|
-
return [
|
|
539
|
-
`${RAW_TRACE_DIAGNOSIS_PATH} exists, but it does not cite any exact raw trace path from the findings.`,
|
|
540
|
-
`Cite at least one of these inspected paths exactly: ${evidencePaths.slice(0, 5).join(", ")}`
|
|
541
|
-
].join("\n");
|
|
542
|
-
}
|
|
543
|
-
return null;
|
|
544
|
-
}
|
|
545
|
-
function requiresRawTraceEvidence(findings) {
|
|
546
|
-
return findings.some((finding) => {
|
|
547
|
-
const f = finding;
|
|
548
|
-
return f.analyst_id === RAW_TRACE_ANALYST_ID || f.area === RAW_TRACE_AREA;
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
function traceEvidencePaths(findings) {
|
|
552
|
-
const out = [];
|
|
553
|
-
for (const finding of findings) {
|
|
554
|
-
const refs = finding.evidence_refs;
|
|
555
|
-
if (!Array.isArray(refs)) continue;
|
|
556
|
-
for (const ref of refs) {
|
|
557
|
-
if (!ref || typeof ref !== "object") continue;
|
|
558
|
-
const uri = ref.uri;
|
|
559
|
-
if (typeof uri === "string" && uri.length > 0) out.push(uri);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return [...new Set(out)];
|
|
563
|
-
}
|
|
564
|
-
function commandVerifier(command, args = [], timeoutMs = 3e5) {
|
|
565
|
-
return (worktreePath) => {
|
|
566
|
-
const result = spawnSync(command, args, {
|
|
567
|
-
cwd: worktreePath,
|
|
568
|
-
encoding: "utf-8",
|
|
569
|
-
timeout: timeoutMs
|
|
570
|
-
});
|
|
571
|
-
if (result.signal) {
|
|
572
|
-
return {
|
|
573
|
-
ok: false,
|
|
574
|
-
feedback: `verifier '${command}' killed by ${result.signal} (likely timeout after ${timeoutMs}ms)`
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
if (result.error) {
|
|
578
|
-
const code = result.error.code;
|
|
579
|
-
if (code === "ENOENT") {
|
|
580
|
-
throw new Error(
|
|
581
|
-
`commandVerifier: '${command}' not found in PATH (setup bug, not a failed candidate)`
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
throw new Error(`commandVerifier: '${command}' failed to spawn: ${result.error.message}`);
|
|
585
|
-
}
|
|
586
|
-
if (result.status === 0) return { ok: true };
|
|
587
|
-
const out = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
|
|
588
|
-
return { ok: false, feedback: out.length > 0 ? out : `exit ${result.status}` };
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
function summarize(findings) {
|
|
592
|
-
if (findings.length === 0) return "agentic improvement";
|
|
593
|
-
if (findings.length === 1) return `agentic: ${truncate(findings[0].claim, 64)}`;
|
|
594
|
-
return `agentic: ${findings.length} findings addressed`;
|
|
595
|
-
}
|
|
596
|
-
function truncate(s, n) {
|
|
597
|
-
return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
|
|
598
|
-
}
|
|
599
|
-
function worktreeDirty(worktreePath) {
|
|
600
|
-
return worktreeChangedPaths(worktreePath).length > 0;
|
|
601
|
-
}
|
|
602
|
-
function worktreeChangedPaths(worktreePath) {
|
|
603
|
-
const result = spawnSync("git", ["status", "--porcelain", "--untracked-files=all"], {
|
|
604
|
-
cwd: worktreePath,
|
|
605
|
-
encoding: "utf-8"
|
|
606
|
-
});
|
|
607
|
-
if (result.error) {
|
|
608
|
-
throw new Error(
|
|
609
|
-
`agenticGenerator: git status failed to spawn in ${worktreePath}: ${result.error.message}`
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
|
-
if (result.status !== 0) {
|
|
613
|
-
throw new Error(
|
|
614
|
-
`agenticGenerator: git status exited ${result.status} in ${worktreePath}: ${result.stderr.trim()}`
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
return result.stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => line.slice(3).trim());
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
export {
|
|
621
|
-
AGENTIC_PROFILE_RESOURCE_ROOT,
|
|
622
|
-
agenticGenerator,
|
|
623
|
-
commandVerifier
|
|
624
|
-
};
|
|
625
|
-
//# sourceMappingURL=chunk-DHCHL6OG.js.map
|