@tangle-network/agent-eval 0.120.2 → 0.120.3

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 (171) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/analyst/index.d.ts +3111 -0
  3. package/dist/analyst/index.js +403 -0
  4. package/dist/analyst/index.js.map +1 -0
  5. package/dist/authenticity/index.d.ts +161 -0
  6. package/dist/authenticity/index.js +215 -0
  7. package/dist/authenticity/index.js.map +1 -0
  8. package/dist/belief-state/index.d.ts +1301 -0
  9. package/dist/belief-state/index.js +2152 -0
  10. package/dist/belief-state/index.js.map +1 -0
  11. package/dist/benchmarks/index.d.ts +974 -0
  12. package/dist/benchmarks/index.js +60 -0
  13. package/dist/benchmarks/index.js.map +1 -0
  14. package/dist/builder-eval/index.d.ts +695 -0
  15. package/dist/builder-eval/index.js +366 -0
  16. package/dist/builder-eval/index.js.map +1 -0
  17. package/dist/campaign/index.d.ts +7454 -0
  18. package/dist/campaign/index.js +272 -0
  19. package/dist/campaign/index.js.map +1 -0
  20. package/dist/chunk-3CDFMEMO.js +3878 -0
  21. package/dist/chunk-3CDFMEMO.js.map +1 -0
  22. package/dist/chunk-3RF76KTD.js +84 -0
  23. package/dist/chunk-3RF76KTD.js.map +1 -0
  24. package/dist/chunk-3XH4Y2SS.js +750 -0
  25. package/dist/chunk-3XH4Y2SS.js.map +1 -0
  26. package/dist/chunk-3YYRZDON.js +45 -0
  27. package/dist/chunk-3YYRZDON.js.map +1 -0
  28. package/dist/chunk-5BYTIDZ7.js +550 -0
  29. package/dist/chunk-5BYTIDZ7.js.map +1 -0
  30. package/dist/chunk-5CVUPHJ4.js +2668 -0
  31. package/dist/chunk-5CVUPHJ4.js.map +1 -0
  32. package/dist/chunk-ARU2PZFM.js +312 -0
  33. package/dist/chunk-ARU2PZFM.js.map +1 -0
  34. package/dist/chunk-BOD4O7OF.js +40 -0
  35. package/dist/chunk-BOD4O7OF.js.map +1 -0
  36. package/dist/chunk-CVJP5TMD.js +766 -0
  37. package/dist/chunk-CVJP5TMD.js.map +1 -0
  38. package/dist/chunk-DPZAEKA6.js +880 -0
  39. package/dist/chunk-DPZAEKA6.js.map +1 -0
  40. package/dist/chunk-DTJ6QUQB.js +131 -0
  41. package/dist/chunk-DTJ6QUQB.js.map +1 -0
  42. package/dist/chunk-GGE4NNQT.js +65 -0
  43. package/dist/chunk-GGE4NNQT.js.map +1 -0
  44. package/dist/chunk-H5UD2323.js +286 -0
  45. package/dist/chunk-H5UD2323.js.map +1 -0
  46. package/dist/chunk-HHWE3POT.js +94 -0
  47. package/dist/chunk-HHWE3POT.js.map +1 -0
  48. package/dist/chunk-HKUCJ437.js +787 -0
  49. package/dist/chunk-HKUCJ437.js.map +1 -0
  50. package/dist/chunk-JHCHEVET.js +274 -0
  51. package/dist/chunk-JHCHEVET.js.map +1 -0
  52. package/dist/chunk-K4DBDHLK.js +158 -0
  53. package/dist/chunk-K4DBDHLK.js.map +1 -0
  54. package/dist/chunk-K6N6XJJX.js +306 -0
  55. package/dist/chunk-K6N6XJJX.js.map +1 -0
  56. package/dist/chunk-MA6HLL3S.js +65 -0
  57. package/dist/chunk-MA6HLL3S.js.map +1 -0
  58. package/dist/chunk-MAZ26DC7.js +99 -0
  59. package/dist/chunk-MAZ26DC7.js.map +1 -0
  60. package/dist/chunk-MOXWMGPC.js +577 -0
  61. package/dist/chunk-MOXWMGPC.js.map +1 -0
  62. package/dist/chunk-NJC7U437.js +626 -0
  63. package/dist/chunk-NJC7U437.js.map +1 -0
  64. package/dist/chunk-NMN4WGSJ.js +1030 -0
  65. package/dist/chunk-NMN4WGSJ.js.map +1 -0
  66. package/dist/chunk-NPCTHQIO.js +91 -0
  67. package/dist/chunk-NPCTHQIO.js.map +1 -0
  68. package/dist/chunk-ONWEPEDO.js +57 -0
  69. package/dist/chunk-ONWEPEDO.js.map +1 -0
  70. package/dist/chunk-OYZAPX5G.js +1526 -0
  71. package/dist/chunk-OYZAPX5G.js.map +1 -0
  72. package/dist/chunk-P5MGQ2FY.js +7958 -0
  73. package/dist/chunk-P5MGQ2FY.js.map +1 -0
  74. package/dist/chunk-PC4UYEBM.js +166 -0
  75. package/dist/chunk-PC4UYEBM.js.map +1 -0
  76. package/dist/chunk-PJQFMIOX.js +1182 -0
  77. package/dist/chunk-PJQFMIOX.js.map +1 -0
  78. package/dist/chunk-PXD6ZFNY.js +1107 -0
  79. package/dist/chunk-PXD6ZFNY.js.map +1 -0
  80. package/dist/chunk-PXE2VKMX.js +140 -0
  81. package/dist/chunk-PXE2VKMX.js.map +1 -0
  82. package/dist/chunk-PZ5AY32C.js +10 -0
  83. package/dist/chunk-PZ5AY32C.js.map +1 -0
  84. package/dist/chunk-QBRSJK47.js +622 -0
  85. package/dist/chunk-QBRSJK47.js.map +1 -0
  86. package/dist/chunk-S3UZOQ5Y.js +328 -0
  87. package/dist/chunk-S3UZOQ5Y.js.map +1 -0
  88. package/dist/chunk-SQQED7ZH.js +998 -0
  89. package/dist/chunk-SQQED7ZH.js.map +1 -0
  90. package/dist/chunk-SYV364BL.js +1266 -0
  91. package/dist/chunk-SYV364BL.js.map +1 -0
  92. package/dist/chunk-T4SQEITX.js +95 -0
  93. package/dist/chunk-T4SQEITX.js.map +1 -0
  94. package/dist/chunk-TT4KNT67.js +124 -0
  95. package/dist/chunk-TT4KNT67.js.map +1 -0
  96. package/dist/chunk-U5CHZ5M3.js +357 -0
  97. package/dist/chunk-U5CHZ5M3.js.map +1 -0
  98. package/dist/chunk-ULOKLHIQ.js +1937 -0
  99. package/dist/chunk-ULOKLHIQ.js.map +1 -0
  100. package/dist/chunk-VI2UW6B6.js +162 -0
  101. package/dist/chunk-VI2UW6B6.js.map +1 -0
  102. package/dist/chunk-VQMK5FMP.js +247 -0
  103. package/dist/chunk-VQMK5FMP.js.map +1 -0
  104. package/dist/chunk-VSMTAMNK.js +53 -0
  105. package/dist/chunk-VSMTAMNK.js.map +1 -0
  106. package/dist/chunk-VZSRQ272.js +149 -0
  107. package/dist/chunk-VZSRQ272.js.map +1 -0
  108. package/dist/chunk-WW2A73HW.js +159 -0
  109. package/dist/chunk-WW2A73HW.js.map +1 -0
  110. package/dist/chunk-X4UCIOTZ.js +136 -0
  111. package/dist/chunk-X4UCIOTZ.js.map +1 -0
  112. package/dist/chunk-XJYR7XFV.js +317 -0
  113. package/dist/chunk-XJYR7XFV.js.map +1 -0
  114. package/dist/chunk-ZET2UAYW.js +89 -0
  115. package/dist/chunk-ZET2UAYW.js.map +1 -0
  116. package/dist/chunk-ZMXDQ4K7.js +870 -0
  117. package/dist/chunk-ZMXDQ4K7.js.map +1 -0
  118. package/dist/chunk-ZZUXHH3R.js +99 -0
  119. package/dist/chunk-ZZUXHH3R.js.map +1 -0
  120. package/dist/cli.d.ts +1 -0
  121. package/dist/cli.js +112 -0
  122. package/dist/cli.js.map +1 -0
  123. package/dist/contract/index.d.ts +4972 -0
  124. package/dist/contract/index.js +1654 -0
  125. package/dist/contract/index.js.map +1 -0
  126. package/dist/control.d.ts +1013 -0
  127. package/dist/control.js +34 -0
  128. package/dist/control.js.map +1 -0
  129. package/dist/fuzz.d.ts +759 -0
  130. package/dist/fuzz.js +714 -0
  131. package/dist/fuzz.js.map +1 -0
  132. package/dist/hosted/index.d.ts +730 -0
  133. package/dist/hosted/index.js +14 -0
  134. package/dist/hosted/index.js.map +1 -0
  135. package/dist/index.d.ts +16780 -0
  136. package/dist/index.js +12168 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/matrix/index.d.ts +155 -0
  139. package/dist/matrix/index.js +8 -0
  140. package/dist/matrix/index.js.map +1 -0
  141. package/dist/meta-eval/index.d.ts +1030 -0
  142. package/dist/meta-eval/index.js +417 -0
  143. package/dist/meta-eval/index.js.map +1 -0
  144. package/dist/multishot/index.d.ts +579 -0
  145. package/dist/multishot/index.js +589 -0
  146. package/dist/multishot/index.js.map +1 -0
  147. package/dist/openapi.json +992 -0
  148. package/dist/pipelines/index.d.ts +567 -0
  149. package/dist/pipelines/index.js +515 -0
  150. package/dist/pipelines/index.js.map +1 -0
  151. package/dist/reporting.d.ts +1277 -0
  152. package/dist/reporting.js +48 -0
  153. package/dist/reporting.js.map +1 -0
  154. package/dist/rl.d.ts +4092 -0
  155. package/dist/rl.js +1724 -0
  156. package/dist/rl.js.map +1 -0
  157. package/dist/run-campaign-75RTPVV5.js +14 -0
  158. package/dist/run-campaign-75RTPVV5.js.map +1 -0
  159. package/dist/storyboard/index.d.ts +279 -0
  160. package/dist/storyboard/index.js +767 -0
  161. package/dist/storyboard/index.js.map +1 -0
  162. package/dist/trace-attributes.d.ts +52 -0
  163. package/dist/trace-attributes.js +62 -0
  164. package/dist/trace-attributes.js.map +1 -0
  165. package/dist/traces.d.ts +2343 -0
  166. package/dist/traces.js +249 -0
  167. package/dist/traces.js.map +1 -0
  168. package/dist/wire/index.d.ts +1252 -0
  169. package/dist/wire/index.js +81 -0
  170. package/dist/wire/index.js.map +1 -0
  171. package/package.json +1 -1
@@ -0,0 +1,567 @@
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 {
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;
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
+ * BudgetBreachView — aggregates breach events across the corpus.
236
+ *
237
+ * Answers: which dimensions get hit most often? Which scenarios are
238
+ * underbudgeted? Which variants trigger the most breaches?
239
+ */
240
+
241
+ interface BudgetBreachFinding {
242
+ runId: string;
243
+ scenarioId: string;
244
+ variantId?: string;
245
+ dimension: keyof BudgetSpec;
246
+ limit: number;
247
+ consumed: number;
248
+ excessRatio: number;
249
+ timestamp: number;
250
+ }
251
+ interface BudgetBreachReport {
252
+ findings: BudgetBreachFinding[];
253
+ byDimension: Record<string, number>;
254
+ byScenario: Record<string, number>;
255
+ byVariant: Record<string, number>;
256
+ totalRuns: number;
257
+ breachedRunRatio: number;
258
+ }
259
+ declare function budgetBreachView(store: TraceStore, options?: {
260
+ scenarioId?: string;
261
+ variantId?: string;
262
+ }): Promise<BudgetBreachReport>;
263
+
264
+ /**
265
+ * Failure taxonomy — canonical classes + a default classifier.
266
+ *
267
+ * Every failed run should end up in a named class. The classifier here
268
+ * is rule-based (fast, deterministic); an LLM fallback can be added by
269
+ * the consumer for novel cases and trained into the rule base over time.
270
+ *
271
+ * Consumers call `classifyFailure(run, spans, events)` and persist the
272
+ * returned class as `Run.outcome.failureClass`.
273
+ */
274
+
275
+ interface FailureContext {
276
+ run: Run;
277
+ spans: Span[];
278
+ events: TraceEvent[];
279
+ }
280
+ /** Ordered rules — first match wins. */
281
+ interface FailureRule {
282
+ id: string;
283
+ match: (ctx: FailureContext) => {
284
+ failureClass: FailureClass;
285
+ reason: string;
286
+ triggerSpanId?: string;
287
+ triggerEventId?: string;
288
+ } | null;
289
+ }
290
+
291
+ /**
292
+ * FailureClusterView — groups failed runs by (failureClass, triggerTool,
293
+ * argHash-prefix) so weekly reviews can prioritize the top-N clusters.
294
+ *
295
+ * Each cluster includes: N runs, scenarios affected, representative
296
+ * error message, a proposed mitigation hint (rule → action table).
297
+ */
298
+
299
+ interface FailureCluster {
300
+ failureClass: FailureClass;
301
+ /** Tool name when the trigger was a tool span, else undefined. */
302
+ toolName?: string;
303
+ /** First 16 chars of argHash — clusters similar args. */
304
+ argPrefix?: string;
305
+ /**
306
+ * Source dimension when the trigger was a judge span (e.g. `'format'`,
307
+ * `'safety'`, `'correctness'`). Lets cross-template aggregators
308
+ * group failures by the dimension that fired without overloading
309
+ * `argPrefix`. Optional — clusters without this field deserialize cleanly.
310
+ */
311
+ dimension?: string;
312
+ runCount: number;
313
+ scenarioIds: string[];
314
+ exampleError?: string;
315
+ exampleRunId: string;
316
+ }
317
+ interface FailureClusterReport {
318
+ clusters: FailureCluster[];
319
+ totalFailures: number;
320
+ totalRuns: number;
321
+ }
322
+ declare function failureClusterView(store: TraceStore, options?: {
323
+ rules?: FailureRule[];
324
+ minClusterSize?: number;
325
+ }): Promise<FailureClusterReport>;
326
+
327
+ /**
328
+ * Trajectory — ordered, structured view over a run's spans.
329
+ *
330
+ * A pure function `buildTrajectory(store, runId) → Trajectory` returns
331
+ * a topologically ordered list of `TrajectoryStep` with parent-child
332
+ * grouping collapsed into a single line-of-agent-work. Separate
333
+ * analyzers (stuck-loop detection, waste ratio) live in
334
+ * `pipelines/` and consume the trajectory.
335
+ */
336
+
337
+ interface TrajectoryStep {
338
+ index: number;
339
+ span: Span;
340
+ /** Depth in the span tree from the root. 0 = top-level. */
341
+ depth: number;
342
+ /** Events attached to this span. */
343
+ events: TraceEvent[];
344
+ }
345
+
346
+ /**
347
+ * FirstDivergenceView — aligns two trajectories by step index, reports
348
+ * the first step where they differ.
349
+ *
350
+ * "Differ" is configurable — default is (kind, toolName if tool, model
351
+ * if llm). Use this view to attribute "why is variant B better?" to a
352
+ * specific step rather than an aggregate mean delta.
353
+ */
354
+
355
+ interface DivergenceReport {
356
+ runA: string;
357
+ runB: string;
358
+ firstDivergenceIndex: number | null;
359
+ aStep?: TrajectoryStep;
360
+ bStep?: TrajectoryStep;
361
+ reason?: string;
362
+ /** Common prefix length (steps that matched). */
363
+ commonPrefixLen: number;
364
+ }
365
+ interface DivergenceOptions {
366
+ /** Returns true if two steps are considered equal. Default: kind + tool/model match. */
367
+ stepEquals?: (a: TrajectoryStep, b: TrajectoryStep) => boolean;
368
+ }
369
+ declare function firstDivergenceView(store: TraceStore, runA: string, runB: string, options?: DivergenceOptions): Promise<DivergenceReport>;
370
+
371
+ /**
372
+ * JudgeAgreementView — pairwise agreement between judges across the
373
+ * corpus, grouped by dimension.
374
+ *
375
+ * Output drives two workflows:
376
+ * - Judge robustness audit: "does Claude agree with GPT at κ ≥ 0.6?"
377
+ * - Calibration tracking: κ vs golden human labels over time (by
378
+ * providing a `humanGoldenJudgeId`).
379
+ */
380
+
381
+ interface JudgePair {
382
+ judgeA: string;
383
+ judgeB: string;
384
+ dimension: string;
385
+ /** Number of (targetSpanId, dimension) tuples both judges scored. */
386
+ commonItems: number;
387
+ pearson: number;
388
+ krippendorff: number;
389
+ }
390
+ interface JudgeAgreementReport {
391
+ pairs: JudgePair[];
392
+ dimensions: string[];
393
+ judgeIds: string[];
394
+ }
395
+ declare function judgeAgreementView(store: TraceStore): Promise<JudgeAgreementReport>;
396
+
397
+ interface MetricVerdict {
398
+ metric: string;
399
+ baselineMean: number;
400
+ candidateMean: number;
401
+ delta: number;
402
+ cohensD: number;
403
+ welchT: number;
404
+ welchDf: number;
405
+ welchP: number;
406
+ stable: boolean;
407
+ /** IQR of the combined samples — used as a rough stability indicator. */
408
+ iqr: number;
409
+ verdict: 'improved' | 'regressed' | 'stable' | 'unstable';
410
+ }
411
+ interface BaselineReport {
412
+ metrics: MetricVerdict[];
413
+ /** True if any critical metric regressed. */
414
+ hasRegression: boolean;
415
+ /** True if any metric is unstable (too noisy to judge). */
416
+ hasUnstable: boolean;
417
+ }
418
+ interface BaselineOptions {
419
+ /** Effect size threshold for meaningful delta (default 0.5 — medium effect). */
420
+ effectThreshold?: number;
421
+ /** p-value threshold for statistical significance (default 0.05). */
422
+ alpha?: number;
423
+ /** IQR/mean ratio above which samples are flagged unstable (default 0.30). */
424
+ unstableCvThreshold?: number;
425
+ }
426
+
427
+ /**
428
+ * RegressionView — compares a candidate slice to a baseline slice on a
429
+ * named metric. Delegates the statistics (Welch's t-test, Cohen's d,
430
+ * IQR stability) to `baseline.ts`.
431
+ *
432
+ * This is the entry point for CI regression gates: "given runs tagged
433
+ * release=A and release=B, did any metric regress?"
434
+ */
435
+
436
+ interface RegressionSpec {
437
+ metric: string;
438
+ higherIsBetter: boolean;
439
+ /** Extract a scalar from a run. Default extractors handle common metrics. */
440
+ extract?: (run: Run, store: TraceStore) => Promise<number | null>;
441
+ }
442
+ interface RegressionOptions extends BaselineOptions {
443
+ baseline: RunFilter;
444
+ candidate: RunFilter;
445
+ }
446
+ declare function regressionView(store: TraceStore, metrics: RegressionSpec[], options: RegressionOptions): Promise<BaselineReport>;
447
+
448
+ /**
449
+ * StuckLoopView — detects when an agent calls the same tool with the
450
+ * same (or structurally similar) arguments ≥ N times in a short window.
451
+ *
452
+ * Rationale: agents that loop are the number-one production failure
453
+ * mode on long-horizon flows. The view returns (runId, toolName,
454
+ * argHash, occurrences, windowMs) for each detected loop plus a
455
+ * fraction of runs affected.
456
+ */
457
+
458
+ interface StuckLoopFinding {
459
+ runId: string;
460
+ toolName: string;
461
+ argHash: string;
462
+ /** Calls in this episode's densest qualifying interval, not the whole-run total. */
463
+ occurrences: number;
464
+ spanIds: string[];
465
+ /** Nearest agent ancestor, or the direct parent when ancestry is incomplete. */
466
+ scopeSpanId?: string;
467
+ /** Milliseconds between first and last call in the loop. */
468
+ windowMs: number;
469
+ }
470
+ interface StuckLoopReport {
471
+ findings: StuckLoopFinding[];
472
+ affectedRunRatio: number;
473
+ totalRuns: number;
474
+ }
475
+ interface StuckLoopOptions {
476
+ /** Minimum call count to flag a loop (default 3). */
477
+ minOccurrences?: number;
478
+ /** Maximum time between the first and last repeated call (default 60 seconds). */
479
+ maxWindowMs?: number;
480
+ /**
481
+ * Maximum other tool calls allowed between adjacent repeats (default 0).
482
+ * Set to 1 to detect alternating patterns such as A,B,A,B,A.
483
+ */
484
+ maxInterveningToolCalls?: number;
485
+ /** Filter to a specific runId; omit to scan the entire corpus. */
486
+ runId?: string;
487
+ }
488
+ declare function stuckLoopView(store: TraceStore, options?: StuckLoopOptions): Promise<StuckLoopReport>;
489
+
490
+ /**
491
+ * Tool-use metrics — derived purely from trace data.
492
+ *
493
+ * No scoring assumptions: consumers supply optional ground-truth tool
494
+ * selections per turn + optional "information used downstream" signals.
495
+ * Without those, we still compute descriptive metrics (error rate,
496
+ * retry rate, duplicate-call rate) that are useful on their own.
497
+ */
498
+
499
+ interface ToolUseMetrics {
500
+ runId: string;
501
+ totalCalls: number;
502
+ /** Calls whose arguments were captured and can be compared for duplication. */
503
+ callsWithCapturedArgs: number;
504
+ byTool: Record<string, ToolStats>;
505
+ errorRate: number;
506
+ /** Ratio of captured-argument calls already seen with the same tool name and arguments. */
507
+ duplicateRate: number;
508
+ /** Ratio of error calls followed by ≥1 retry on same tool. */
509
+ retryRate: number;
510
+ /** Optional: of the calls agent made, fraction the evaluator marked as "correct selection". */
511
+ selectionAccuracy?: number;
512
+ }
513
+ interface ToolStats {
514
+ calls: number;
515
+ callsWithCapturedArgs: number;
516
+ errors: number;
517
+ avgLatencyMs: number;
518
+ duplicates: number;
519
+ }
520
+ interface ToolUseOptions {
521
+ /** Map of spanId → whether the evaluator judged the tool selection correct. Optional. */
522
+ selectionLabels?: Record<string, boolean>;
523
+ }
524
+ declare function computeToolUseMetrics(store: TraceStore, runId: string, options?: ToolUseOptions): Promise<ToolUseMetrics>;
525
+
526
+ /**
527
+ * Typed query helpers over TraceStore.
528
+ *
529
+ * Not a full SQL engine — a minimal, composable set of operators that
530
+ * cover the canned-pipeline use cases. For ad-hoc analytics, persist to
531
+ * NDJSON and point DuckDB at it; the schema is stable so external SQL
532
+ * tooling works out of the box.
533
+ */
534
+
535
+ declare function llmSpans(store: TraceStore, runId?: string): Promise<LlmSpan[]>;
536
+
537
+ /**
538
+ * ToolWasteView — fraction of tool calls whose results weren't used
539
+ * downstream. Without a "used" signal we fall back to structural
540
+ * proxies: error calls, duplicate calls, and tool calls followed by
541
+ * zero subsequent LLM spans are all considered waste.
542
+ *
543
+ * Consumers can pass a `usageOracle` that inspects a tool span and
544
+ * returns true iff the tool's result appears in a later LLM message,
545
+ * artifact, or state mutation — that's the canonical definition; the
546
+ * default heuristic is a reasonable fallback.
547
+ */
548
+
549
+ interface ToolWasteFinding {
550
+ runId: string;
551
+ wastedCalls: number;
552
+ totalCalls: number;
553
+ wasteRate: number;
554
+ }
555
+ interface ToolWasteReport {
556
+ byRun: ToolWasteFinding[];
557
+ overallWasteRate: number;
558
+ }
559
+ interface ToolWasteOptions {
560
+ runId?: string;
561
+ usageOracle?: (tool: ToolSpan, later: {
562
+ llm: Awaited<ReturnType<typeof llmSpans>>;
563
+ }) => boolean;
564
+ }
565
+ declare function toolWasteView(store: TraceStore, options?: ToolWasteOptions): Promise<ToolWasteReport>;
566
+
567
+ export { type BudgetBreachFinding, type BudgetBreachReport, type DivergenceOptions, type DivergenceReport, type FailureCluster, type FailureClusterReport, type JudgeAgreementReport, type JudgePair, type RegressionOptions, type RegressionSpec, type StuckLoopFinding, type StuckLoopOptions, type StuckLoopReport, type ToolWasteFinding, type ToolWasteOptions, type ToolWasteReport, budgetBreachView, computeToolUseMetrics, failureClusterView, firstDivergenceView, judgeAgreementView, regressionView, stuckLoopView, toolWasteView };