@tangle-network/agent-eval 0.117.1 → 0.118.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 (143) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/analyst/index.d.ts +2772 -21
  3. package/dist/analyst/index.js +7 -6
  4. package/dist/analyst/index.js.map +1 -1
  5. package/dist/belief-state/index.d.ts +706 -10
  6. package/dist/belief-state/index.js +2 -1
  7. package/dist/belief-state/index.js.map +1 -1
  8. package/dist/benchmarks/index.d.ts +958 -14
  9. package/dist/benchmarks/index.js +12 -10
  10. package/dist/builder-eval/index.d.ts +449 -4
  11. package/dist/builder-eval/index.js +4 -3
  12. package/dist/builder-eval/index.js.map +1 -1
  13. package/dist/campaign/index.d.ts +4275 -73
  14. package/dist/campaign/index.js +12 -10
  15. package/dist/{chunk-VF3XSYTI.js → chunk-33JA4TFA.js} +6 -6
  16. package/dist/{chunk-4JLWXDYA.js → chunk-3EHHMC6E.js} +2 -2
  17. package/dist/{chunk-CCZIVI3F.js → chunk-BFW56GTT.js} +2 -2
  18. package/dist/{chunk-YZPO4UHR.js → chunk-FTUMG2U7.js} +124 -149
  19. package/dist/chunk-FTUMG2U7.js.map +1 -0
  20. package/dist/{chunk-E4BUPP7Z.js → chunk-HKUCJ437.js} +38 -66
  21. package/dist/chunk-HKUCJ437.js.map +1 -0
  22. package/dist/{chunk-HZHNRYHK.js → chunk-K6N6XJJX.js} +2 -2
  23. package/dist/chunk-KSDQVPLR.js +286 -0
  24. package/dist/chunk-KSDQVPLR.js.map +1 -0
  25. package/dist/chunk-MA6HLL3S.js +65 -0
  26. package/dist/chunk-MA6HLL3S.js.map +1 -0
  27. package/dist/{chunk-MGEHEHSN.js → chunk-OIIMMLRB.js} +11 -11
  28. package/dist/{chunk-DXZRATT5.js → chunk-OYZAPX5G.js} +3 -3
  29. package/dist/chunk-PXE2VKMX.js +140 -0
  30. package/dist/chunk-PXE2VKMX.js.map +1 -0
  31. package/dist/{chunk-JSJZ4PJ6.js → chunk-Q442S5AS.js} +17 -17
  32. package/dist/{chunk-ODVOOEWQ.js → chunk-QBRSJK47.js} +2 -2
  33. package/dist/{chunk-S2F4J57L.js → chunk-QKEGNI5B.js} +77 -32
  34. package/dist/chunk-QKEGNI5B.js.map +1 -0
  35. package/dist/{chunk-5UF54T55.js → chunk-S3UZOQ5Y.js} +34 -7
  36. package/dist/chunk-S3UZOQ5Y.js.map +1 -0
  37. package/dist/{chunk-FQNLDL4D.js → chunk-SVH2ANFD.js} +136 -4
  38. package/dist/chunk-SVH2ANFD.js.map +1 -0
  39. package/dist/{chunk-GQCZRZ7L.js → chunk-U5CHZ5M3.js} +9 -9
  40. package/dist/{chunk-TVVP3ZZQ.js → chunk-VQMK5FMP.js} +2 -1
  41. package/dist/{chunk-TVVP3ZZQ.js.map → chunk-VQMK5FMP.js.map} +1 -1
  42. package/dist/chunk-WDHBCA3M.js +31 -0
  43. package/dist/chunk-WDHBCA3M.js.map +1 -0
  44. package/dist/{chunk-HQPHZGL6.js → chunk-YLMUS4MM.js} +9 -9
  45. package/dist/{chunk-LQUTGLOZ.js → chunk-ZET2UAYW.js} +15 -65
  46. package/dist/chunk-ZET2UAYW.js.map +1 -0
  47. package/dist/contract/index.d.ts +4012 -38
  48. package/dist/contract/index.js +56 -29
  49. package/dist/contract/index.js.map +1 -1
  50. package/dist/control.d.ts +1013 -9
  51. package/dist/control.js +4 -3
  52. package/dist/fuzz.d.ts +194 -4
  53. package/dist/fuzz.js +3 -3
  54. package/dist/hosted/index.d.ts +498 -17
  55. package/dist/index.d.ts +10992 -1288
  56. package/dist/index.js +101 -80
  57. package/dist/index.js.map +1 -1
  58. package/dist/matrix/index.d.ts +139 -4
  59. package/dist/meta-eval/index.d.ts +862 -15
  60. package/dist/meta-eval/index.js +2 -1
  61. package/dist/meta-eval/index.js.map +1 -1
  62. package/dist/multishot/index.d.ts +214 -14
  63. package/dist/openapi.json +1 -1
  64. package/dist/pipelines/index.d.ts +392 -7
  65. package/dist/pipelines/index.js +5 -3
  66. package/dist/pipelines/index.js.map +1 -1
  67. package/dist/reporting.d.ts +1277 -17
  68. package/dist/rl.d.ts +2359 -28
  69. package/dist/rl.js +6 -5
  70. package/dist/rl.js.map +1 -1
  71. package/dist/storyboard/index.d.ts +86 -1
  72. package/dist/trace-attributes.d.ts +16 -0
  73. package/dist/trace-attributes.js +32 -0
  74. package/dist/trace-attributes.js.map +1 -0
  75. package/dist/traces.d.ts +1978 -697
  76. package/dist/traces.js +53 -32
  77. package/dist/wire/index.d.ts +655 -9
  78. package/docs/insight-report.md +44 -0
  79. package/package.json +9 -3
  80. package/dist/adversarial-B7loGVVX.d.ts +0 -19
  81. package/dist/analyst-C8HHvfJp.d.ts +0 -88
  82. package/dist/analyze-runs--2x39HZ7.d.ts +0 -81
  83. package/dist/baseline-DKq3gJpP.d.ts +0 -141
  84. package/dist/calibration-C8MTS7cw.d.ts +0 -101
  85. package/dist/chunk-5UF54T55.js.map +0 -1
  86. package/dist/chunk-E4BUPP7Z.js.map +0 -1
  87. package/dist/chunk-FQNLDL4D.js.map +0 -1
  88. package/dist/chunk-LQUTGLOZ.js.map +0 -1
  89. package/dist/chunk-S2F4J57L.js.map +0 -1
  90. package/dist/chunk-YZPO4UHR.js.map +0 -1
  91. package/dist/code-agent-session-CjZsVd19.d.ts +0 -87
  92. package/dist/control-6vuGfmDH.d.ts +0 -258
  93. package/dist/cost-ledger-DWy3XdJc.d.ts +0 -183
  94. package/dist/dataset-NENEzRgk.d.ts +0 -115
  95. package/dist/default-registry-DaK8b3fv.d.ts +0 -155
  96. package/dist/emitter-CjD7vUwv.d.ts +0 -122
  97. package/dist/errors-oeQrLqXC.d.ts +0 -74
  98. package/dist/failure-cluster-DOAcSJ87.d.ts +0 -76
  99. package/dist/feedback-trajectory-BUnM58xL.d.ts +0 -348
  100. package/dist/gepa-eESocoDi.d.ts +0 -642
  101. package/dist/index-PdX4VnPA.d.ts +0 -423
  102. package/dist/insight-report-DY4nDW9Q.d.ts +0 -310
  103. package/dist/integrity-DqlBiLyK.d.ts +0 -81
  104. package/dist/judge-calibration-7C-IDmKr.d.ts +0 -145
  105. package/dist/kind-factory-ClZmO25A.d.ts +0 -171
  106. package/dist/llm-client-qoDd18Qz.d.ts +0 -289
  107. package/dist/multi-layer-verifier-BsqKuLyN.d.ts +0 -150
  108. package/dist/off-policy-DiwuKKg7.d.ts +0 -132
  109. package/dist/outcome-store-rnXLEqSn.d.ts +0 -63
  110. package/dist/policy-edit-wG9uFEFm.d.ts +0 -455
  111. package/dist/pre-registration-BWQhJ3vz.d.ts +0 -761
  112. package/dist/provenance-DpjwyseI.d.ts +0 -541
  113. package/dist/query-CF7PG61p.d.ts +0 -35
  114. package/dist/raw-provider-sink-C46HDghv.d.ts +0 -132
  115. package/dist/release-report-C8G2i5Xi.d.ts +0 -236
  116. package/dist/researcher-C8XyxQsu.d.ts +0 -387
  117. package/dist/rubric-predictive-validity-p49lLVrE.d.ts +0 -105
  118. package/dist/run-record-BDH49H2E.d.ts +0 -360
  119. package/dist/runtime-trajectory-DGBIUt4B.d.ts +0 -49
  120. package/dist/schema-B3Q3l9Z_.d.ts +0 -201
  121. package/dist/semantic-concept-judge-CXnPEJbf.d.ts +0 -723
  122. package/dist/sequential-5iSVfzl2.d.ts +0 -139
  123. package/dist/series-convergence-D5OWMBg6.d.ts +0 -33
  124. package/dist/statistics-KUnG73jH.d.ts +0 -494
  125. package/dist/storage-DrX3v_5B.d.ts +0 -50
  126. package/dist/store-C1YxJDEK.d.ts +0 -248
  127. package/dist/store-DGqD0Pyo.d.ts +0 -116
  128. package/dist/summary-report-C5bKFfm-.d.ts +0 -445
  129. package/dist/test-graded-scenario-B0ybnPY7.d.ts +0 -166
  130. package/dist/types-BSw1rOUB.d.ts +0 -634
  131. package/dist/types-BUxNaJ8c.d.ts +0 -108
  132. package/dist/types-BkfcQnxV.d.ts +0 -313
  133. package/dist/verdict-C9MlYujm.d.ts +0 -35
  134. /package/dist/{chunk-VF3XSYTI.js.map → chunk-33JA4TFA.js.map} +0 -0
  135. /package/dist/{chunk-4JLWXDYA.js.map → chunk-3EHHMC6E.js.map} +0 -0
  136. /package/dist/{chunk-CCZIVI3F.js.map → chunk-BFW56GTT.js.map} +0 -0
  137. /package/dist/{chunk-HZHNRYHK.js.map → chunk-K6N6XJJX.js.map} +0 -0
  138. /package/dist/{chunk-MGEHEHSN.js.map → chunk-OIIMMLRB.js.map} +0 -0
  139. /package/dist/{chunk-DXZRATT5.js.map → chunk-OYZAPX5G.js.map} +0 -0
  140. /package/dist/{chunk-JSJZ4PJ6.js.map → chunk-Q442S5AS.js.map} +0 -0
  141. /package/dist/{chunk-ODVOOEWQ.js.map → chunk-QBRSJK47.js.map} +0 -0
  142. /package/dist/{chunk-GQCZRZ7L.js.map → chunk-U5CHZ5M3.js.map} +0 -0
  143. /package/dist/{chunk-HQPHZGL6.js.map → chunk-YLMUS4MM.js.map} +0 -0
@@ -1,13 +1,354 @@
1
- import { c as CalibrationReport } from '../calibration-C8MTS7cw.js';
2
- import { O as OffPolicyEstimate, a as OffPolicyOptions, b as OffPolicyTrajectory } from '../off-policy-DiwuKKg7.js';
3
- import { d as CodeAgentSessionSource, a as CodeAgentSessionIntakeOptions, c as CodeAgentSessionMetrics, C as CodeAgentSessionDiagnostic } from '../code-agent-session-CjZsVd19.js';
4
- import { R as RunRecord, a as RunSplitTag } from '../run-record-BDH49H2E.js';
5
- import { T as TraceStore } from '../store-DGqD0Pyo.js';
6
- import { R as RuntimeTrajectoryRecord, P as ProjectRuntimeTrajectoryEvidenceOptions, a as RuntimeTrajectoryEvidenceProjection } from '../runtime-trajectory-DGBIUt4B.js';
7
- import '../schema-B3Q3l9Z_.js';
8
- import '../outcome-store-rnXLEqSn.js';
9
- import '@tangle-network/agent-interface';
10
- import '../errors-oeQrLqXC.js';
1
+ type RunStatus = 'running' | 'completed' | 'failed' | 'aborted';
2
+ interface BudgetSpec {
3
+ tokens?: number;
4
+ wallMs?: number;
5
+ calls?: number;
6
+ usd?: number;
7
+ }
8
+ interface RunOutcome$1 {
9
+ score?: number;
10
+ pass?: boolean;
11
+ failureClass?: FailureClass;
12
+ notes?: string;
13
+ }
14
+ /**
15
+ * Layer — optional classification in a nested build workflow.
16
+ * `builder`: the meta-agent editing a project (e.g. agent-builder Forge chat).
17
+ * `app-build`: sandbox harness that compiled + tested the generated scaffold.
18
+ * `app-runtime`: a run of the generated agent against a domain scenario.
19
+ * `meta`: any meta-eval (judge replay, correlation analysis).
20
+ */
21
+ type RunLayer = 'builder' | 'app-build' | 'app-runtime' | 'meta' | 'custom';
22
+ interface Run {
23
+ runId: string;
24
+ /**
25
+ * Stable identifier of the scenario being executed.
26
+ *
27
+ * Always populated on the persisted Run — but `TraceEmitter.startRun` accepts
28
+ * input WITHOUT this field, substituting a sensible default
29
+ * (`run.layer ?? run.tags?.['kind'] ?? 'runtime'`) when the caller has no
30
+ * curated scenario to anchor to (runtime / operator / meta-eval runs). This
31
+ * keeps the persisted shape unambiguous for downstream filters + aggregations
32
+ * while removing the boilerplate of inventing placeholder ids at the call site.
33
+ */
34
+ scenarioId: string;
35
+ variantId?: string;
36
+ datasetVersion?: string;
37
+ /** Git SHA of agent code at run time. */
38
+ codeSha?: string;
39
+ /** Hash of the prompt template + any system prompt. */
40
+ promptSha?: string;
41
+ /** Model id + date + system-prompt hash, concatenated. */
42
+ modelFingerprint?: string;
43
+ seed?: number;
44
+ /** Arbitrary environment markers (shell, docker version, tz). */
45
+ envFingerprint?: Record<string, string>;
46
+ /** Version of the redaction rules applied to this run. */
47
+ redactionVersion?: string;
48
+ /** Parent run in a nested build workflow. A builder run's children are
49
+ * app-build runs; those children are app-runtime runs. */
50
+ parentRunId?: string;
51
+ /** Stable project identifier — groups runs across chats + sessions. */
52
+ projectId?: string;
53
+ /** Chat/conversation identifier within a project. */
54
+ chatId?: string;
55
+ /** Layer classification — hint for aggregation; not enforced. */
56
+ layer?: RunLayer;
57
+ startedAt: number;
58
+ endedAt?: number;
59
+ status: RunStatus;
60
+ outcome?: RunOutcome$1;
61
+ budget?: BudgetSpec;
62
+ /** Free-form labels for downstream grouping. */
63
+ tags?: Record<string, string>;
64
+ }
65
+ type SpanKind = 'agent' | 'llm' | 'tool' | 'retrieval' | 'judge' | 'sandbox' | 'custom';
66
+ type SpanStatus = 'ok' | 'error';
67
+ interface SpanBase {
68
+ spanId: string;
69
+ parentSpanId?: string;
70
+ runId: string;
71
+ kind: SpanKind;
72
+ name: string;
73
+ startedAt: number;
74
+ endedAt?: number;
75
+ status?: SpanStatus;
76
+ error?: string;
77
+ /** Anything not covered by typed fields. Kept deliberately free-form. */
78
+ attributes?: Record<string, unknown>;
79
+ }
80
+ interface Message {
81
+ role: 'system' | 'user' | 'assistant' | 'tool';
82
+ content: string;
83
+ tokens?: number;
84
+ /** Multi-modal content descriptors; blobs themselves live in Artifacts. */
85
+ images?: Array<{
86
+ artifactId?: string;
87
+ url?: string;
88
+ mime?: string;
89
+ }>;
90
+ }
91
+ interface LlmSpan extends SpanBase {
92
+ kind: 'llm';
93
+ model: string;
94
+ messages: Message[];
95
+ output?: string;
96
+ inputTokens?: number;
97
+ /** All generated tokens, including the reasoning subset when present. */
98
+ outputTokens?: number;
99
+ cachedTokens?: number;
100
+ cacheWriteTokens?: number;
101
+ /** Reasoning-token subset of `outputTokens`. */
102
+ reasoningTokens?: number;
103
+ costUsd?: number;
104
+ finishReason?: string;
105
+ }
106
+ interface ToolSpan extends SpanBase {
107
+ kind: 'tool';
108
+ toolName: string;
109
+ args: unknown;
110
+ /** False when the source observed the call but did not capture its arguments. */
111
+ argsCaptured?: boolean;
112
+ result?: unknown;
113
+ latencyMs?: number;
114
+ }
115
+ interface RetrievalSpan extends SpanBase {
116
+ kind: 'retrieval';
117
+ query: string;
118
+ hits: Array<{
119
+ docId: string;
120
+ score: number;
121
+ content?: string;
122
+ }>;
123
+ }
124
+ interface JudgeSpan extends SpanBase {
125
+ kind: 'judge';
126
+ judgeId: string;
127
+ /** Span this judgment applies to. */
128
+ targetSpanId: string;
129
+ dimension: string;
130
+ /** Numeric score (free-range; interpretation up to the judge). */
131
+ score: number;
132
+ rationale?: string;
133
+ evidence?: string;
134
+ }
135
+ interface SandboxSpan extends SpanBase {
136
+ kind: 'sandbox';
137
+ image?: string;
138
+ command?: string;
139
+ exitCode?: number;
140
+ testsTotal?: number;
141
+ testsPassed?: number;
142
+ stdoutHash?: string;
143
+ stderrHash?: string;
144
+ /** Duration in ms; the harness fills this explicitly (endedAt - startedAt may miss setup). */
145
+ wallMs?: number;
146
+ }
147
+ interface GenericSpan extends SpanBase {
148
+ kind: 'agent' | 'custom';
149
+ }
150
+ type Span = LlmSpan | ToolSpan | RetrievalSpan | JudgeSpan | SandboxSpan | GenericSpan;
151
+ type EventKind = 'log' | 'error' | 'budget_decrement' | 'budget_breach' | 'state_mutation' | 'policy_violation' | 'redaction_applied' | 'custom';
152
+ interface TraceEvent {
153
+ eventId: string;
154
+ runId: string;
155
+ spanId?: string;
156
+ kind: EventKind;
157
+ timestamp: number;
158
+ payload: Record<string, unknown>;
159
+ }
160
+ interface BudgetLedgerEntry {
161
+ runId: string;
162
+ dimension: keyof BudgetSpec;
163
+ limit: number;
164
+ consumed: number;
165
+ remaining: number;
166
+ timestamp: number;
167
+ breached: boolean;
168
+ /** Span that triggered this entry, if any. */
169
+ spanId?: string;
170
+ }
171
+ interface Artifact {
172
+ artifactId: string;
173
+ runId: string;
174
+ spanId?: string;
175
+ contentType: string;
176
+ sizeBytes: number;
177
+ /** sha256 in hex. */
178
+ hash: string;
179
+ /** External storage URL (R2, S3, filesystem path). */
180
+ storageUrl?: string;
181
+ /** Inline content for small blobs — keep under ~64KB. */
182
+ inlineContent?: string;
183
+ }
184
+ type FailureClass = 'success' | 'reasoning_error' | 'tool_selection_error' | 'tool_argument_error' | 'tool_recovery_failure' | 'hallucination' | 'instruction_following' | 'safety_refusal_miss' | 'policy_violation' | 'budget_exceeded' | 'format_drift' | 'permission_escalation' | 'pii_leak' | 'cost_overrun' | 'timeout' | 'sandbox_failure' | 'missing_user_data' | 'missing_domain_data' | 'missing_codebase_context' | 'missing_runtime_context' | 'missing_credentials' | 'missing_integration_connection' | 'missing_integration_scope' | 'integration_approval_required' | 'integration_auth_expired' | 'integration_provider_failure' | 'bad_integration_manifest' | 'unsafe_integration_write_denied' | 'stale_external_data' | 'bad_retrieval' | 'insufficient_evidence' | 'contradictory_evidence' | 'ambiguous_user_intent' | 'knowledge_readiness_blocked' | 'unknown';
185
+
186
+ interface RunFilter {
187
+ scenarioId?: string;
188
+ variantId?: string;
189
+ status?: RunStatus;
190
+ since?: number;
191
+ until?: number;
192
+ tag?: {
193
+ key: string;
194
+ value: string;
195
+ };
196
+ parentRunId?: string;
197
+ projectId?: string;
198
+ chatId?: string;
199
+ layer?: RunLayer;
200
+ }
201
+ interface SpanFilter {
202
+ runId?: string;
203
+ parentSpanId?: string;
204
+ kind?: SpanKind;
205
+ name?: string;
206
+ toolName?: string;
207
+ judgeId?: string;
208
+ since?: number;
209
+ until?: number;
210
+ }
211
+ interface EventFilter {
212
+ runId?: string;
213
+ spanId?: string;
214
+ kind?: EventKind;
215
+ since?: number;
216
+ until?: number;
217
+ }
218
+ interface TraceStore {
219
+ appendRun(run: Run): Promise<void>;
220
+ updateRun(runId: string, patch: Partial<Run>): Promise<void>;
221
+ appendSpan(span: Span): Promise<void>;
222
+ updateSpan(spanId: string, patch: Partial<Span>): Promise<void>;
223
+ appendEvent(event: TraceEvent): Promise<void>;
224
+ appendArtifact(artifact: Artifact): Promise<void>;
225
+ appendBudgetEntry(entry: BudgetLedgerEntry): Promise<void>;
226
+ getRun(runId: string): Promise<Run | undefined>;
227
+ listRuns(filter?: RunFilter): Promise<Run[]>;
228
+ spans(filter?: SpanFilter): Promise<Span[]>;
229
+ events(filter?: EventFilter): Promise<TraceEvent[]>;
230
+ budget(runId: string): Promise<BudgetLedgerEntry[]>;
231
+ artifacts(runId: string): Promise<Artifact[]>;
232
+ }
233
+
234
+ /**
235
+ * Calibration curve — binned "if eval says X, what does reality show?"
236
+ *
237
+ * Companion to correlationStudy. Raw correlation is a single number;
238
+ * the calibration curve shows *where* the eval is well-calibrated vs
239
+ * overconfident / underconfident. Buckets the eval metric, computes
240
+ * mean outcome per bucket, reports expected-calibration-error (ECE).
241
+ */
242
+
243
+ interface CalibrationBin {
244
+ lower: number;
245
+ upper: number;
246
+ n: number;
247
+ evalMean: number;
248
+ outcomeMean: number;
249
+ /** |outcomeMean − evalMean|; contributes to ECE weighted by n/total. */
250
+ gap: number;
251
+ }
252
+ interface CalibrationReport {
253
+ evalMetric: string;
254
+ outcomeMetric: string;
255
+ n: number;
256
+ bins: CalibrationBin[];
257
+ /** Expected Calibration Error — Σ (n_i/N) × |outcomeMean_i − evalMean_i|. */
258
+ ece: number;
259
+ /** Max bin gap — upper bound on miscalibration. */
260
+ maxGap: number;
261
+ }
262
+
263
+ /**
264
+ * Off-policy evaluation primitives.
265
+ *
266
+ * Standard inverse-probability-weighted (IPS), self-normalized
267
+ * importance-weighted (SNIPS), and doubly-robust (DR) estimators for the
268
+ * value of a *target* policy given trajectories collected under a
269
+ * *behavior* policy. This is the canonical RL eval task: "we have last
270
+ * week's runs, we changed the policy — how would the new one do without
271
+ * re-running?"
272
+ *
273
+ * The math here is textbook (Dudík, Langford, Li 2011 for DR; Swaminathan
274
+ * & Joachims 2015 for SNIPS) but the *application* to LLM-agent
275
+ * evaluation needs care:
276
+ *
277
+ * - The "policy" is the (prompt, tool config, model snapshot) triple.
278
+ * Two policies have the same probability over an action *iff* their
279
+ * LLM call would emit the same token with the same probability —
280
+ * which is generally unknowable without the model log-probs.
281
+ * - For LLM agents, propensity scores must be supplied by the caller
282
+ * (logged in the trace, recovered from token log-probs, or estimated
283
+ * via a learned propensity model). We do NOT estimate propensity here.
284
+ * - Doubly-robust requires a Q-function (model-based reward predictor).
285
+ * We accept any callable; consumers pass either a tabular average,
286
+ * a regression fit, or a learned reward model.
287
+ *
288
+ * Bias / variance tradeoffs:
289
+ * - IPS: unbiased; high variance for small overlap, infinite variance
290
+ * when target has support outside behavior.
291
+ * - SNIPS: lower variance, slight bias; usually preferred in practice.
292
+ * - DR: doubly-robust — unbiased if either propensity OR Q-function is
293
+ * correct. Lowest practical variance when Q is decent. Use this.
294
+ *
295
+ * Caveat the panel will land: on the LLM-agent setting, propensity scores
296
+ * recovered from token log-probs are noisy, the action space is enormous,
297
+ * and overlap is often poor. These estimators are useful but not magic;
298
+ * complement with `replayCampaign` (exact replay where the request hashes
299
+ * match) for high-confidence answers and OPE for the gap.
300
+ */
301
+ interface OffPolicyTrajectory {
302
+ /** Stable id, for traceability through the dataset. */
303
+ runId: string;
304
+ /** Reward observed under the behavior policy (the realized outcome). */
305
+ reward: number;
306
+ /**
307
+ * Behavior-policy probability of the action that was taken. For LLM
308
+ * agents this is typically `exp(sum(token_log_probs))` over the chosen
309
+ * trajectory. Must be in (0, 1].
310
+ */
311
+ behaviorProb: number;
312
+ /**
313
+ * Target-policy probability of the same action. For replay-style
314
+ * counterfactual evaluation this is what the *new* policy would have
315
+ * assigned to the *old* trajectory. Must be in [0, 1].
316
+ */
317
+ targetProb: number;
318
+ /**
319
+ * Optional model-based reward prediction at the same context. Used by
320
+ * `doublyRobust`. Set to `null` for IPS-only evaluation.
321
+ */
322
+ qHat?: number | null;
323
+ }
324
+ interface OffPolicyEstimate {
325
+ /** Estimated value of the target policy. */
326
+ value: number;
327
+ /** Standard error of the estimate. */
328
+ standardError: number;
329
+ /** Effective sample size (Kong 1992). Lower = more reliance on a few high-weight samples. */
330
+ effectiveSampleSize: number;
331
+ /** Number of trajectories used. */
332
+ n: number;
333
+ /**
334
+ * Diagnostic: maximum importance weight observed. Large values (>>10x
335
+ * mean) are a red flag — variance is dominated by a few outliers.
336
+ */
337
+ maxImportanceWeight: number;
338
+ }
339
+ interface OffPolicyOptions {
340
+ /**
341
+ * Cap importance weights at this value (Ionides 2008 truncated IS) to
342
+ * trade unbiasedness for variance reduction. Default `Infinity` (no cap).
343
+ * Set e.g. `10` for stable estimates when the policies are close.
344
+ */
345
+ weightCap?: number;
346
+ /** Reward clipping range. Default `[0, 1]`. */
347
+ rewardClip?: {
348
+ low: number;
349
+ high: number;
350
+ };
351
+ }
11
352
 
12
353
  declare const BELIEF_DECISION_KINDS: readonly ["continue", "verify", "ask", "retry", "stop", "memory-write", "memory-read", "tool-select", "skill-select", "workflow-select", "surface-promote"];
13
354
  type BeliefDecisionKind = (typeof BELIEF_DECISION_KINDS)[number];
@@ -211,6 +552,317 @@ interface BeliefCalibrationOptions {
211
552
  }
212
553
  declare function calibrateBeliefDecisions(points: BeliefDecisionPoint[], options?: BeliefCalibrationOptions): CalibrationReport | null;
213
554
 
555
+ type AgentProfileCellSchemaVersion = 'agent-profile-cell/v1';
556
+ type AgentProfileDimensionValue = string | number | boolean | null;
557
+ interface AgentProfileSource {
558
+ /** Runtime/profile contract being fingerprinted, e.g. `agent-interface-profile`. */
559
+ kind: string;
560
+ /** sha256 over the canonical source profile object. */
561
+ hash: string;
562
+ }
563
+ interface AgentProfileHarness {
564
+ id: string;
565
+ version?: string;
566
+ hash?: string;
567
+ }
568
+ interface AgentProfileCell {
569
+ schemaVersion: AgentProfileCellSchemaVersion;
570
+ cellId: string;
571
+ profileId: string;
572
+ sourceProfile: AgentProfileSource;
573
+ harness?: AgentProfileHarness;
574
+ model?: string;
575
+ promptHash?: string;
576
+ dimensions?: Record<string, AgentProfileDimensionValue>;
577
+ }
578
+
579
+ /**
580
+ * Paper-grade RunRecord schema + runtime validator.
581
+ *
582
+ * Every run that participates in a promotion gate, paper table, or
583
+ * researcher loop SHOULD be recorded as a `RunRecord`. The mandatory
584
+ * fields are exactly those the paper "Two Loops, Three Roles" requires
585
+ * for reproducibility: who/what/when/cost/seed/hash, plus the search vs
586
+ * holdout split tag and either a `searchScore` or a `holdoutScore`.
587
+ *
588
+ * This is intentionally NOT a replacement for the rich `Run` /
589
+ * `ProposeReviewReport` / `ScenarioResult` types already in the
590
+ * package. Those are runtime structures with full provenance. A
591
+ * `RunRecord` is the analysis-time projection — the JSON-friendly
592
+ * row you'd put in a parquet file or paste into a notebook.
593
+ *
594
+ * Validate at the boundary:
595
+ *
596
+ * const rec = validateRunRecord(rawJson) // throws on missing
597
+ * const ok = isRunRecord(rawJson) // boolean check
598
+ * const rec = parseRunRecordSafe(rawJson) // { ok, value | error }
599
+ *
600
+ * The validator runs in pure TS — zod is intentionally NOT a
601
+ * dependency. Round-trip tested in `tests/run-record.test.ts`.
602
+ */
603
+
604
+ /** Search/dev/holdout split tag. 'search' is the paper-grade alias for the
605
+ * combined train+test pool that the optimizer is allowed to read. */
606
+ type RunSplitTag = 'search' | 'dev' | 'holdout';
607
+ interface RunTokenUsage {
608
+ input: number;
609
+ /** All generated tokens charged as output, including reasoning tokens. */
610
+ output: number;
611
+ /** Reasoning-token subset of `output`, when the provider reports it. */
612
+ reasoning?: number;
613
+ /** Prompt tokens served from a provider cache. */
614
+ cached?: number;
615
+ /** Prompt tokens written into a provider cache. */
616
+ cacheWrite?: number;
617
+ }
618
+ /**
619
+ * How a run's USD amount was obtained.
620
+ *
621
+ * `costUsd` remains mandatory for wire compatibility. New producers should
622
+ * always populate this discriminated union so a missing bill is never
623
+ * mistaken for an observed zero-dollar run. For `uncaptured`, `costUsd` uses
624
+ * the legacy `0` sentinel while this field carries the truthful null.
625
+ */
626
+ type RunCostProvenance = {
627
+ kind: 'observed';
628
+ usd: number;
629
+ } | {
630
+ kind: 'estimated';
631
+ usd: number;
632
+ } | {
633
+ kind: 'uncaptured';
634
+ usd: null;
635
+ };
636
+ interface RunJudgeMetadata {
637
+ model: string;
638
+ promptVersion: string;
639
+ /** [0,1] confidence the judge declared. Constant judge confidence
640
+ * across many runs is a fallback signal (see `canary.ts`). */
641
+ confidence: number;
642
+ /** True if the judge degraded to a fallback path (rules-only,
643
+ * prior-call cache, etc.). The canary uses this to alert. */
644
+ fallback: boolean;
645
+ }
646
+ /**
647
+ * Per-judge / per-dimension breakdown for runs scored by an ensemble of
648
+ * judges over a multi-dimensional rubric.
649
+ *
650
+ * The collapsed `outcome.searchScore` / `holdoutScore` carries the
651
+ * composite the gate uses. The full breakdown belongs here so consumers
652
+ * can answer "which judge disagreed?", "which dimension dragged the
653
+ * composite down?", and "did half the panel fail?" without re-running.
654
+ *
655
+ * `perJudge[judgeId][dim]` is the canonical source; `perDimMean` and
656
+ * `composite` are convenience projections — derivable but precomputed so
657
+ * downstream IRR primitives (`interRaterReliability`,
658
+ * `corpusInterRaterAgreement`) and reporters don't pay the same
659
+ * aggregation twice.
660
+ *
661
+ * Fail-loud discipline: judges that errored out land in `failedJudges`
662
+ * by id. A missing key in `perJudge` is ambiguous (silent zero vs not
663
+ * run); the explicit list makes a partial-failure recorded as such.
664
+ */
665
+ interface JudgeScoresRecord {
666
+ /** Per-judge per-dimension scores. `{ "kimi-k2.6": { helpfulness: 0.8, clarity: 0.7 }, ... }`. */
667
+ perJudge: Record<string, Record<string, number>>;
668
+ /** Per-dim mean across judges. Convenience — derivable from `perJudge`. */
669
+ perDimMean: Record<string, number>;
670
+ /** Composite mean across all dims and judges. Mirrors the score
671
+ * the gate sees on `outcome.searchScore` / `holdoutScore`. */
672
+ composite: number;
673
+ /** Judges that errored or returned an unparseable verdict. Recorded
674
+ * by id (e.g. `['glm-5.1']`) so a partial-failure case is explicit,
675
+ * not inferred from missing keys in `perJudge`. */
676
+ failedJudges?: string[];
677
+ /** Free-form notes the judges emitted (joined across judges or
678
+ * first-judge only — consumer's choice). */
679
+ notes?: string;
680
+ }
681
+ interface RunOutcome {
682
+ /** Score on the search/optimization split. Optional because a
683
+ * holdout-only evaluation only fills `holdoutScore`. */
684
+ searchScore?: number;
685
+ /** Score on the held-out split. Optional because a search-only run
686
+ * only fills `searchScore`. At least one must be present. */
687
+ holdoutScore?: number;
688
+ /** Bag of any other metric the run produced — judge dimensions,
689
+ * pass/fail counters, latency stats, etc. Numeric only — keeps
690
+ * reporters honest. */
691
+ raw: Record<string, number>;
692
+ /** Per-judge / per-dim breakdown. Consumers writing ensemble
693
+ * judgements populate this; substrate primitives like
694
+ * `interRaterReliability` and `corpusInterRaterAgreement` accept
695
+ * these records as input. Optional — single-judge or scalar-only
696
+ * runs leave it unset. */
697
+ judgeScores?: JudgeScoresRecord;
698
+ /** Authenticity / realness verdict — did the run build the REAL thing on the
699
+ * intended infra, or fake it (see `./authenticity`)? Optional: only domains
700
+ * with an authenticity config populate it. Carried in the corpus so the
701
+ * flywheel / off-policy learning can optimize for real completion, not gamed
702
+ * pass-rate. `score` is 0-1; `gated` is the anti-Goodhart flag — a gated run
703
+ * must not count as a real success regardless of `score`. */
704
+ realness?: {
705
+ score: number;
706
+ gated: boolean;
707
+ reason?: string;
708
+ };
709
+ }
710
+ /**
711
+ * Mandatory paper-grade fields for a single evaluation run. Optional
712
+ * fields are extension points; mandatory fields throw if missing.
713
+ *
714
+ * Hash discipline:
715
+ * - `promptHash` is the sha256 of the EFFECTIVE prompt sent to the
716
+ * model (after any steering bundle merge).
717
+ * - `configHash` is the sha256 of the effective run config (model,
718
+ * temperature, tools, judges, splits). The pair (promptHash,
719
+ * configHash) uniquely identifies an experiment cell.
720
+ *
721
+ * Model snapshot discipline:
722
+ * - `model` MUST encode a snapshot version. Bare aliases like
723
+ * `claude-sonnet-4` or `gpt-4o` are banned — they remap silently.
724
+ * Use `claude-sonnet-4-6@2025-04-15` or `gpt-4o-2024-11-20`.
725
+ */
726
+ interface RunRecord {
727
+ /** UUID for the run. */
728
+ runId: string;
729
+ /** Logical experiment grouping (a treatment vs a baseline within
730
+ * the same sweep should share `experimentId`). */
731
+ experimentId: string;
732
+ /** Stable identifier for the candidate (variant) being run. The
733
+ * promotion gate compares two `candidateId`s on matched items. */
734
+ candidateId: string;
735
+ /** RNG seed for the run. Always recorded — silent re-seeding is
736
+ * the most common cause of non-reproducible numbers. */
737
+ seed: number;
738
+ /** Model identifier WITH snapshot version. */
739
+ model: string;
740
+ /** sha256 of the effective prompt (post-steering). */
741
+ promptHash: string;
742
+ /** sha256 of the effective config. */
743
+ configHash: string;
744
+ /** Git SHA the harness was run from. */
745
+ commitSha: string;
746
+ /** End-to-end wall-clock duration in milliseconds. */
747
+ wallMs: number;
748
+ /** Time spent queued before execution started, if known. */
749
+ queueMs?: number;
750
+ /** Total USD cost. Mandatory — runs without a cost number are
751
+ * unbounded by definition and must not be admitted into the gate.
752
+ * `0` is retained as the compatibility sentinel for an uncaptured amount;
753
+ * inspect `costProvenance` before treating it as observed. */
754
+ costUsd: number;
755
+ /** Observed, model-priced estimate, or genuinely uncaptured USD amount.
756
+ * Optional only so existing serialized RunRecords remain valid. */
757
+ costProvenance?: RunCostProvenance;
758
+ /** Token usage breakdown. */
759
+ tokenUsage: RunTokenUsage;
760
+ /** Judge-side metadata, if a judge was used. */
761
+ judgeMetadata?: RunJudgeMetadata;
762
+ /** Per-split scores + raw bag. */
763
+ outcome: RunOutcome;
764
+ /** Canonical, cross-agent failure class drawn from the shared
765
+ * `FAILURE_CLASSES` taxonomy. This is the aggregation key that makes
766
+ * "which failure dominates across the whole fleet" answerable in ONE
767
+ * vocabulary — every agent classifies against the same enum. Producers
768
+ * set it via the substrate classifier; leave unset only when the failure
769
+ * genuinely can't be classified. */
770
+ failureClass?: FailureClass;
771
+ /** Free-form domain-specific failure detail, scoped UNDER `failureClass`
772
+ * (e.g. failureClass='tool_recovery_failure', failureMode='forge_build_unsatisfied').
773
+ * The within-agent drill-down; `failureClass` is the cross-agent key. */
774
+ failureMode?: string;
775
+ /** Which split this run was drawn from. */
776
+ splitTag: RunSplitTag;
777
+ /**
778
+ * Stable scenario identifier the run was scored against. Optional for
779
+ * backwards compatibility, but **strongly recommended**: every primitive
780
+ * that pairs runs by scenario (preferences, paired stats, BT tournament)
781
+ * keys on this. The campaign artifact populates it canonically; legacy
782
+ * runs without it fall back to inference from `outcome.raw.scenario_id`
783
+ * or `experimentId`.
784
+ */
785
+ scenarioId?: string;
786
+ /**
787
+ * Canonical identity for the agent profile cell that produced this row:
788
+ * profile artifact hash plus optional harness/model/prompt/reporting
789
+ * dimensions. Use `agentProfile.cellId` to group persona sweeps and
790
+ * longitudinal reports by the complete source profile, not by a loose
791
+ * candidate label or opaque config hash.
792
+ */
793
+ agentProfile?: AgentProfileCell;
794
+ }
795
+
796
+ type CodeAgentSessionSource = 'codex' | 'claude-code' | 'opencode' | 'kimi-code' | 'pi';
797
+ interface CodeAgentSessionMetrics {
798
+ entries: number;
799
+ userMessages: number;
800
+ assistantMessages: number;
801
+ reasoningItems: number;
802
+ toolCalls: number;
803
+ toolOutputs: number;
804
+ toolErrors: number;
805
+ patchAttempts: number;
806
+ patchSuccesses: number;
807
+ patchFailures: number;
808
+ turnsStarted: number;
809
+ turnsCompleted: number;
810
+ turnsAborted: number;
811
+ contextCompactions: number;
812
+ prLinks: number;
813
+ fileSnapshots: number;
814
+ graphNodes: number;
815
+ graphEdges: number;
816
+ actionCandidates: number;
817
+ verificationReports: number;
818
+ completionDecisions: number;
819
+ reliabilityRows: number;
820
+ reliabilityLift: number;
821
+ inputTokens: number;
822
+ outputTokens: number;
823
+ reasoningTokens: number;
824
+ cachedTokens: number;
825
+ cacheWriteTokens: number;
826
+ observedCostUsd: number;
827
+ observedCostCaptured?: boolean;
828
+ wallMs: number;
829
+ processScore: number;
830
+ }
831
+ interface CodeAgentSessionDiagnostic {
832
+ source: CodeAgentSessionSource;
833
+ sessionId: string;
834
+ sourcePath?: string;
835
+ entries: number;
836
+ malformedLines: number;
837
+ inferredScore: boolean;
838
+ hasExplicitTerminalSignal: boolean;
839
+ hasQualityLabel: boolean;
840
+ hasTokenUsage: boolean;
841
+ hasCost: boolean;
842
+ costKind?: RunCostProvenance['kind'];
843
+ warnings: string[];
844
+ }
845
+ interface CodeAgentSessionIntakeOptions {
846
+ entries: unknown[];
847
+ malformedLines?: number;
848
+ sourcePath?: string;
849
+ experimentId?: string;
850
+ candidateId?: string;
851
+ seed?: number;
852
+ splitTag?: RunSplitTag;
853
+ scenarioId?: string;
854
+ model?: string;
855
+ promptHash?: string;
856
+ configHash?: string;
857
+ commitSha?: string;
858
+ score?: number;
859
+ /** Explicit cost receipt. Use `uncaptured` when the source says dollars
860
+ * were not captured; the adapter will not relabel its compatibility $0
861
+ * sentinel as observed. When omitted, source-reported cost wins, then a
862
+ * token-priced estimate, then uncaptured. */
863
+ costProvenance?: RunCostProvenance;
864
+ }
865
+
214
866
  interface BeliefOpeOptions extends OffPolicyOptions {
215
867
  minEffectiveSampleSize?: number;
216
868
  minEffectiveSampleRatio?: number;
@@ -574,6 +1226,50 @@ interface RuntimeBeliefPhase0Measurement {
574
1226
  }
575
1227
  declare function buildRuntimeBeliefPhase0Measurement(options: BuildRuntimeBeliefPhase0MeasurementOptions): RuntimeBeliefPhase0Measurement;
576
1228
 
1229
+ interface RuntimeTrajectoryHookEvent {
1230
+ id: string;
1231
+ runId: string;
1232
+ scenarioId?: string;
1233
+ target: string;
1234
+ phase: string;
1235
+ timestamp: number;
1236
+ stepIndex?: number;
1237
+ parentId?: string;
1238
+ payload?: unknown;
1239
+ metadata?: Record<string, unknown>;
1240
+ }
1241
+ interface RuntimeTrajectoryRecord {
1242
+ id?: string;
1243
+ scenarioId?: string;
1244
+ splitTag?: RunSplitTag;
1245
+ runtimeEvents?: unknown;
1246
+ [key: string]: unknown;
1247
+ }
1248
+ interface RuntimeTrajectoryRunRecord {
1249
+ runId: string;
1250
+ scenarioId?: string;
1251
+ splitTag: RunSplitTag;
1252
+ }
1253
+ interface RuntimeTrajectoryEvidenceSummary {
1254
+ recordCount: number;
1255
+ recordWithRuntimeEventsCount: number;
1256
+ runtimeRunCount: number;
1257
+ lifecycleEventCount: number;
1258
+ defaultedSplitCount: number;
1259
+ }
1260
+ interface RuntimeTrajectoryEvidenceProjection {
1261
+ runs: RuntimeTrajectoryRunRecord[];
1262
+ events: RuntimeTrajectoryHookEvent[];
1263
+ summary: RuntimeTrajectoryEvidenceSummary;
1264
+ diagnostics: string[];
1265
+ }
1266
+ interface ProjectRuntimeTrajectoryEvidenceOptions<TRecord extends RuntimeTrajectoryRecord = RuntimeTrajectoryRecord> {
1267
+ records: TRecord[];
1268
+ defaultSplitTag?: RunSplitTag;
1269
+ recordIdOf?: (record: TRecord, index: number) => string | undefined;
1270
+ scenarioIdOf?: (record: TRecord, index: number) => string | undefined;
1271
+ }
1272
+
577
1273
  type RuntimeBenchmarkTrajectoryRecord = RuntimeTrajectoryRecord & {
578
1274
  benchmark?: unknown;
579
1275
  condition?: unknown;