@tangle-network/agent-eval 0.120.2 → 0.120.4

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 (172) hide show
  1. package/CHANGELOG.md +13 -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 +7469 -0
  18. package/dist/campaign/index.js +272 -0
  19. package/dist/campaign/index.js.map +1 -0
  20. package/dist/chunk-3RF76KTD.js +84 -0
  21. package/dist/chunk-3RF76KTD.js.map +1 -0
  22. package/dist/chunk-3XH4Y2SS.js +750 -0
  23. package/dist/chunk-3XH4Y2SS.js.map +1 -0
  24. package/dist/chunk-3YYRZDON.js +45 -0
  25. package/dist/chunk-3YYRZDON.js.map +1 -0
  26. package/dist/chunk-5BYTIDZ7.js +550 -0
  27. package/dist/chunk-5BYTIDZ7.js.map +1 -0
  28. package/dist/chunk-5CVUPHJ4.js +2668 -0
  29. package/dist/chunk-5CVUPHJ4.js.map +1 -0
  30. package/dist/chunk-7QBFOJ3E.js +3920 -0
  31. package/dist/chunk-7QBFOJ3E.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-PC4UYEBM.js +166 -0
  73. package/dist/chunk-PC4UYEBM.js.map +1 -0
  74. package/dist/chunk-PJQFMIOX.js +1182 -0
  75. package/dist/chunk-PJQFMIOX.js.map +1 -0
  76. package/dist/chunk-PXD6ZFNY.js +1107 -0
  77. package/dist/chunk-PXD6ZFNY.js.map +1 -0
  78. package/dist/chunk-PXE2VKMX.js +140 -0
  79. package/dist/chunk-PXE2VKMX.js.map +1 -0
  80. package/dist/chunk-PZ5AY32C.js +10 -0
  81. package/dist/chunk-PZ5AY32C.js.map +1 -0
  82. package/dist/chunk-QBRSJK47.js +622 -0
  83. package/dist/chunk-QBRSJK47.js.map +1 -0
  84. package/dist/chunk-S3UZOQ5Y.js +328 -0
  85. package/dist/chunk-S3UZOQ5Y.js.map +1 -0
  86. package/dist/chunk-SQQED7ZH.js +998 -0
  87. package/dist/chunk-SQQED7ZH.js.map +1 -0
  88. package/dist/chunk-SYV364BL.js +1266 -0
  89. package/dist/chunk-SYV364BL.js.map +1 -0
  90. package/dist/chunk-T4SQEITX.js +95 -0
  91. package/dist/chunk-T4SQEITX.js.map +1 -0
  92. package/dist/chunk-TT4KNT67.js +124 -0
  93. package/dist/chunk-TT4KNT67.js.map +1 -0
  94. package/dist/chunk-U5CHZ5M3.js +357 -0
  95. package/dist/chunk-U5CHZ5M3.js.map +1 -0
  96. package/dist/chunk-ULOKLHIQ.js +1937 -0
  97. package/dist/chunk-ULOKLHIQ.js.map +1 -0
  98. package/dist/chunk-VI2UW6B6.js +162 -0
  99. package/dist/chunk-VI2UW6B6.js.map +1 -0
  100. package/dist/chunk-VQMK5FMP.js +247 -0
  101. package/dist/chunk-VQMK5FMP.js.map +1 -0
  102. package/dist/chunk-VSMTAMNK.js +53 -0
  103. package/dist/chunk-VSMTAMNK.js.map +1 -0
  104. package/dist/chunk-VZSRQ272.js +149 -0
  105. package/dist/chunk-VZSRQ272.js.map +1 -0
  106. package/dist/chunk-WW2A73HW.js +159 -0
  107. package/dist/chunk-WW2A73HW.js.map +1 -0
  108. package/dist/chunk-X4UCIOTZ.js +136 -0
  109. package/dist/chunk-X4UCIOTZ.js.map +1 -0
  110. package/dist/chunk-XJYR7XFV.js +317 -0
  111. package/dist/chunk-XJYR7XFV.js.map +1 -0
  112. package/dist/chunk-ZET2UAYW.js +89 -0
  113. package/dist/chunk-ZET2UAYW.js.map +1 -0
  114. package/dist/chunk-ZMXDQ4K7.js +870 -0
  115. package/dist/chunk-ZMXDQ4K7.js.map +1 -0
  116. package/dist/chunk-ZTJPIIVI.js +7958 -0
  117. package/dist/chunk-ZTJPIIVI.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 +4987 -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/docs/eval-surface-map.md +1 -1
  172. package/package.json +1 -1
@@ -0,0 +1,695 @@
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
+ * TraceEmitter — hierarchical span builder that auto-parents using an
236
+ * internal stack. One emitter per Run; emitters do NOT share state.
237
+ *
238
+ * Convenience methods (`llm`, `tool`, `retrieval`, `judge`, `sandbox`)
239
+ * return a `SpanHandle` with `.end()` / `.fail()` so callers don't
240
+ * have to thread spanIds manually. For async workflows that can't use
241
+ * the stack (e.g. fan-out parallel calls), pass `parentSpanId`
242
+ * explicitly.
243
+ */
244
+
245
+ interface SpanHandle<S extends Span = Span> {
246
+ span: S;
247
+ end(patch?: Partial<S>): Promise<void>;
248
+ fail(error: string | Error, patch?: Partial<S>): Promise<void>;
249
+ }
250
+ interface RunCompleteHookContext {
251
+ runId: string;
252
+ emitter: TraceEmitter;
253
+ store: TraceStore;
254
+ /** Outcome the caller passed to `endRun` (undefined for `abortRun`). */
255
+ outcome?: RunOutcome;
256
+ /** Final run status. */
257
+ status: 'completed' | 'failed' | 'aborted';
258
+ }
259
+ type RunCompleteHook = (ctx: RunCompleteHookContext) => Promise<void> | void;
260
+ interface TraceEmitterOptions {
261
+ runId?: string;
262
+ /** Inject a clock for deterministic tests. */
263
+ now?: () => number;
264
+ /** Inject an id generator for deterministic tests. */
265
+ id?: () => string;
266
+ /**
267
+ * Hooks fired after `endRun` / `abortRun` writes the final run state.
268
+ * Designed for trace-analyst auto-execution, integrity assertions, and
269
+ * outbound notifications. Hooks run sequentially in the order supplied.
270
+ *
271
+ * By default a hook that throws is swallowed and logged as a `note` event
272
+ * on the run — auto-orchestration must not crash the underlying flow.
273
+ * Set `hookErrors: 'throw'` to propagate.
274
+ */
275
+ onRunComplete?: RunCompleteHook[];
276
+ /** `'swallow'` (default) | `'throw'`. */
277
+ hookErrors?: 'swallow' | 'throw';
278
+ }
279
+ declare class TraceEmitter {
280
+ private store;
281
+ private stack;
282
+ private _runId;
283
+ private now;
284
+ private id;
285
+ private hooks;
286
+ private hookErrors;
287
+ constructor(store: TraceStore, options?: TraceEmitterOptions);
288
+ get runId(): string;
289
+ get traceStore(): TraceStore;
290
+ /** Append a hook after construction (e.g. attach the trace analyst). */
291
+ addRunCompleteHook(hook: RunCompleteHook): void;
292
+ /**
293
+ * Begin a Run.
294
+ *
295
+ * `scenarioId` is required on the persisted Run shape — every Run downstream
296
+ * gets a non-empty scenarioId so filters and aggregations stay simple — but
297
+ * the INPUT here accepts it as optional. When omitted, startRun substitutes
298
+ * a sensible default (`run.layer ?? run.tags?.['kind'] ?? 'runtime'`) so
299
+ * runtime / operator / meta-eval runs that have no curated-scenario corpus
300
+ * to anchor to don't have to invent placeholder strings at the call site.
301
+ */
302
+ startRun(run: Omit<Run, 'runId' | 'scenarioId' | 'startedAt' | 'status'> & {
303
+ scenarioId?: string;
304
+ }): Promise<Run>;
305
+ endRun(outcome?: RunOutcome): Promise<void>;
306
+ abortRun(reason: string): Promise<void>;
307
+ private runHooks;
308
+ span<S extends Span = Span>(init: {
309
+ kind: SpanKind;
310
+ name: string;
311
+ parentSpanId?: string;
312
+ attributes?: Record<string, unknown>;
313
+ } & Partial<Omit<S, 'spanId' | 'runId' | 'startedAt' | 'kind' | 'name'>>): Promise<SpanHandle<S>>;
314
+ private handle;
315
+ private pop;
316
+ llm(init: Omit<LlmSpan, 'spanId' | 'runId' | 'kind' | 'startedAt'>): Promise<SpanHandle<LlmSpan>>;
317
+ tool(init: Omit<ToolSpan, 'spanId' | 'runId' | 'kind' | 'startedAt'>): Promise<SpanHandle<ToolSpan>>;
318
+ retrieval(init: Omit<RetrievalSpan, 'spanId' | 'runId' | 'kind' | 'startedAt'>): Promise<SpanHandle<RetrievalSpan>>;
319
+ recordJudge(verdict: Omit<JudgeSpan, 'spanId' | 'runId' | 'kind' | 'startedAt' | 'endedAt'>): Promise<JudgeSpan>;
320
+ sandbox(init: Omit<SandboxSpan, 'spanId' | 'runId' | 'kind' | 'startedAt'>): Promise<SpanHandle<SandboxSpan>>;
321
+ emit(event: {
322
+ kind: EventKind;
323
+ spanId?: string;
324
+ payload?: Record<string, unknown>;
325
+ }): Promise<TraceEvent>;
326
+ recordBudget(entry: Omit<BudgetLedgerEntry, 'runId' | 'timestamp'> & {
327
+ timestamp?: number;
328
+ }): Promise<BudgetLedgerEntry>;
329
+ recordArtifact(artifact: Omit<Artifact, 'artifactId' | 'runId'>): Promise<Artifact>;
330
+ /**
331
+ * Runs `fn` inside a span; auto-ends on success, auto-fails on throw.
332
+ * Returns the fn's return value. Use this for the 95% case.
333
+ */
334
+ within<T>(init: Parameters<TraceEmitter['span']>[0], fn: (handle: SpanHandle) => Promise<T>): Promise<T>;
335
+ }
336
+
337
+ /**
338
+ * SandboxHarness — executes a scenario in an isolated environment and
339
+ * emits a rich SandboxSpan into the trace.
340
+ *
341
+ * Two built-in drivers:
342
+ * - `SubprocessSandboxDriver` — spawn in a local cwd with env vars.
343
+ * Fast, no dependencies, fine for unit tests and most CI gates.
344
+ * - `DockerSandboxDriver` — lifted from tangle-router's sandbox path;
345
+ * shells out to `docker run`. Stronger isolation, slower startup.
346
+ *
347
+ * Consumers implement `SandboxDriver` for custom backends (Firecracker,
348
+ * Cloudflare sandbox product, etc.). The harness doesn't care which.
349
+ */
350
+
351
+ interface HarnessConfig {
352
+ /** Setup command (e.g. "pnpm install"). Non-zero exit fails the run. */
353
+ setupCommand?: string;
354
+ /** Run command (e.g. "pnpm build"). */
355
+ runCommand?: string;
356
+ /** Test command (e.g. "pnpm test --run"). Drives the test count + pass count. */
357
+ testCommand?: string;
358
+ /** Absolute cwd for the subprocess driver. Ignored by docker driver. */
359
+ cwd?: string;
360
+ /** Max wall-clock per phase in ms. Default 10 minutes. */
361
+ timeoutMs?: number;
362
+ /**
363
+ * Cap on captured stdout+stderr bytes per phase. A runaway process can
364
+ * otherwise grow the in-memory buffer without bound. Once hit, further
365
+ * output is dropped and `outputTruncated` is set. Default 16 MiB.
366
+ */
367
+ maxOutputBytes?: number;
368
+ /** Image for the docker driver. */
369
+ image?: string;
370
+ /** Extra env vars (validated; shell-escaped). */
371
+ env?: Record<string, string>;
372
+ /** Parser for the test output — maps stdout/stderr/exit code → pass count. */
373
+ testParser?: TestOutputParser;
374
+ }
375
+ interface TestOutputParser {
376
+ id: string;
377
+ parse(stdout: string, stderr: string, exitCode: number): {
378
+ testsTotal: number;
379
+ testsPassed: number;
380
+ } | undefined;
381
+ }
382
+ interface SandboxResult {
383
+ phase: 'setup' | 'run' | 'test';
384
+ exitCode: number;
385
+ stdout: string;
386
+ stderr: string;
387
+ wallMs: number;
388
+ testsTotal?: number;
389
+ testsPassed?: number;
390
+ /**
391
+ * True when the process was killed because it exceeded `timeoutMs`. A
392
+ * SIGKILLed child can still close with exit code 0; callers MUST treat
393
+ * a timed-out phase as a hard failure regardless of `exitCode`, never
394
+ * as a pass. `undefined`/`false` means the process completed on its own.
395
+ */
396
+ killedByTimeout?: boolean;
397
+ /**
398
+ * True when captured stdout/stderr hit `maxOutputBytes` and further
399
+ * output was dropped. The result is still returned (the process was
400
+ * not killed for this), but downstream parsers see truncated text.
401
+ */
402
+ outputTruncated?: boolean;
403
+ }
404
+ interface SandboxDriver {
405
+ id: string;
406
+ exec(phase: SandboxResult['phase'], command: string, config: HarnessConfig): Promise<SandboxResult>;
407
+ }
408
+ interface SandboxHarnessResult {
409
+ passed: boolean;
410
+ setup?: SandboxResult;
411
+ run?: SandboxResult;
412
+ test?: SandboxResult;
413
+ totalWallMs: number;
414
+ /** Final score — 0 when no tests; otherwise testsPassed/testsTotal. */
415
+ score: number;
416
+ }
417
+
418
+ /**
419
+ * TestGradedScenario — a scenario whose score comes from a test suite.
420
+ *
421
+ * This is the SWE-bench pattern generalized. The scenario ships:
422
+ * - fixture data (setup instructions)
423
+ * - a test command the harness runs
424
+ * - optional assertion overrides
425
+ *
426
+ * The runner emits a run, delegates to SandboxHarness, records the
427
+ * outcome, and returns a structured verdict. Consumers bind their own
428
+ * agent execution to this contract.
429
+ */
430
+
431
+ interface TestGradedScenario {
432
+ id: string;
433
+ description?: string;
434
+ harness: HarnessConfig;
435
+ /** Optional pass threshold in 0..1 (default 1.0 = all tests must pass). */
436
+ passThreshold?: number;
437
+ /** Provenance for dataset tracking. */
438
+ datasetVersion?: string;
439
+ /** Free-form tags (difficulty, category, etc.). */
440
+ tags?: Record<string, string>;
441
+ }
442
+ interface TestGradedRunResult {
443
+ runId: string;
444
+ scenario: TestGradedScenario;
445
+ harness: SandboxHarnessResult;
446
+ pass: boolean;
447
+ score: number;
448
+ failureClass?: FailureClass;
449
+ }
450
+
451
+ /**
452
+ * BuilderSession — ties a builder-of-builders workflow together.
453
+ *
454
+ * Models agent-builder's shape: Project → Chat → Edit → Ship → App →
455
+ * AppAgent. Each layer is a Run (linked via parentRunId). The
456
+ * framework-enforced invariants:
457
+ *
458
+ * - One Project → many Chats; chatId scopes runs within a project.
459
+ * - One Chat = one builder Run with `layer='builder'`.
460
+ * - One Ship = one child Run with `layer='app-build'` + SandboxHarness.
461
+ * - One AppScenario = one grandchild Run with `layer='app-runtime'`.
462
+ *
463
+ * Consumers obtain a BuilderSession, call `startChat`, drive the
464
+ * builder agent (emitting spans), and call `ship` / `runAppScenario`
465
+ * as the workflow progresses. The session reconstructs itself from
466
+ * trace data via `resume(store, projectId)`.
467
+ */
468
+
469
+ interface BuilderSessionInit {
470
+ projectId: string;
471
+ chatId?: string;
472
+ /** Free-form: user's task description, project name, etc. Stored on the builder Run. */
473
+ tags?: Record<string, string>;
474
+ }
475
+ interface ShipOptions {
476
+ harness: HarnessConfig;
477
+ driver?: SandboxDriver;
478
+ /** scenarioId of this app-build run. Defaults to `${projectId}/build`. */
479
+ scenarioId?: string;
480
+ }
481
+ interface RunAppScenarioOptions {
482
+ scenario: TestGradedScenario;
483
+ /** Harness driver override; defaults to the one the session was created with. */
484
+ driver?: SandboxDriver;
485
+ }
486
+ declare class BuilderSession {
487
+ private store;
488
+ private builderEmitter;
489
+ readonly projectId: string;
490
+ readonly chatId: string;
491
+ private builderRunId?;
492
+ private lastBuildRunId?;
493
+ private defaultDriver?;
494
+ constructor(store: TraceStore, init: BuilderSessionInit, driver?: SandboxDriver);
495
+ /** Start the builder (L0) run for this chat. Returns the runId. */
496
+ startChat(scenarioId?: string): Promise<string>;
497
+ /** The emitter for builder-level spans (edits, LLM calls, tool invocations). */
498
+ get emitter(): TraceEmitter;
499
+ /**
500
+ * Ship the project's generated app: run the sandbox harness as a child
501
+ * Run (`layer='app-build'`). Returns the build result + runId.
502
+ */
503
+ ship(options: ShipOptions): Promise<{
504
+ runId: string;
505
+ result: SandboxHarnessResult;
506
+ }>;
507
+ /**
508
+ * Run a domain scenario against the just-built app as a grandchild Run
509
+ * (`layer='app-runtime'`). The `ship` call must precede this so the
510
+ * parent is set correctly; if no build exists yet the session attaches
511
+ * directly to the builder run (useful for prototypes).
512
+ */
513
+ runAppScenario(options: RunAppScenarioOptions): Promise<TestGradedRunResult>;
514
+ /** Record an end-of-chat meta score (judge verdict on whether the builder
515
+ * served the user's intent). Accepts a numeric score + optional rationale. */
516
+ recordMetaScore(score: number, rationale?: string): Promise<void>;
517
+ /** Close the builder Run with a final outcome. */
518
+ endChat(outcome: {
519
+ pass: boolean;
520
+ score?: number;
521
+ notes?: string;
522
+ }): Promise<void>;
523
+ /**
524
+ * Inline app-runtime run — for cases where the "scenario" isn't a
525
+ * SWE-bench-style test suite but a live agent interaction (LLM chat,
526
+ * domain flow). Returns an emitter bound to a fresh Run in the
527
+ * `app-runtime` layer; caller emits spans inside and calls
528
+ * `.endRun()` with the final verdict.
529
+ */
530
+ startAppRuntime(scenarioId: string): Promise<TraceEmitter>;
531
+ /**
532
+ * Lightweight "ship marker" — record an app-build Run with a caller-
533
+ * provided verdict. Use when there isn't a sandbox harness to run but
534
+ * you still want to mark the build state at publish time.
535
+ */
536
+ recordShipMarker(args: {
537
+ pass: boolean;
538
+ score: number;
539
+ scenarioId?: string;
540
+ notes?: string;
541
+ }): Promise<string>;
542
+ get lastBuildRunIdValue(): string | undefined;
543
+ get builderRunIdValue(): string | undefined;
544
+ }
545
+ /**
546
+ * Reconstruct the most recent BuilderSession state for a given project —
547
+ * returns { builderRunId, lastBuildRunId, chatRuns }. For chat-first UIs
548
+ * this is how a resumed session finds its place in the edit history.
549
+ */
550
+ declare function resumeBuilderSession(store: TraceStore, projectId: string): Promise<{
551
+ projectId: string;
552
+ chatRuns: Run[];
553
+ lastBuilderRun?: Run;
554
+ lastBuildRun?: Run;
555
+ lastAppRuntimeRuns: Run[];
556
+ }>;
557
+
558
+ /**
559
+ * Three-layer evaluation — the canonical scoring breakdown for
560
+ * builder-of-builders workflows.
561
+ *
562
+ * meta_score: did the builder understand + satisfy user intent?
563
+ * (judge verdict attached to the builder run)
564
+ * build_score: did the generated scaffold build + pass its own tests?
565
+ * (outcome.score on the app-build child run)
566
+ * runtime_score: did the generated agent pass its domain scenarios?
567
+ * (mean outcome.score over app-runtime grandchild runs)
568
+ *
569
+ * Returns a structured report per project. The cross-layer correlation
570
+ * is the highest-leverage signal the framework computes — if
571
+ * meta_score doesn't predict runtime_score, the builder's self-scoring
572
+ * is broken.
573
+ *
574
+ * Scaffold-only mode: when a project has no `app-runtime` runs (e.g. a
575
+ * scaffold-builder eval that grades compose + build without driving a
576
+ * runtime scenario), `kind` is `'scaffold-only'` and `complete` measures
577
+ * meta + build only. Consumers can tell the two apart without having to
578
+ * interpret null-runtime as either "not yet computed" or "N/A for this
579
+ * project shape".
580
+ */
581
+
582
+ type ProjectKind = 'full' | 'scaffold-only';
583
+ interface ThreeLayerProjectReport {
584
+ projectId: string;
585
+ /**
586
+ * `'full'` when the project has at least one `app-runtime` run;
587
+ * `'scaffold-only'` when it only has meta + build layers. Lets
588
+ * downstream consumers treat a null runtime score as expected
589
+ * (scaffold-only) vs. missing (full, pipeline broke).
590
+ */
591
+ kind: ProjectKind;
592
+ builderRunId?: string;
593
+ /** Judge-verdict score on the builder run (0..1 after normalization). */
594
+ metaScore: number | null;
595
+ buildRunId?: string;
596
+ /** 0..1 from the sandbox harness (testsPassed / testsTotal). */
597
+ buildScore: number | null;
598
+ appRuntimeRunIds: string[];
599
+ /** Mean of outcome.score over app-runtime runs, 0..1. Always null in scaffold-only mode. */
600
+ runtimeScore: number | null;
601
+ runtimePassRate: number | null;
602
+ /**
603
+ * Layer-aware completeness:
604
+ * - `kind='full'`: all three layers scored
605
+ * - `kind='scaffold-only'`: meta + build scored (runtime not applicable)
606
+ */
607
+ complete: boolean;
608
+ }
609
+ declare function scoreProject(store: TraceStore, projectId: string): Promise<ThreeLayerProjectReport>;
610
+ /** Aggregate scoring across every project in a corpus. */
611
+ declare function scoreAllProjects(store: TraceStore): Promise<ThreeLayerProjectReport[]>;
612
+
613
+ /**
614
+ * Meta-eval correlation — the highest-leverage signal in the framework.
615
+ *
616
+ * Given a corpus of three-layer project reports, compute how well each
617
+ * pair of layers correlates. The question we care about most:
618
+ *
619
+ * Does `metaScore` (what the builder thinks it did) predict
620
+ * `runtimeScore` (what the user actually gets)?
621
+ *
622
+ * If r < ~0.4, the builder's self-scoring is broken — it's optimizing
623
+ * for something other than real-world success. If r > 0.7, meta_score
624
+ * is a usable proxy and can drive CI gates cheaply.
625
+ *
626
+ * Non-parametric rank correlation (Spearman) is also reported because
627
+ * meta scores are often ordinal-ish.
628
+ */
629
+
630
+ interface LayerCorrelation {
631
+ n: number;
632
+ pearson: number;
633
+ spearman: number;
634
+ }
635
+ interface CorrelationReport {
636
+ /** Pairs present in the corpus (layers with ≥ 2 matched data points). */
637
+ metaVsBuild?: LayerCorrelation;
638
+ metaVsRuntime?: LayerCorrelation;
639
+ buildVsRuntime?: LayerCorrelation;
640
+ /** Number of complete projects (all 3 scores present). */
641
+ completeProjects: number;
642
+ }
643
+ declare function correlateLayers(reports: ThreeLayerProjectReport[]): CorrelationReport;
644
+
645
+ /**
646
+ * ProjectRegistry — project-level aggregation over the trace corpus.
647
+ *
648
+ * Thin reader over TraceStore that answers the questions a chat-first,
649
+ * resumable UI needs:
650
+ * - listProjects() → project IDs with latest activity
651
+ * - projectTimeline(id) → chats + builds + runtime runs, chronological
652
+ * - projectChats(id) → chat-level summaries (turn count, outcome)
653
+ *
654
+ * All queries are pure reads; no state duplication.
655
+ */
656
+
657
+ interface ProjectSummary {
658
+ projectId: string;
659
+ chatCount: number;
660
+ buildCount: number;
661
+ appRuntimeCount: number;
662
+ lastActivityAt: number;
663
+ latestChatId?: string;
664
+ latestOutcome?: {
665
+ pass: boolean;
666
+ score?: number;
667
+ };
668
+ }
669
+ interface ChatSummary {
670
+ chatId: string;
671
+ projectId: string;
672
+ builderRunId: string;
673
+ startedAt: number;
674
+ endedAt?: number;
675
+ status: Run['status'];
676
+ outcome?: Run['outcome'];
677
+ /** Counts of spans emitted during the chat. */
678
+ llmTurns?: number;
679
+ toolCalls?: number;
680
+ buildRunId?: string;
681
+ appRuntimeRunIds: string[];
682
+ }
683
+ interface ProjectTimelineEntry {
684
+ run: Run;
685
+ layerBucket: 'chat' | 'build' | 'runtime' | 'other';
686
+ }
687
+ declare class ProjectRegistry {
688
+ private store;
689
+ constructor(store: TraceStore);
690
+ listProjects(): Promise<ProjectSummary[]>;
691
+ projectTimeline(projectId: string): Promise<ProjectTimelineEntry[]>;
692
+ projectChats(projectId: string): Promise<ChatSummary[]>;
693
+ }
694
+
695
+ export { BuilderSession, type BuilderSessionInit, type ChatSummary, type CorrelationReport, type LayerCorrelation, type ProjectKind, ProjectRegistry, type ProjectSummary, type ProjectTimelineEntry, type RunAppScenarioOptions, type ShipOptions, type ThreeLayerProjectReport, correlateLayers, resumeBuilderSession, scoreAllProjects, scoreProject };