@tangle-network/agent-eval 0.125.0 → 0.126.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +62 -35
  2. package/README.md +270 -189
  3. package/dist/analyst/index.d.ts +15 -145
  4. package/dist/analyst/index.js +33 -47
  5. package/dist/analyst/index.js.map +1 -1
  6. package/dist/benchmarks/index.d.ts +45 -162
  7. package/dist/benchmarks/index.js +8 -9
  8. package/dist/campaign/index.d.ts +3674 -5393
  9. package/dist/campaign/index.js +21 -95
  10. package/dist/{chunk-R226UZOI.js → chunk-474LBSOX.js} +2 -2
  11. package/dist/{chunk-HM6V7F3M.js → chunk-FO7HEH76.js} +3 -3
  12. package/dist/chunk-IILEIWGW.js +635 -0
  13. package/dist/chunk-IILEIWGW.js.map +1 -0
  14. package/dist/{chunk-EQUK3RFS.js → chunk-J5SQWP6Y.js} +8 -5
  15. package/dist/chunk-J5SQWP6Y.js.map +1 -0
  16. package/dist/{chunk-W5B3ZGP3.js → chunk-KE2VWPZX.js} +8 -6
  17. package/dist/{chunk-W5B3ZGP3.js.map → chunk-KE2VWPZX.js.map} +1 -1
  18. package/dist/{chunk-DT7OXY3C.js → chunk-LUNF2SEL.js} +538 -851
  19. package/dist/chunk-LUNF2SEL.js.map +1 -0
  20. package/dist/chunk-NGUYT5CI.js +4637 -0
  21. package/dist/chunk-NGUYT5CI.js.map +1 -0
  22. package/dist/{chunk-QFQZ3U3X.js → chunk-OCFJACJU.js} +2 -2
  23. package/dist/{chunk-GID26AN4.js → chunk-P22LJ3Y2.js} +4 -6
  24. package/dist/{chunk-GID26AN4.js.map → chunk-P22LJ3Y2.js.map} +1 -1
  25. package/dist/{chunk-SJT4OBVL.js → chunk-SDPM6554.js} +3 -3
  26. package/dist/{chunk-D5JZ7UDZ.js → chunk-UCLVDLCH.js} +136 -50
  27. package/dist/chunk-UCLVDLCH.js.map +1 -0
  28. package/dist/chunk-VMUENW6F.js +7274 -0
  29. package/dist/chunk-VMUENW6F.js.map +1 -0
  30. package/dist/{chunk-JKDNAOF5.js → chunk-W4L6C2XT.js} +2 -2
  31. package/dist/chunk-WGXIEX7P.js +116 -0
  32. package/dist/chunk-WGXIEX7P.js.map +1 -0
  33. package/dist/{chunk-GRCDRKII.js → chunk-WS3NZZQQ.js} +58 -20
  34. package/dist/chunk-WS3NZZQQ.js.map +1 -0
  35. package/dist/cli.js +3 -3
  36. package/dist/contract/index.d.ts +3220 -3094
  37. package/dist/contract/index.js +173 -42
  38. package/dist/contract/index.js.map +1 -1
  39. package/dist/control.js +2 -3
  40. package/dist/fuzz.d.ts +14 -1
  41. package/dist/fuzz.js +1 -1
  42. package/dist/hosted/index.d.ts +8 -1
  43. package/dist/index.d.ts +71 -687
  44. package/dist/index.js +178 -497
  45. package/dist/index.js.map +1 -1
  46. package/dist/openapi.json +1 -1
  47. package/dist/rl.d.ts +5 -100
  48. package/dist/rl.js +4 -5
  49. package/dist/rl.js.map +1 -1
  50. package/dist/{run-campaign-I3JXKVAK.js → run-campaign-LVFKZCEU.js} +3 -3
  51. package/dist/traces.js +2 -3
  52. package/dist/wire/index.d.ts +14 -1
  53. package/dist/wire/index.js +3 -3
  54. package/docs/campaign-proposers.md +363 -168
  55. package/docs/design/loop-taxonomy.md +142 -190
  56. package/docs/design.md +1 -1
  57. package/docs/distributed-driver.md +8 -11
  58. package/docs/feature-guide.md +20 -19
  59. package/docs/knowledge-readiness.md +2 -5
  60. package/docs/multi-shot-optimization.md +35 -27
  61. package/docs/rollout.md +5 -5
  62. package/package.json +4 -4
  63. package/dist/chunk-A62YMFWA.js +0 -9269
  64. package/dist/chunk-A62YMFWA.js.map +0 -1
  65. package/dist/chunk-A6GT67HT.js +0 -550
  66. package/dist/chunk-A6GT67HT.js.map +0 -1
  67. package/dist/chunk-D5JZ7UDZ.js.map +0 -1
  68. package/dist/chunk-DT7OXY3C.js.map +0 -1
  69. package/dist/chunk-EQUK3RFS.js.map +0 -1
  70. package/dist/chunk-GC4ATIKK.js +0 -317
  71. package/dist/chunk-GC4ATIKK.js.map +0 -1
  72. package/dist/chunk-GRCDRKII.js.map +0 -1
  73. package/dist/chunk-LOW3U7JZ.js +0 -328
  74. package/dist/chunk-LOW3U7JZ.js.map +0 -1
  75. package/dist/chunk-PMITBABE.js +0 -3841
  76. package/dist/chunk-PMITBABE.js.map +0 -1
  77. /package/dist/{chunk-R226UZOI.js.map → chunk-474LBSOX.js.map} +0 -0
  78. /package/dist/{chunk-HM6V7F3M.js.map → chunk-FO7HEH76.js.map} +0 -0
  79. /package/dist/{chunk-QFQZ3U3X.js.map → chunk-OCFJACJU.js.map} +0 -0
  80. /package/dist/{chunk-SJT4OBVL.js.map → chunk-SDPM6554.js.map} +0 -0
  81. /package/dist/{chunk-JKDNAOF5.js.map → chunk-W4L6C2XT.js.map} +0 -0
  82. /package/dist/{run-campaign-I3JXKVAK.js.map → run-campaign-LVFKZCEU.js.map} +0 -0
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  checkBehavioralCanary,
10
10
  checkCanaries,
11
11
  runBehavioralCanaries
12
- } from "./chunk-SJT4OBVL.js";
12
+ } from "./chunk-SDPM6554.js";
13
13
  import {
14
14
  mintRolloutRows,
15
15
  rolloutReward
@@ -46,7 +46,7 @@ import {
46
46
  BENCHMARK_SPLIT_SEED,
47
47
  benchmarks_exports,
48
48
  deterministicSplit
49
- } from "./chunk-JKDNAOF5.js";
49
+ } from "./chunk-W4L6C2XT.js";
50
50
  import {
51
51
  DEFAULT_RULES,
52
52
  classifyFailure,
@@ -87,7 +87,7 @@ import {
87
87
  pairArms,
88
88
  parseCorrectnessResponse,
89
89
  verifyCompletion
90
- } from "./chunk-A62YMFWA.js";
90
+ } from "./chunk-NGUYT5CI.js";
91
91
  import {
92
92
  DEFAULT_MUTATION_PRIMITIVES,
93
93
  DEFAULT_RED_TEAM_CORPUS,
@@ -98,7 +98,6 @@ import {
98
98
  REFERENCE_EQUIVALENCE_JUDGE_VERSION,
99
99
  adversarialJudge,
100
100
  buildReflectionPrompt,
101
- campaignMeanComposite,
102
101
  codeExecutionJudge,
103
102
  coherenceJudge,
104
103
  costReceiptFromTCloud,
@@ -108,9 +107,7 @@ import {
108
107
  crowdingDistance,
109
108
  defaultJudges,
110
109
  dominates,
111
- gepaProposer,
112
110
  hashScenarios,
113
- heldOutGate,
114
111
  llmJudge,
115
112
  maximumChargeForTCloudRequest,
116
113
  paretoFrontier,
@@ -119,13 +116,12 @@ import {
119
116
  redTeamDataset,
120
117
  redTeamReport,
121
118
  runCanaries,
122
- runImprovementLoop,
123
119
  runReferenceEquivalenceJudge,
124
120
  scalarScore,
125
121
  scoreRedTeamOutput,
126
122
  surfaceContentHash,
127
123
  toolNamesForRun
128
- } from "./chunk-PMITBABE.js";
124
+ } from "./chunk-VMUENW6F.js";
129
125
  import {
130
126
  BackendIntegrityError,
131
127
  assertRealAgentReceipts,
@@ -137,7 +133,7 @@ import {
137
133
  inMemoryVerdictCache,
138
134
  summarizeAgentReceiptIntegrity,
139
135
  summarizeBackendIntegrity
140
- } from "./chunk-D5JZ7UDZ.js";
136
+ } from "./chunk-UCLVDLCH.js";
141
137
  import {
142
138
  DEFAULT_COMPLEXITY_WEIGHTS,
143
139
  FindingsStore,
@@ -150,47 +146,32 @@ import {
150
146
  defaultIsMaterial,
151
147
  diffFindings,
152
148
  runSemanticConceptJudge
153
- } from "./chunk-W5B3ZGP3.js";
154
- import {
155
- buildDefaultAnalystRegistry,
156
- computeTraceMetrics,
157
- createChatClient
158
- } from "./chunk-A6GT67HT.js";
159
- import "./chunk-HHWE3POT.js";
149
+ } from "./chunk-KE2VWPZX.js";
160
150
  import {
161
151
  AnalystRegistry,
162
- DEFAULT_RUN_SCORE_WEIGHTS,
163
152
  DEFAULT_TRACE_ANALYST_KINDS,
164
153
  FAILURE_MODE_KIND_SPEC,
165
154
  IMPROVEMENT_KIND_SPEC,
166
155
  KNOWLEDGE_GAP_KIND_SPEC,
167
156
  KNOWLEDGE_POISONING_KIND_SPEC,
168
- Mutex,
169
- POLICY_EDIT_AXES,
170
- POLICY_EDIT_CANDIDATE_RECORD_SCHEMA,
171
- POLICY_EDIT_TARGET_SURFACES,
172
- PolicyEditValidationError,
173
- admitPolicyEdit,
174
- aggregateRunScore,
175
- applyPolicyEditToSurface,
176
- clamp01,
157
+ buildDefaultAnalystRegistry,
177
158
  computeFindingId,
178
- computePolicyEditId,
159
+ computeTraceMetrics,
179
160
  createAnalystAi,
161
+ createChatClient,
180
162
  createTraceAnalystKind,
181
- isPolicyEdit,
182
163
  makeFinding,
183
- makePolicyEdit,
184
- makePolicyEditCandidateRecord,
185
- mapConcurrent,
186
- policyEditFromFinding,
187
- policyEditsFromFindings,
188
164
  renderPriorFindings,
189
- renderUpstreamFindings,
190
- scorePolicyEditReadiness,
191
- validatePolicyEdit,
192
- validatePolicyEditCandidateRecord
193
- } from "./chunk-DT7OXY3C.js";
165
+ renderUpstreamFindings
166
+ } from "./chunk-LUNF2SEL.js";
167
+ import "./chunk-HHWE3POT.js";
168
+ import {
169
+ DEFAULT_RUN_SCORE_WEIGHTS,
170
+ Mutex,
171
+ aggregateRunScore,
172
+ clamp01,
173
+ mapConcurrent
174
+ } from "./chunk-WGXIEX7P.js";
194
175
  import {
195
176
  allCriticalPassed,
196
177
  controlFailureClassFromVerification,
@@ -211,7 +192,7 @@ import {
211
192
  stopOnNoProgress,
212
193
  stopOnRepeatedAction,
213
194
  subjectiveEval
214
- } from "./chunk-R226UZOI.js";
195
+ } from "./chunk-474LBSOX.js";
215
196
  import {
216
197
  assertReleaseConfidence,
217
198
  bootstrapCi,
@@ -221,7 +202,7 @@ import {
221
202
  } from "./chunk-MOXWMGPC.js";
222
203
  import {
223
204
  runEvalCampaign
224
- } from "./chunk-GID26AN4.js";
205
+ } from "./chunk-P22LJ3Y2.js";
225
206
  import "./chunk-ARU2PZFM.js";
226
207
  import {
227
208
  LlmCallError,
@@ -238,7 +219,7 @@ import {
238
219
  maximumChargeForLlmRequest,
239
220
  probeLlm,
240
221
  stripFencedJson
241
- } from "./chunk-EQUK3RFS.js";
222
+ } from "./chunk-J5SQWP6Y.js";
242
223
  import {
243
224
  evaluateInterimReleaseConfidence,
244
225
  pairedEvalueSequence
@@ -301,7 +282,7 @@ import {
301
282
  costForTokenPricing,
302
283
  costForUsage,
303
284
  modelPriceKey
304
- } from "./chunk-GRCDRKII.js";
285
+ } from "./chunk-WS3NZZQQ.js";
305
286
  import {
306
287
  MODEL_PRICING,
307
288
  MetricsCollector,
@@ -340,7 +321,7 @@ import {
340
321
  scoreTraceInsightReadiness,
341
322
  tokenizeDomainWords,
342
323
  traceAnalystOnRunComplete
343
- } from "./chunk-QFQZ3U3X.js";
324
+ } from "./chunk-OCFJACJU.js";
344
325
  import "./chunk-H5UD2323.js";
345
326
  import {
346
327
  extractUsage,
@@ -405,14 +386,26 @@ import {
405
386
  llmSpanFromProvider
406
387
  } from "./chunk-VQMK5FMP.js";
407
388
  import {
389
+ AGENT_PROFILE_KINDS,
390
+ AgentProfileCellValidationError,
408
391
  RunRecordValidationError,
392
+ agentProfileCellHashMaterial,
393
+ agentProfileCellKey,
394
+ assertRunAgentProfileCell,
395
+ buildAgentInterfaceProfileCell,
396
+ buildAgentProfileCell,
397
+ groupRunsByAgentProfileCell,
409
398
  isRunRecord,
410
399
  modelHasSnapshot,
411
400
  parseRunRecordSafe,
401
+ requireAgentProfileCell,
412
402
  resolveRunCostProvenance,
413
403
  roundTripRunRecord,
414
- validateRunRecord
415
- } from "./chunk-LOW3U7JZ.js";
404
+ toAgentProfileJson,
405
+ validateAgentProfileCell,
406
+ validateRunRecord,
407
+ verifyAgentProfileCell
408
+ } from "./chunk-IILEIWGW.js";
416
409
  import {
417
410
  FAILURE_CLASSES,
418
411
  TRACE_SCHEMA_VERSION,
@@ -422,20 +415,6 @@ import {
422
415
  isSandboxSpan,
423
416
  isToolSpan
424
417
  } from "./chunk-MA6HLL3S.js";
425
- import {
426
- AGENT_PROFILE_KINDS,
427
- AgentProfileCellValidationError,
428
- agentProfileCellHashMaterial,
429
- agentProfileCellKey,
430
- assertRunAgentProfileCell,
431
- buildAgentInterfaceProfileCell,
432
- buildAgentProfileCell,
433
- groupRunsByAgentProfileCell,
434
- requireAgentProfileCell,
435
- toAgentProfileJson,
436
- validateAgentProfileCell,
437
- verifyAgentProfileCell
438
- } from "./chunk-GC4ATIKK.js";
439
418
  import {
440
419
  canonicalize,
441
420
  evaluateHypothesis,
@@ -10066,414 +10045,6 @@ function isOtelConfigured() {
10066
10045
  return !!(typeof process !== "undefined" && process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
10067
10046
  }
10068
10047
 
10069
- // src/traced-analyst.ts
10070
- async function tracedAnalyzeTraces(input, options, traceOpts) {
10071
- const parentSpan = await traceOpts.emitter.span({
10072
- kind: "custom",
10073
- name: "analyst:analyze-traces",
10074
- parentSpanId: traceOpts.parentSpanId,
10075
- attributes: {
10076
- "analyst.question_length": input.question.length,
10077
- "analyst.max_turns": options.maxTurns ?? 12,
10078
- "analyst.max_subqueries": options.maxSubqueries ?? 4,
10079
- "eval.phase": "analyst"
10080
- }
10081
- });
10082
- const originalOnTurn = options.onTurn;
10083
- const wrappedOptions = {
10084
- ...options,
10085
- onTurn: async (turn) => {
10086
- const turnSpan = await traceOpts.emitter.span({
10087
- kind: "custom",
10088
- name: `analyst:turn-${turn.turn}`,
10089
- parentSpanId: parentSpan.span.spanId,
10090
- attributes: {
10091
- "analyst.stage": turn.stage,
10092
- "analyst.turn": turn.turn,
10093
- "analyst.is_error": turn.isError,
10094
- "analyst.code_length": turn.code.length,
10095
- "analyst.output_length": turn.output.length,
10096
- "eval.phase": "analyst"
10097
- }
10098
- });
10099
- if (turn.isError) {
10100
- await turnSpan.fail("Turn produced an error");
10101
- } else {
10102
- await turnSpan.end();
10103
- }
10104
- if (originalOnTurn) await originalOnTurn(turn);
10105
- }
10106
- };
10107
- try {
10108
- const result = await analyzeTraces(input, wrappedOptions);
10109
- await parentSpan.end({
10110
- attributes: {
10111
- "analyst.question_length": input.question.length,
10112
- "analyst.turn_count": result.turnCount,
10113
- "analyst.finding_count": result.findings.length,
10114
- "analyst.answer_length": result.answer.length,
10115
- "eval.phase": "analyst"
10116
- }
10117
- });
10118
- return result;
10119
- } catch (err) {
10120
- await parentSpan.fail(err instanceof Error ? err : String(err));
10121
- throw err;
10122
- }
10123
- }
10124
-
10125
- // src/traced-judges.ts
10126
- function traceJudge(judge, judgeName, opts) {
10127
- return async (tc, input) => {
10128
- const span = await opts.emitter.span({
10129
- kind: "llm",
10130
- name: `judge:${judgeName}`,
10131
- parentSpanId: opts.parentSpanId,
10132
- attributes: {
10133
- "judge.name": judgeName,
10134
- "eval.phase": "judge"
10135
- }
10136
- });
10137
- try {
10138
- const scores2 = await judge(tc, input);
10139
- const composite = scores2.length > 0 ? scores2.reduce((sum4, s) => sum4 + s.score, 0) / scores2.length : 0;
10140
- await span.end({
10141
- attributes: {
10142
- "judge.name": judgeName,
10143
- "judge.composite_score": composite,
10144
- "judge.dimension_count": scores2.length,
10145
- "eval.phase": "judge"
10146
- }
10147
- });
10148
- return scores2;
10149
- } catch (err) {
10150
- await span.fail(err instanceof Error ? err : String(err));
10151
- throw err;
10152
- }
10153
- };
10154
- }
10155
- function traceJudgeEnsemble(judges, judgeNames, opts) {
10156
- return async (tc, input) => {
10157
- const ensembleSpan = await opts.emitter.span({
10158
- kind: "custom",
10159
- name: "judge:ensemble",
10160
- parentSpanId: opts.parentSpanId,
10161
- attributes: {
10162
- "judge.ensemble_size": judges.length,
10163
- "eval.phase": "judge"
10164
- }
10165
- });
10166
- try {
10167
- const allScores = [];
10168
- let failedJudges = 0;
10169
- for (let i = 0; i < judges.length; i++) {
10170
- const judge = judges[i];
10171
- const name = judgeNames[i] ?? `judge_${i}`;
10172
- const tracedFn = traceJudge(judge, name, {
10173
- emitter: opts.emitter,
10174
- parentSpanId: ensembleSpan.span.spanId
10175
- });
10176
- try {
10177
- const scores2 = await tracedFn(tc, input);
10178
- allScores.push(...scores2);
10179
- } catch (err) {
10180
- if (!(err instanceof JudgeParseError)) throw err;
10181
- failedJudges++;
10182
- }
10183
- }
10184
- const composite = allScores.length > 0 ? allScores.reduce((sum4, s) => sum4 + s.score, 0) / allScores.length : 0;
10185
- await ensembleSpan.end({
10186
- attributes: {
10187
- "judge.ensemble_size": judges.length,
10188
- "judge.composite_score": composite,
10189
- "judge.total_dimensions": allScores.length,
10190
- "judge.failed_judges": failedJudges,
10191
- "eval.phase": "judge"
10192
- }
10193
- });
10194
- return allScores;
10195
- } catch (err) {
10196
- await ensembleSpan.fail(err instanceof Error ? err : String(err));
10197
- throw err;
10198
- }
10199
- };
10200
- }
10201
-
10202
- // src/campaign/distillation/agreement-judge.ts
10203
- var AGREEMENT_DIM = "agreement";
10204
- function buildAgreementJudge(options) {
10205
- const name = options.name ?? "gold-agreement";
10206
- const goldOnly = options.goldOnly ?? true;
10207
- const declaredDims = options.dimensionKeys ?? [AGREEMENT_DIM];
10208
- return {
10209
- name,
10210
- dimensions: declaredDims.map((key) => ({
10211
- key,
10212
- description: `Per-field agreement between the produced label and the gold label on '${key}'`
10213
- })),
10214
- appliesTo: goldOnly ? (scenario) => scenario.kind === "gold" : void 0,
10215
- score({ artifact, scenario }) {
10216
- const { score, dimensions } = options.compareLabels(artifact, scenario.label);
10217
- if (!Number.isFinite(score) || score < 0 || score > 1) {
10218
- throw new Error(
10219
- `buildAgreementJudge: comparator returned out-of-range score ${score} for scenario '${scenario.id}' (must be in [0,1])`
10220
- );
10221
- }
10222
- const outDims = { [AGREEMENT_DIM]: score, ...dimensions };
10223
- const weakest = Object.entries(dimensions).sort((a, b) => a[1] - b[1])[0];
10224
- const notes = weakest ? `agreement ${score.toFixed(3)}; weakest field '${weakest[0]}' (${weakest[1].toFixed(3)})` : `agreement ${score.toFixed(3)}`;
10225
- return { composite: score, dimensions: outDims, notes };
10226
- }
10227
- };
10228
- }
10229
- function fieldAgreement(spec) {
10230
- const categorical = spec.categorical ?? [];
10231
- const array = spec.array ?? [];
10232
- if (categorical.length === 0 && array.length === 0) {
10233
- throw new Error("fieldAgreement: at least one categorical or array field is required");
10234
- }
10235
- return (produced, gold) => {
10236
- const p = produced ?? {};
10237
- const g = gold ?? {};
10238
- const dimensions = {};
10239
- for (const field of categorical) {
10240
- dimensions[field] = categoricalAgreement(p[field], g[field]);
10241
- }
10242
- for (const field of array) {
10243
- dimensions[field] = jaccard(asArray(p[field]), asArray(g[field]));
10244
- }
10245
- const values = Object.values(dimensions);
10246
- const score = values.length === 0 ? 0 : values.reduce((a, b) => a + b, 0) / values.length;
10247
- return { score, dimensions };
10248
- };
10249
- }
10250
- function categoricalAgreement(produced, gold) {
10251
- if (produced === void 0 && gold === void 0) return 1;
10252
- return normalizeScalar(produced) === normalizeScalar(gold) ? 1 : 0;
10253
- }
10254
- function normalizeScalar(value) {
10255
- if (value === void 0) return "__undefined__";
10256
- if (value === null) return "__null__";
10257
- return JSON.stringify(value);
10258
- }
10259
- function asArray(value) {
10260
- if (Array.isArray(value)) return value;
10261
- if (value === void 0 || value === null) return [];
10262
- return [value];
10263
- }
10264
- function jaccard(a, b) {
10265
- const sa = new Set(a.map((x) => JSON.stringify(x)));
10266
- const sb = new Set(b.map((x) => JSON.stringify(x)));
10267
- if (sa.size === 0 && sb.size === 0) return 1;
10268
- let inter = 0;
10269
- for (const x of sa) if (sb.has(x)) inter++;
10270
- const union = sa.size + sb.size - inter;
10271
- return union === 0 ? 1 : inter / union;
10272
- }
10273
-
10274
- // src/campaign/distillation/gold-scenarios.ts
10275
- import { readFileSync as readFileSync5 } from "fs";
10276
- function loadGoldScenarios(jsonlPath) {
10277
- const text = readFileSync5(jsonlPath, "utf8");
10278
- return parseGoldJsonl(text, jsonlPath);
10279
- }
10280
- function parseGoldJsonl(text, sourceLabel = "<inline>") {
10281
- const out = [];
10282
- const lines = text.split("\n");
10283
- for (let i = 0; i < lines.length; i++) {
10284
- const raw = lines[i].trim();
10285
- if (raw.length === 0) continue;
10286
- let parsed;
10287
- try {
10288
- parsed = JSON.parse(raw);
10289
- } catch (err) {
10290
- throw new Error(
10291
- `loadGoldScenarios: ${sourceLabel}:${i + 1} is not valid JSON \u2014 ${err instanceof Error ? err.message : String(err)}`
10292
- );
10293
- }
10294
- const rawId = parsed.scenarioId ?? parsed.id;
10295
- if (typeof rawId !== "string" || rawId.length === 0) {
10296
- throw new Error(
10297
- `loadGoldScenarios: ${sourceLabel}:${i + 1} missing string \`scenarioId\`/\`id\``
10298
- );
10299
- }
10300
- const id = rawId.replace(/:/g, "__");
10301
- if (parsed.input === void 0) {
10302
- throw new Error(`loadGoldScenarios: ${sourceLabel}:${i + 1} (${rawId}) missing \`input\``);
10303
- }
10304
- if (parsed.label === void 0) {
10305
- throw new Error(`loadGoldScenarios: ${sourceLabel}:${i + 1} (${rawId}) missing \`label\``);
10306
- }
10307
- const scenario = {
10308
- id,
10309
- kind: "gold",
10310
- input: parsed.input,
10311
- label: parsed.label
10312
- };
10313
- const tags = [];
10314
- if (id !== rawId) tags.push(`gold-id:${rawId}`);
10315
- if (parsed.split !== void 0) tags.push(`split:${parsed.split}`);
10316
- if (tags.length > 0) scenario.tags = tags;
10317
- out.push(scenario);
10318
- }
10319
- if (out.length === 0) {
10320
- throw new Error(`loadGoldScenarios: ${sourceLabel} contained no gold records`);
10321
- }
10322
- return out;
10323
- }
10324
- function splitGold(scenarios, options = {}) {
10325
- const testEveryNth = options.testEveryNth ?? 4;
10326
- if (!Number.isInteger(testEveryNth) || testEveryNth < 2) {
10327
- throw new Error("splitGold: testEveryNth must be an integer \u2265 2 (else train or test is empty)");
10328
- }
10329
- const train = [];
10330
- const test = [];
10331
- let implicitIndex = 0;
10332
- for (const scenario of scenarios) {
10333
- const explicit = explicitSplit(scenario);
10334
- if (explicit === "train") {
10335
- train.push(scenario);
10336
- } else if (explicit === "test") {
10337
- test.push(scenario);
10338
- } else {
10339
- if (implicitIndex % testEveryNth === 0) test.push(scenario);
10340
- else train.push(scenario);
10341
- implicitIndex += 1;
10342
- }
10343
- }
10344
- return { train, test };
10345
- }
10346
- function explicitSplit(scenario) {
10347
- for (const tag of scenario.tags ?? []) {
10348
- if (tag === "split:train") return "train";
10349
- if (tag === "split:test") return "test";
10350
- }
10351
- return void 0;
10352
- }
10353
-
10354
- // src/campaign/distillation/run-distillation.ts
10355
- async function runDistillation(opts) {
10356
- if (opts.train.length === 0) throw new Error("runDistillation: train split is empty");
10357
- if (opts.holdout.length === 0) throw new Error("runDistillation: holdout split is empty");
10358
- const chat = createChatClient(opts.llm);
10359
- const render = opts.renderStudentPrompt ?? defaultRenderStudentPrompt;
10360
- const parse = opts.parseStudentLabel ?? defaultParseStudentLabel;
10361
- const runDir = opts.runDir ?? `.evolve/distillation/${Date.now()}`;
10362
- const studentTemperature = opts.studentTemperature ?? 0;
10363
- const studentMaxTokens = opts.studentMaxTokens ?? 1024;
10364
- const proposer = gepaProposer({
10365
- llm: opts.reflectionLlm,
10366
- model: opts.optimizerModel,
10367
- target: "a cheap single-shot analyst system prompt that reproduces an expensive workflow gold verdict",
10368
- mutationPrimitives: opts.mutationPrimitives ?? DEFAULT_MUTATION_PRIMITIVES2,
10369
- constraints: opts.constraints
10370
- });
10371
- const gate = opts.gate ?? heldOutGate({
10372
- scenarios: opts.holdout,
10373
- deltaThreshold: opts.deltaThreshold ?? 0
10374
- });
10375
- const loop = await runImprovementLoop({
10376
- baselineSurface: opts.baselinePrompt,
10377
- scenarios: opts.train,
10378
- holdoutScenarios: opts.holdout,
10379
- judges: [opts.judge],
10380
- proposer,
10381
- gate,
10382
- autoOnPromote: "none",
10383
- // the loop NEVER opens a PR — the caller decides
10384
- populationSize: opts.populationSize ?? 4,
10385
- maxGenerations: opts.maxGenerations ?? 3,
10386
- reps: opts.reps ?? 1,
10387
- runDir,
10388
- // The student spends tokens; tracing must stay on (the proposer is wired and
10389
- // runImprovementLoop refuses tracing='off' with a proposer).
10390
- tracing: "on",
10391
- dispatchWithSurface: async (surface, scenario, ctx) => {
10392
- const prompt = render({
10393
- surface: typeof surface === "string" ? surface : JSON.stringify(surface),
10394
- input: scenario.input,
10395
- scenarioId: scenario.id
10396
- });
10397
- const request = {
10398
- model: opts.studentModel,
10399
- messages: prompt,
10400
- jsonMode: true,
10401
- temperature: studentTemperature,
10402
- maxTokens: studentMaxTokens
10403
- };
10404
- const paid = await ctx.cost.runPaidCall({
10405
- actor: "distillation-student",
10406
- model: opts.studentModel,
10407
- maximumCharge: chat.maximumAttempts === void 0 ? void 0 : maximumChargeForLlmRequest(request, { maxRetries: chat.maximumAttempts }),
10408
- execute: (signal, callId) => chat.chat(request, { signal, idempotencyKey: callId }),
10409
- receipt: costReceiptFromLlm,
10410
- receiptFromError: costReceiptFromLlmError
10411
- });
10412
- if (!paid.succeeded) throw paid.error;
10413
- return parse(paid.value.content, scenario.id);
10414
- }
10415
- });
10416
- const winnerPrompt = typeof loop.winnerSurface === "string" ? loop.winnerSurface : opts.baselinePrompt;
10417
- const baseline = campaignMeanComposite(loop.baselineOnHoldout);
10418
- const winner = campaignMeanComposite(loop.winnerOnHoldout);
10419
- return {
10420
- ...loop,
10421
- winnerPrompt,
10422
- holdoutAgreement: { baseline, winner, delta: winner - baseline }
10423
- };
10424
- }
10425
- var DEFAULT_MUTATION_PRIMITIVES2 = [
10426
- "Add an explicit output-schema instruction so the model emits exactly the gold label fields as JSON.",
10427
- "Add a one-line decision rule for each verdict field the student keeps getting wrong.",
10428
- "Add a worked example mapping a representative input to its correct gold label.",
10429
- "Tighten ambiguous phrasing that lets the student hedge instead of committing to a verdict.",
10430
- "Add a guardrail that forces the student to set boolean risk flags (e.g. leak risk) when the triggering condition is present."
10431
- ];
10432
- function defaultRenderStudentPrompt(args) {
10433
- return [
10434
- { role: "system", content: args.surface },
10435
- {
10436
- role: "user",
10437
- content: `Input:
10438
- ${stableStringify(args.input)}
10439
-
10440
- Respond with ONLY a single JSON object \u2014 the verdict. No prose, no code fences.`
10441
- }
10442
- ];
10443
- }
10444
- function defaultParseStudentLabel(rawContent, scenarioId) {
10445
- const stripped = stripFence(rawContent).trim();
10446
- if (stripped.length === 0) {
10447
- throw new Error(`distillation student returned empty output for scenario '${scenarioId}'`);
10448
- }
10449
- try {
10450
- return JSON.parse(stripped);
10451
- } catch (err) {
10452
- throw new Error(
10453
- `distillation student returned non-JSON for scenario '${scenarioId}': ${err instanceof Error ? err.message : String(err)} \u2014 raw: ${stripped.slice(0, 200)}`
10454
- );
10455
- }
10456
- }
10457
- function stripFence(text) {
10458
- const fenced = /```(?:json)?\s*([\s\S]*?)\s*```/.exec(text);
10459
- return fenced ? fenced[1] ?? text : text;
10460
- }
10461
- function stableStringify(value) {
10462
- return JSON.stringify(value, replacerSortKeys(), 2);
10463
- }
10464
- function replacerSortKeys() {
10465
- return (_key, value) => {
10466
- if (value && typeof value === "object" && !Array.isArray(value)) {
10467
- const sorted = {};
10468
- for (const k of Object.keys(value).sort()) {
10469
- sorted[k] = value[k];
10470
- }
10471
- return sorted;
10472
- }
10473
- return value;
10474
- };
10475
- }
10476
-
10477
10048
  // src/profile/index.ts
10478
10049
  var profile_exports = {};
10479
10050
  __export(profile_exports, {
@@ -10615,6 +10186,139 @@ function sectionHash(section) {
10615
10186
  return surfaceContentHash(JSON.stringify({ title: section.title, body: section.body }));
10616
10187
  }
10617
10188
 
10189
+ // src/traced-analyst.ts
10190
+ async function tracedAnalyzeTraces(input, options, traceOpts) {
10191
+ const parentSpan = await traceOpts.emitter.span({
10192
+ kind: "custom",
10193
+ name: "analyst:analyze-traces",
10194
+ parentSpanId: traceOpts.parentSpanId,
10195
+ attributes: {
10196
+ "analyst.question_length": input.question.length,
10197
+ "analyst.max_turns": options.maxTurns ?? 12,
10198
+ "analyst.max_subqueries": options.maxSubqueries ?? 4,
10199
+ "eval.phase": "analyst"
10200
+ }
10201
+ });
10202
+ const originalOnTurn = options.onTurn;
10203
+ const wrappedOptions = {
10204
+ ...options,
10205
+ onTurn: async (turn) => {
10206
+ const turnSpan = await traceOpts.emitter.span({
10207
+ kind: "custom",
10208
+ name: `analyst:turn-${turn.turn}`,
10209
+ parentSpanId: parentSpan.span.spanId,
10210
+ attributes: {
10211
+ "analyst.stage": turn.stage,
10212
+ "analyst.turn": turn.turn,
10213
+ "analyst.is_error": turn.isError,
10214
+ "analyst.code_length": turn.code.length,
10215
+ "analyst.output_length": turn.output.length,
10216
+ "eval.phase": "analyst"
10217
+ }
10218
+ });
10219
+ if (turn.isError) {
10220
+ await turnSpan.fail("Turn produced an error");
10221
+ } else {
10222
+ await turnSpan.end();
10223
+ }
10224
+ if (originalOnTurn) await originalOnTurn(turn);
10225
+ }
10226
+ };
10227
+ try {
10228
+ const result = await analyzeTraces(input, wrappedOptions);
10229
+ await parentSpan.end({
10230
+ attributes: {
10231
+ "analyst.question_length": input.question.length,
10232
+ "analyst.turn_count": result.turnCount,
10233
+ "analyst.finding_count": result.findings.length,
10234
+ "analyst.answer_length": result.answer.length,
10235
+ "eval.phase": "analyst"
10236
+ }
10237
+ });
10238
+ return result;
10239
+ } catch (err) {
10240
+ await parentSpan.fail(err instanceof Error ? err : String(err));
10241
+ throw err;
10242
+ }
10243
+ }
10244
+
10245
+ // src/traced-judges.ts
10246
+ function traceJudge(judge, judgeName, opts) {
10247
+ return async (tc, input) => {
10248
+ const span = await opts.emitter.span({
10249
+ kind: "llm",
10250
+ name: `judge:${judgeName}`,
10251
+ parentSpanId: opts.parentSpanId,
10252
+ attributes: {
10253
+ "judge.name": judgeName,
10254
+ "eval.phase": "judge"
10255
+ }
10256
+ });
10257
+ try {
10258
+ const scores2 = await judge(tc, input);
10259
+ const composite = scores2.length > 0 ? scores2.reduce((sum4, s) => sum4 + s.score, 0) / scores2.length : 0;
10260
+ await span.end({
10261
+ attributes: {
10262
+ "judge.name": judgeName,
10263
+ "judge.composite_score": composite,
10264
+ "judge.dimension_count": scores2.length,
10265
+ "eval.phase": "judge"
10266
+ }
10267
+ });
10268
+ return scores2;
10269
+ } catch (err) {
10270
+ await span.fail(err instanceof Error ? err : String(err));
10271
+ throw err;
10272
+ }
10273
+ };
10274
+ }
10275
+ function traceJudgeEnsemble(judges, judgeNames, opts) {
10276
+ return async (tc, input) => {
10277
+ const ensembleSpan = await opts.emitter.span({
10278
+ kind: "custom",
10279
+ name: "judge:ensemble",
10280
+ parentSpanId: opts.parentSpanId,
10281
+ attributes: {
10282
+ "judge.ensemble_size": judges.length,
10283
+ "eval.phase": "judge"
10284
+ }
10285
+ });
10286
+ try {
10287
+ const allScores = [];
10288
+ let failedJudges = 0;
10289
+ for (let i = 0; i < judges.length; i++) {
10290
+ const judge = judges[i];
10291
+ const name = judgeNames[i] ?? `judge_${i}`;
10292
+ const tracedFn = traceJudge(judge, name, {
10293
+ emitter: opts.emitter,
10294
+ parentSpanId: ensembleSpan.span.spanId
10295
+ });
10296
+ try {
10297
+ const scores2 = await tracedFn(tc, input);
10298
+ allScores.push(...scores2);
10299
+ } catch (err) {
10300
+ if (!(err instanceof JudgeParseError)) throw err;
10301
+ failedJudges++;
10302
+ }
10303
+ }
10304
+ const composite = allScores.length > 0 ? allScores.reduce((sum4, s) => sum4 + s.score, 0) / allScores.length : 0;
10305
+ await ensembleSpan.end({
10306
+ attributes: {
10307
+ "judge.ensemble_size": judges.length,
10308
+ "judge.composite_score": composite,
10309
+ "judge.total_dimensions": allScores.length,
10310
+ "judge.failed_judges": failedJudges,
10311
+ "eval.phase": "judge"
10312
+ }
10313
+ });
10314
+ return allScores;
10315
+ } catch (err) {
10316
+ await ensembleSpan.fail(err instanceof Error ? err : String(err));
10317
+ throw err;
10318
+ }
10319
+ };
10320
+ }
10321
+
10618
10322
  // src/cost-report.ts
10619
10323
  function costReport(ledger) {
10620
10324
  const summary = ledger.summary();
@@ -10735,13 +10439,13 @@ function verifyAttestation(report, attested) {
10735
10439
  }
10736
10440
 
10737
10441
  // src/product-benchmark/index.ts
10738
- import { existsSync as existsSync6, readFileSync as readFileSync7, statSync as statSync3 } from "fs";
10442
+ import { existsSync as existsSync6, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
10739
10443
  import { dirname as dirname4, join as join5 } from "path";
10740
10444
 
10741
10445
  // src/product-benchmark/export.ts
10742
10446
  import { spawnSync as spawnSync2 } from "child_process";
10743
10447
  import { createHash } from "crypto";
10744
- import { cpSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync } from "fs";
10448
+ import { cpSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync } from "fs";
10745
10449
  import { basename as basename2, dirname as dirname3, isAbsolute, join as join4, relative, resolve } from "path";
10746
10450
  var productBenchmarkMutableSurfaces = [
10747
10451
  "prompt",
@@ -10789,19 +10493,19 @@ function productBenchmarkRepoIdentity() {
10789
10493
  };
10790
10494
  }
10791
10495
  function packageVersion(name) {
10792
- const pkg = JSON.parse(readFileSync6(resolve("package.json"), "utf8"));
10496
+ const pkg = JSON.parse(readFileSync5(resolve("package.json"), "utf8"));
10793
10497
  if (pkg.name === name && pkg.version) return pkg.version;
10794
10498
  const declared = pkg.dependencies?.[name] ?? pkg.devDependencies?.[name];
10795
10499
  if (declared) return declared;
10796
10500
  const installed = resolve("node_modules", name, "package.json");
10797
10501
  if (existsSync5(installed)) {
10798
- const installedPkg = JSON.parse(readFileSync6(installed, "utf8"));
10502
+ const installedPkg = JSON.parse(readFileSync5(installed, "utf8"));
10799
10503
  if (installedPkg.version) return installedPkg.version;
10800
10504
  }
10801
10505
  return "unknown";
10802
10506
  }
10803
10507
  function readRunRecords(path) {
10804
- const lines = readFileSync6(path, "utf8").split("\n").map((line) => line.trim()).filter(Boolean);
10508
+ const lines = readFileSync5(path, "utf8").split("\n").map((line) => line.trim()).filter(Boolean);
10805
10509
  return lines.map((line, index) => {
10806
10510
  let parsed;
10807
10511
  try {
@@ -11452,7 +11156,7 @@ function productBenchmarkIntegrityFailures(record) {
11452
11156
  return failures;
11453
11157
  }
11454
11158
  function readProductBenchmarkRecords(path) {
11455
- const lines = readFileSync7(path, "utf8").split("\n").map((line) => line.trim()).filter(Boolean);
11159
+ const lines = readFileSync6(path, "utf8").split("\n").map((line) => line.trim()).filter(Boolean);
11456
11160
  const records = [];
11457
11161
  for (const [index, line] of lines.entries()) {
11458
11162
  try {
@@ -11465,7 +11169,7 @@ function readProductBenchmarkRecords(path) {
11465
11169
  }
11466
11170
  function readProductBenchmarkManifest(path) {
11467
11171
  try {
11468
- return validateProductBenchmarkManifest(JSON.parse(readFileSync7(path, "utf8")));
11172
+ return validateProductBenchmarkManifest(JSON.parse(readFileSync6(path, "utf8")));
11469
11173
  } catch (err) {
11470
11174
  wrapValidationError(path, err);
11471
11175
  }
@@ -11668,11 +11372,7 @@ export {
11668
11372
  OTEL_AGENT_EVAL_SCOPE,
11669
11373
  OUTPUT_VALUE,
11670
11374
  OtlpFileTraceStore,
11671
- POLICY_EDIT_AXES,
11672
- POLICY_EDIT_CANDIDATE_RECORD_SCHEMA,
11673
- POLICY_EDIT_TARGET_SURFACES,
11674
11375
  PairwiseSteeringOptimizer,
11675
- PolicyEditValidationError,
11676
11376
  ProductClient,
11677
11377
  PromptRegistry,
11678
11378
  REDACTION_VERSION,
@@ -11718,7 +11418,6 @@ export {
11718
11418
  ValidationError,
11719
11419
  VerificationError,
11720
11420
  acquisitionPlansForKnowledgeGaps,
11721
- admitPolicyEdit,
11722
11421
  adversarialJudge,
11723
11422
  agentProfileCellHashMaterial,
11724
11423
  agentProfileCellKey,
@@ -11738,7 +11437,6 @@ export {
11738
11437
  analyzeTraces,
11739
11438
  appendScorecard,
11740
11439
  applyLlmSpanOtlpAttributes,
11741
- applyPolicyEditToSurface,
11742
11440
  applyToolSpanOtlpAttributes,
11743
11441
  argHash,
11744
11442
  asNumber,
@@ -11772,7 +11470,6 @@ export {
11772
11470
  bootstrapCi,
11773
11471
  buildAgentInterfaceProfileCell,
11774
11472
  buildAgentProfileCell,
11775
- buildAgreementJudge,
11776
11473
  buildDefaultAnalystRegistry,
11777
11474
  buildDriverSystemPrompt,
11778
11475
  buildProductBenchmarkManifest,
@@ -11820,7 +11517,6 @@ export {
11820
11517
  composeValidators,
11821
11518
  computeExperimentStats,
11822
11519
  computeFindingId,
11823
- computePolicyEditId,
11824
11520
  computeToolUseMetrics,
11825
11521
  computeTraceMetrics,
11826
11522
  confidenceInterval,
@@ -11867,10 +11563,8 @@ export {
11867
11563
  defaultBlendWeights,
11868
11564
  defaultIsMaterial,
11869
11565
  defaultJudges,
11870
- defaultParseStudentLabel,
11871
11566
  defaultProviderRedactor,
11872
11567
  defaultReferenceReplayMatcher,
11873
- defaultRenderStudentPrompt,
11874
11568
  defaultTraceInsightPanel,
11875
11569
  deployGateLayer,
11876
11570
  describeTraceInsightScope,
@@ -11910,7 +11604,6 @@ export {
11910
11604
  feedbackTrajectoriesToOptimizerRows,
11911
11605
  feedbackTrajectoryToDatasetScenario,
11912
11606
  feedbackTrajectoryToOptimizerRow,
11913
- fieldAgreement,
11914
11607
  fileContains,
11915
11608
  fileExists,
11916
11609
  fileExperimentStore,
@@ -11968,7 +11661,6 @@ export {
11968
11661
  isLlmSpan,
11969
11662
  isModelPriced,
11970
11663
  isOtelConfigured,
11971
- isPolicyEdit,
11972
11664
  isRetrievalSpan,
11973
11665
  isRolloutLine,
11974
11666
  isRunRecord,
@@ -11994,15 +11686,12 @@ export {
11994
11686
  llmJudge,
11995
11687
  llmSpanFromProvider,
11996
11688
  llmSpans,
11997
- loadGoldScenarios,
11998
11689
  loadScorecard,
11999
11690
  loadScorerFromGrader,
12000
11691
  localCommandRunner,
12001
11692
  lowercaseMutator,
12002
11693
  makeEvalTools,
12003
11694
  makeFinding,
12004
- makePolicyEdit,
12005
- makePolicyEditCandidateRecord,
12006
11695
  mannWhitneyU,
12007
11696
  mapConcurrent,
12008
11697
  matchGoldens,
@@ -12043,7 +11732,6 @@ export {
12043
11732
  paretoFrontierWithCrowding,
12044
11733
  parseCorrectnessResponse,
12045
11734
  parseFeedbackTrajectoriesJsonl,
12046
- parseGoldJsonl,
12047
11735
  parseReflectionResponse,
12048
11736
  parseRunRecordSafe,
12049
11737
  parseRuntimeTrajectoryHookEvent,
@@ -12054,8 +11742,6 @@ export {
12054
11742
  pearsonR,
12055
11743
  pixelDeltaRatio,
12056
11744
  planTraceInsightQuestions,
12057
- policyEditFromFinding,
12058
- policyEditsFromFindings,
12059
11745
  politenessPrefixMutator,
12060
11746
  positionalBias,
12061
11747
  preflightModels,
@@ -12118,7 +11804,6 @@ export {
12118
11804
  runBehavioralCanaries,
12119
11805
  runCanaries,
12120
11806
  runCounterfactual,
12121
- runDistillation,
12122
11807
  runE2EWorkflow,
12123
11808
  runEvalCampaign,
12124
11809
  runExpectations,
@@ -12144,7 +11829,6 @@ export {
12144
11829
  scoreContinuity,
12145
11830
  scoreFromEvals,
12146
11831
  scoreKnowledgeReadiness,
12147
- scorePolicyEditReadiness,
12148
11832
  scorePrReviewComments,
12149
11833
  scorePrReviewSource,
12150
11834
  scoreRedTeamOutput,
@@ -12159,7 +11843,6 @@ export {
12159
11843
  showMeasured,
12160
11844
  signManifest,
12161
11845
  spearmanR,
12162
- splitGold,
12163
11846
  statusAdvanced,
12164
11847
  stopOnNoProgress,
12165
11848
  stopOnRepeatedAction,
@@ -12197,8 +11880,6 @@ export {
12197
11880
  urlContains,
12198
11881
  userQuestionsForKnowledgeGaps,
12199
11882
  validateAgentProfileCell,
12200
- validatePolicyEdit,
12201
- validatePolicyEditCandidateRecord,
12202
11883
  validateProductBenchmarkManifest,
12203
11884
  validateProductBenchmarkRecord,
12204
11885
  validateProductBenchmarkRun,