@agent-inspect/jest 6.31.37 → 6.31.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +738 -0
- package/dist/index.d.ts +738 -0
- package/dist/index.mjs +465 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
declare const TRACE_ARTIFACT_MANIFEST_SCHEMA_VERSION: "0.1";
|
|
2
|
+
/** Experimental reporter framework identifier for local CI artifacts. */
|
|
3
|
+
type TraceReporterFramework = "vitest" | "jest" | "manual";
|
|
4
|
+
/** Experimental reporter test status normalized across supported test runners. */
|
|
5
|
+
type TraceTestStatus = "passed" | "failed" | "skipped" | "todo";
|
|
6
|
+
/** Experimental reporter artifact kind used in artifact manifests. */
|
|
7
|
+
type TraceArtifactKind = "trace" | "report" | "eval" | "redaction" | "summary" | "evidence";
|
|
8
|
+
/** Experimental reporter artifact file format used in artifact manifests. */
|
|
9
|
+
type TraceArtifactFormat = "json" | "jsonl" | "md" | "html";
|
|
10
|
+
/** Experimental redaction profile marker recorded with reporter artifacts. */
|
|
11
|
+
type TraceArtifactRedactionProfile = "local" | "share" | "strict";
|
|
12
|
+
/** Experimental reporter diagnostic severity. */
|
|
13
|
+
type TraceReporterDiagnosticSeverity = "info" | "warning" | "error";
|
|
14
|
+
/** Experimental reporter diagnostic code for safe, non-throwing reporter helpers. */
|
|
15
|
+
type TraceReporterDiagnosticCode = "invalid_artifact_path" | "artifact_path_escape" | "artifact_path_empty" | "artifact_path_absolute" | "reporter_failure";
|
|
16
|
+
/** Experimental diagnostic emitted by reporter helpers instead of throwing. */
|
|
17
|
+
interface TraceReporterDiagnostic {
|
|
18
|
+
code: TraceReporterDiagnosticCode;
|
|
19
|
+
severity: TraceReporterDiagnosticSeverity;
|
|
20
|
+
message: string;
|
|
21
|
+
target?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Experimental manifest artifact entry shared by framework reporters. */
|
|
24
|
+
interface TraceArtifact {
|
|
25
|
+
kind: TraceArtifactKind;
|
|
26
|
+
path: string;
|
|
27
|
+
format: TraceArtifactFormat;
|
|
28
|
+
redactionProfile: TraceArtifactRedactionProfile;
|
|
29
|
+
title?: string;
|
|
30
|
+
sizeBytes?: number;
|
|
31
|
+
diagnostics?: TraceReporterDiagnostic[];
|
|
32
|
+
}
|
|
33
|
+
/** Experimental normalized test result entry shared by framework reporters. */
|
|
34
|
+
interface TraceTestResult {
|
|
35
|
+
testId: string;
|
|
36
|
+
name: string;
|
|
37
|
+
file?: string;
|
|
38
|
+
status: TraceTestStatus;
|
|
39
|
+
durationMs?: number;
|
|
40
|
+
tracePath?: string;
|
|
41
|
+
artifacts?: TraceArtifact[];
|
|
42
|
+
diagnostics?: TraceReporterDiagnostic[];
|
|
43
|
+
}
|
|
44
|
+
/** Experimental reporter artifact manifest shared by framework reporters. */
|
|
45
|
+
interface TraceArtifactManifest {
|
|
46
|
+
schemaVersion: typeof TRACE_ARTIFACT_MANIFEST_SCHEMA_VERSION;
|
|
47
|
+
generatedAt: string;
|
|
48
|
+
framework: TraceReporterFramework;
|
|
49
|
+
results: TraceTestResult[];
|
|
50
|
+
artifacts: TraceArtifact[];
|
|
51
|
+
diagnostics: TraceReporterDiagnostic[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type AttributionConfidence = "explicit" | "correlated" | "heuristic" | "unknown";
|
|
55
|
+
type InspectKind = "RUN" | "AGENT" | "LLM" | "TOOL" | "CHAIN" | "RETRIEVER" | "DECISION" | "RESULT" | "ERROR" | "LOGIC" | "LOG" | "OUTCOME";
|
|
56
|
+
interface EventSource {
|
|
57
|
+
type: "manual" | "json-log" | "log4js" | "pino" | "winston" | "adapter";
|
|
58
|
+
file?: string;
|
|
59
|
+
line?: number;
|
|
60
|
+
}
|
|
61
|
+
interface InspectEvent {
|
|
62
|
+
eventId: string;
|
|
63
|
+
runId: string;
|
|
64
|
+
parentId?: string;
|
|
65
|
+
name: string;
|
|
66
|
+
kind: InspectKind;
|
|
67
|
+
timestamp: number;
|
|
68
|
+
status?: "running" | "ok" | "error";
|
|
69
|
+
durationMs?: number;
|
|
70
|
+
attributes?: Record<string, unknown>;
|
|
71
|
+
confidence: AttributionConfidence;
|
|
72
|
+
source: EventSource;
|
|
73
|
+
}
|
|
74
|
+
interface InspectNode {
|
|
75
|
+
event: InspectEvent;
|
|
76
|
+
children: InspectNode[];
|
|
77
|
+
depth: number;
|
|
78
|
+
}
|
|
79
|
+
/** Bounded parent/cycle summary for visibility-first tree building (6.14.2+). */
|
|
80
|
+
interface RelationshipSummary {
|
|
81
|
+
rootCount: number;
|
|
82
|
+
selfParentCount: number;
|
|
83
|
+
cycleCount: number;
|
|
84
|
+
unresolvedParentCount: number;
|
|
85
|
+
normalizedEdgeCount: number;
|
|
86
|
+
}
|
|
87
|
+
interface InspectRunTree {
|
|
88
|
+
runId: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
status?: "running" | "ok" | "error";
|
|
91
|
+
startedAt?: number;
|
|
92
|
+
endedAt?: number;
|
|
93
|
+
durationMs?: number;
|
|
94
|
+
children: InspectNode[];
|
|
95
|
+
metadata: {
|
|
96
|
+
totalEvents: number;
|
|
97
|
+
confidenceBreakdown: Record<AttributionConfidence, number>;
|
|
98
|
+
kinds: Record<InspectKind, number>;
|
|
99
|
+
relationshipSummary?: RelationshipSummary;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type PersistedEventSourceType = "manual" | "json-log" | "log4js" | "adapter" | "ai-sdk" | "otel";
|
|
104
|
+
interface PersistedEventSource {
|
|
105
|
+
type: PersistedEventSourceType;
|
|
106
|
+
name?: string;
|
|
107
|
+
version?: string;
|
|
108
|
+
}
|
|
109
|
+
type PersistedEventStatus = "running" | "ok" | "error" | "unknown";
|
|
110
|
+
interface PersistedInspectError {
|
|
111
|
+
name?: string;
|
|
112
|
+
message: string;
|
|
113
|
+
code?: string;
|
|
114
|
+
}
|
|
115
|
+
interface PersistedTokenUsage {
|
|
116
|
+
input?: number;
|
|
117
|
+
output?: number;
|
|
118
|
+
total?: number;
|
|
119
|
+
/** Cache-read tokens (informational; never added to total). */
|
|
120
|
+
cached?: number;
|
|
121
|
+
/** Cache-write / cache-creation tokens (informational; never added to total). */
|
|
122
|
+
cacheWrite?: number;
|
|
123
|
+
/** Reasoning / thinking tokens when providers report them separately. */
|
|
124
|
+
reasoning?: number;
|
|
125
|
+
}
|
|
126
|
+
interface PersistedTraceContext {
|
|
127
|
+
traceId?: string;
|
|
128
|
+
spanId?: string;
|
|
129
|
+
parentSpanId?: string;
|
|
130
|
+
}
|
|
131
|
+
interface PersistedInspectEventBase {
|
|
132
|
+
eventId: string;
|
|
133
|
+
runId: string;
|
|
134
|
+
parentId?: string;
|
|
135
|
+
kind: InspectKind;
|
|
136
|
+
name: string;
|
|
137
|
+
status?: PersistedEventStatus;
|
|
138
|
+
timestamp: string;
|
|
139
|
+
startedAt?: string;
|
|
140
|
+
endedAt?: string;
|
|
141
|
+
durationMs?: number;
|
|
142
|
+
confidence: AttributionConfidence;
|
|
143
|
+
source: PersistedEventSource;
|
|
144
|
+
attributes?: Record<string, unknown>;
|
|
145
|
+
inputSummary?: unknown;
|
|
146
|
+
outputSummary?: unknown;
|
|
147
|
+
error?: PersistedInspectError;
|
|
148
|
+
tokenUsage?: PersistedTokenUsage;
|
|
149
|
+
trace?: PersistedTraceContext;
|
|
150
|
+
}
|
|
151
|
+
interface PersistedInspectEventV02 extends PersistedInspectEventBase {
|
|
152
|
+
schemaVersion: "0.2";
|
|
153
|
+
}
|
|
154
|
+
interface PersistedInspectEventV10 extends PersistedInspectEventBase {
|
|
155
|
+
schemaVersion: "1.0";
|
|
156
|
+
[key: string]: unknown;
|
|
157
|
+
}
|
|
158
|
+
type PersistedInspectEvent = PersistedInspectEventV02 | PersistedInspectEventV10;
|
|
159
|
+
|
|
160
|
+
type TraceReadWarningSeverity = "info" | "warning" | "error";
|
|
161
|
+
interface TraceReadWarning {
|
|
162
|
+
code: string;
|
|
163
|
+
message: string;
|
|
164
|
+
severity?: TraceReadWarningSeverity;
|
|
165
|
+
sourceFile?: string;
|
|
166
|
+
line?: number;
|
|
167
|
+
field?: string;
|
|
168
|
+
}
|
|
169
|
+
interface TraceReadResult {
|
|
170
|
+
format: string;
|
|
171
|
+
events: PersistedInspectEvent[];
|
|
172
|
+
runs: InspectRunTree[];
|
|
173
|
+
warnings: TraceReadWarning[];
|
|
174
|
+
unsupportedFields: string[];
|
|
175
|
+
sourceFiles: string[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Explicit actor/run projection for TraceContract evaluation (#320).
|
|
180
|
+
*
|
|
181
|
+
* Selectors use only declared metadata (or explicit event ids). Zero matches
|
|
182
|
+
* and singular-actor ambiguity fail closed. No timestamp or display-name
|
|
183
|
+
* inference.
|
|
184
|
+
*
|
|
185
|
+
* @experimental
|
|
186
|
+
*/
|
|
187
|
+
interface TraceContractScope {
|
|
188
|
+
runId?: string;
|
|
189
|
+
subAgentId?: string;
|
|
190
|
+
groupId?: string;
|
|
191
|
+
workflowStep?: string;
|
|
192
|
+
/** Explicit root event id; evaluation projects to that event and descendants. */
|
|
193
|
+
rootEventId?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Declared-versus-enforced control checks for TraceContract (6.23).
|
|
198
|
+
*
|
|
199
|
+
* A stored declaration is not proof of enforcement.
|
|
200
|
+
*
|
|
201
|
+
* @experimental
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
type ControlStage = "declared" | "presented" | "validated" | "enforced" | "observed" | "accepted";
|
|
205
|
+
interface TraceContractControlRules {
|
|
206
|
+
/**
|
|
207
|
+
* Tools declared/presented to the agent (inline). Distinct from `enforcedTools`.
|
|
208
|
+
*/
|
|
209
|
+
declaredTools?: string[];
|
|
210
|
+
/**
|
|
211
|
+
* Tools the harness claims to enforce (inline allowlist).
|
|
212
|
+
*/
|
|
213
|
+
enforcedTools?: string[];
|
|
214
|
+
/**
|
|
215
|
+
* RUN/event attribute holding a string[] of declared tool names.
|
|
216
|
+
* Used when `declaredTools` is omitted.
|
|
217
|
+
*/
|
|
218
|
+
declaredToolsAttribute?: string;
|
|
219
|
+
/**
|
|
220
|
+
* RUN/event attribute holding a string[] of enforced tool names.
|
|
221
|
+
*/
|
|
222
|
+
enforcedToolsAttribute?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Fail when both declared and enforced sets resolve and differ.
|
|
225
|
+
*/
|
|
226
|
+
requireDeclaredMatchesEnforced?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Fail when any observed finished tool is outside the enforced set.
|
|
229
|
+
*/
|
|
230
|
+
requireObservedWithinEnforced?: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Fail when any observed finished tool is outside the declared set.
|
|
233
|
+
*/
|
|
234
|
+
requireObservedWithinDeclared?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Require observation names for control stages (default `control.<stage>`).
|
|
237
|
+
*/
|
|
238
|
+
requiredStages?: Array<{
|
|
239
|
+
stage: ControlStage;
|
|
240
|
+
/** Observation name; defaults to `control.<stage>`. */
|
|
241
|
+
observation?: string;
|
|
242
|
+
}>;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Bounded safe recovery operation contracts (6.27).
|
|
247
|
+
*
|
|
248
|
+
* Additive `retry.operations[]` rules for read-first recovery oracles.
|
|
249
|
+
* AgentInspect evaluates traces; it does not perform retries.
|
|
250
|
+
*
|
|
251
|
+
* @experimental
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/** How same-argument evidence may be compared across attempts. */
|
|
255
|
+
type RecoverySameArgumentsMode = "structured-or-digest";
|
|
256
|
+
/**
|
|
257
|
+
* Side-effect class for conservative write recovery semantics.
|
|
258
|
+
* Read-only tools may recover without write idempotency proof.
|
|
259
|
+
* Write tools treat timeout/unknown completion as fail/unevaluable
|
|
260
|
+
* unless authoritative idempotency evidence is present.
|
|
261
|
+
*/
|
|
262
|
+
type RecoverySideEffectClass = "read" | "write";
|
|
263
|
+
interface TraceContractRecoveryRetryableErrors {
|
|
264
|
+
/** Allowed error codes on failed attempts that precede a retry. */
|
|
265
|
+
codes?: readonly string[];
|
|
266
|
+
}
|
|
267
|
+
interface TraceContractRecoverySuccessfulResultDependency {
|
|
268
|
+
/** Consumer kind that must observe the successful tool result. */
|
|
269
|
+
consumerKind: "LLM";
|
|
270
|
+
/**
|
|
271
|
+
* When true, an LLM event must explicitly reference the successful tool
|
|
272
|
+
* event id (attributes / workflow metadata), not merely follow it in time.
|
|
273
|
+
*/
|
|
274
|
+
requireExplicitReference?: boolean;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Per-tool bounded recovery oracle (additive under `retry.operations`).
|
|
278
|
+
*
|
|
279
|
+
* @experimental Additive in 6.27.
|
|
280
|
+
*/
|
|
281
|
+
interface TraceContractRecoveryOperation {
|
|
282
|
+
tool: string;
|
|
283
|
+
maxAttempts?: number;
|
|
284
|
+
retryableErrors?: TraceContractRecoveryRetryableErrors;
|
|
285
|
+
requireFailureBeforeRetry?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* When true or `"structured-or-digest"`, retries must share structured
|
|
288
|
+
* arguments or matching digests. Missing evidence fails closed.
|
|
289
|
+
*/
|
|
290
|
+
requireSameArguments?: boolean | RecoverySameArgumentsMode;
|
|
291
|
+
requireTerminalSuccess?: boolean;
|
|
292
|
+
requireRecoveredFailureVisible?: boolean;
|
|
293
|
+
successfulResultDependency?: TraceContractRecoverySuccessfulResultDependency;
|
|
294
|
+
/**
|
|
295
|
+
* Defaults to `"read"`. Write tools apply conservative timeout/unknown rules.
|
|
296
|
+
*/
|
|
297
|
+
sideEffectClass?: RecoverySideEffectClass;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Retry / side-effect safety checks for TraceContract (6.23+; corrected in 6.25.1).
|
|
302
|
+
*
|
|
303
|
+
* Uses explicit attempt identity from session workflow metadata.
|
|
304
|
+
* AgentInspect evaluates; it does not perform retries.
|
|
305
|
+
*
|
|
306
|
+
* @experimental
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
interface TraceContractRetryRules {
|
|
310
|
+
/**
|
|
311
|
+
* Maximum attempts per `operationId` (or `attemptOf` grouping).
|
|
312
|
+
* Prefers distinct `attemptId` values, else validated contiguous `attemptNumber`s,
|
|
313
|
+
* else finished tool/LLM events in the operation.
|
|
314
|
+
*/
|
|
315
|
+
maxAttempts?: number;
|
|
316
|
+
/**
|
|
317
|
+
* When true, every operation with attempts must include a non-running terminal event.
|
|
318
|
+
*/
|
|
319
|
+
requireTerminalResult?: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Fail when `fallbackOf` is set without an earlier failure for the referenced operation
|
|
322
|
+
* that chronologically precedes the fallback event.
|
|
323
|
+
*/
|
|
324
|
+
fallbackOnlyAfterFailure?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Tool names treated as non-idempotent. A later attempt after an `ok` occurrence fails
|
|
327
|
+
* unless idempotency / no-side-effect evidence is present on the retry.
|
|
328
|
+
*/
|
|
329
|
+
nonIdempotentTools?: string[];
|
|
330
|
+
/**
|
|
331
|
+
* When true, genuine retries (including error→success) require `idempotencyKey`
|
|
332
|
+
* or `attributes.noSideEffect === true` / `sideEffect === false`.
|
|
333
|
+
* A client key alone is not proof of exactly-once mutation.
|
|
334
|
+
*/
|
|
335
|
+
requireIdempotencyEvidenceForRetry?: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* When true, recovered success paths must retain an earlier error attempt in the
|
|
338
|
+
* same operation/retry chain (not merely coexistence of ok+error).
|
|
339
|
+
*/
|
|
340
|
+
requireRecoveredFailureVisible?: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Per-tool bounded recovery oracles (read-first; write timeout/unknown fails closed).
|
|
343
|
+
*
|
|
344
|
+
* @experimental Additive in 6.27.
|
|
345
|
+
*/
|
|
346
|
+
operations?: readonly TraceContractRecoveryOperation[];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
type ToolArgumentOperator = "exists" | "type" | "equals" | "oneOf";
|
|
350
|
+
type ToolArgumentOccurrence = "first" | "last" | "any" | "all";
|
|
351
|
+
interface ToolArgumentCheck {
|
|
352
|
+
tool: string;
|
|
353
|
+
path: string;
|
|
354
|
+
operator: ToolArgumentOperator;
|
|
355
|
+
occurrence?: ToolArgumentOccurrence;
|
|
356
|
+
/** Required for `equals`. */
|
|
357
|
+
expected?: unknown;
|
|
358
|
+
/** Required for `oneOf`. */
|
|
359
|
+
oneOf?: readonly unknown[];
|
|
360
|
+
/** Required for `type` (`string` | `number` | `boolean` | `object` | `array` | `null`). */
|
|
361
|
+
type?: "string" | "number" | "boolean" | "object" | "array" | "null";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* @experimental Typed trace contract input. Evolves during v6.5.x.
|
|
366
|
+
*/
|
|
367
|
+
interface TraceContractRunRules {
|
|
368
|
+
requireCompleted?: boolean;
|
|
369
|
+
allowedStatuses?: string[];
|
|
370
|
+
maxDurationMs?: number;
|
|
371
|
+
}
|
|
372
|
+
interface TraceContractToolRules {
|
|
373
|
+
/**
|
|
374
|
+
* Unconditional tool presence invariant. Every named tool must appear at least
|
|
375
|
+
* once. Do not use for cache-hit or alternate-path shortcuts — prefer
|
|
376
|
+
* `alternatives.anyOf` or `observations.required` when a legitimate path may
|
|
377
|
+
* skip the tool.
|
|
378
|
+
*
|
|
379
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
380
|
+
*/
|
|
381
|
+
required?: string[];
|
|
382
|
+
/** Alias of `required` (TraceContract v2 normalization). */
|
|
383
|
+
requiredTools?: string[];
|
|
384
|
+
forbidden?: string[];
|
|
385
|
+
/** Alias of `forbidden`. */
|
|
386
|
+
forbiddenTools?: string[];
|
|
387
|
+
allowed?: string[];
|
|
388
|
+
maxCalls?: number;
|
|
389
|
+
/**
|
|
390
|
+
* Required tool order expanded into adjacent pairs.
|
|
391
|
+
*
|
|
392
|
+
* `[A, B, C]` expands to “A before B” and “B before C”, each comparing the
|
|
393
|
+
* selected `requiredOrderMode` to every pair. Unlisted intermediate tools
|
|
394
|
+
* are allowed.
|
|
395
|
+
*
|
|
396
|
+
* TraceContract `requiredOrder` **implies presence**: every listed name is
|
|
397
|
+
* added to the effective required-tool set. Low-level `createToolOrderingRule`
|
|
398
|
+
* alone may still pass vacuously when an endpoint is missing.
|
|
399
|
+
*
|
|
400
|
+
* The default `first-occurrence` mode preserves first-occurrence encounter
|
|
401
|
+
* ordering; overlapping intervals emit a non-failing warning. `happens-before`
|
|
402
|
+
* requires the first before event to finish before the first after event starts.
|
|
403
|
+
* `all-occurrences` applies that causal boundary to every occurrence.
|
|
404
|
+
*
|
|
405
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
406
|
+
* @beta Available through `agent-inspect/checks`. Additive changes may ship
|
|
407
|
+
* in minor releases; breaking changes require a future major.
|
|
408
|
+
*/
|
|
409
|
+
requiredOrder?: string[];
|
|
410
|
+
/**
|
|
411
|
+
* Ordering semantics applied to every adjacent pair in `requiredOrder`.
|
|
412
|
+
* Causal modes fail closed when a required interval boundary is unavailable.
|
|
413
|
+
*
|
|
414
|
+
* @defaultValue `"first-occurrence"`
|
|
415
|
+
* @beta Available through `agent-inspect/checks`.
|
|
416
|
+
*/
|
|
417
|
+
requiredOrderMode?: "first-occurrence" | "happens-before" | "all-occurrences";
|
|
418
|
+
/**
|
|
419
|
+
* Bounded structured tool-argument checks (JSON Pointer + limited operators).
|
|
420
|
+
*
|
|
421
|
+
* Missing structured evidence fails closed as unevaluable (not pass).
|
|
422
|
+
* Findings never embed full actual inputs.
|
|
423
|
+
*
|
|
424
|
+
* @experimental Additive in 6.23.
|
|
425
|
+
*/
|
|
426
|
+
arguments?: ToolArgumentCheck[];
|
|
427
|
+
/**
|
|
428
|
+
* Default occurrence mode for `orderRules` when a rule omits `occurrenceMode`.
|
|
429
|
+
*
|
|
430
|
+
* @experimental Additive in 6.23.
|
|
431
|
+
*/
|
|
432
|
+
defaultOccurrenceMode?: "first-occurrence" | "happens-before" | "all-occurrences";
|
|
433
|
+
/**
|
|
434
|
+
* Mixed per-pair ordering rules (additive alongside `requiredOrder`).
|
|
435
|
+
*
|
|
436
|
+
* @experimental Additive in 6.23.
|
|
437
|
+
*/
|
|
438
|
+
orderRules?: Array<{
|
|
439
|
+
before: string;
|
|
440
|
+
after: string;
|
|
441
|
+
occurrenceMode?: "first-occurrence" | "happens-before" | "all-occurrences";
|
|
442
|
+
requireEndpoints?: boolean;
|
|
443
|
+
}>;
|
|
444
|
+
}
|
|
445
|
+
interface TraceContractLlmRules {
|
|
446
|
+
maxCalls?: number;
|
|
447
|
+
maxTotalTokens?: number;
|
|
448
|
+
allowedModels?: string[];
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Explicit TOOL or LLM step endpoint for typed cross-kind ordering.
|
|
452
|
+
*
|
|
453
|
+
* @experimental Additive in 6.31.
|
|
454
|
+
*/
|
|
455
|
+
type TraceContractStepKind = "TOOL" | "LLM";
|
|
456
|
+
/**
|
|
457
|
+
* Named step endpoint with an explicit event kind.
|
|
458
|
+
*
|
|
459
|
+
* @experimental Additive in 6.31.
|
|
460
|
+
*/
|
|
461
|
+
interface TraceContractStepRef {
|
|
462
|
+
kind: TraceContractStepKind;
|
|
463
|
+
name: string;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* One typed before/after ordering relation across TOOL and/or LLM steps.
|
|
467
|
+
*
|
|
468
|
+
* Unlike `tools.requiredOrder` / `orderRules`, endpoints are kind-qualified so
|
|
469
|
+
* an LLM named `generate_answer` does not satisfy a TOOL endpoint (and vice versa).
|
|
470
|
+
*
|
|
471
|
+
* @experimental Additive in 6.31.
|
|
472
|
+
*/
|
|
473
|
+
interface TraceContractStepOrderRelation {
|
|
474
|
+
before: TraceContractStepRef;
|
|
475
|
+
after: TraceContractStepRef;
|
|
476
|
+
/**
|
|
477
|
+
* Ordering semantics for this pair.
|
|
478
|
+
*
|
|
479
|
+
* @defaultValue `"first-occurrence"`
|
|
480
|
+
*/
|
|
481
|
+
mode?: "first-occurrence" | "happens-before" | "all-occurrences";
|
|
482
|
+
/**
|
|
483
|
+
* When true (default), missing endpoints of the declared kind fail.
|
|
484
|
+
* Wrong-kind same-name events do not satisfy the endpoint.
|
|
485
|
+
*
|
|
486
|
+
* @defaultValue `true`
|
|
487
|
+
*/
|
|
488
|
+
requireEndpoints?: boolean;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Cross-kind step ordering (TOOL ↔ LLM). Does not change TOOL-only
|
|
492
|
+
* `tools.requiredOrder` / `orderRules` semantics.
|
|
493
|
+
*
|
|
494
|
+
* @experimental Additive in 6.31.
|
|
495
|
+
*/
|
|
496
|
+
interface TraceContractStepRules {
|
|
497
|
+
orderRelations?: TraceContractStepOrderRelation[];
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Structural provenance requirements for named observed outcomes (#321).
|
|
501
|
+
*
|
|
502
|
+
* These checks prove method/evidence linkage was recorded. They do **not**
|
|
503
|
+
* prove the claim is semantically true, authorized, complete, or externally
|
|
504
|
+
* trusted.
|
|
505
|
+
*
|
|
506
|
+
* @experimental
|
|
507
|
+
*/
|
|
508
|
+
interface TraceContractObservationProvenance {
|
|
509
|
+
/** Require a non-empty method from the bounded ObservedOutcomeMethod vocabulary. */
|
|
510
|
+
method?: boolean;
|
|
511
|
+
/**
|
|
512
|
+
* Require bounded evidence references. Supported shapes:
|
|
513
|
+
* `string` event id, `{ eventId }`, or `{ eventIds: string[] }` (max 16 ids).
|
|
514
|
+
*/
|
|
515
|
+
evidence?: boolean;
|
|
516
|
+
/** When true with evidence, each referenced event id must exist in the same run. */
|
|
517
|
+
sameRunEventReference?: boolean;
|
|
518
|
+
}
|
|
519
|
+
interface TraceContractObservationRules {
|
|
520
|
+
required?: string[];
|
|
521
|
+
failOn?: Array<"failed" | "unknown" | "skipped">;
|
|
522
|
+
/**
|
|
523
|
+
* Structural provenance gates for `required` observation names.
|
|
524
|
+
*
|
|
525
|
+
* @experimental
|
|
526
|
+
*/
|
|
527
|
+
requireProvenance?: TraceContractObservationProvenance;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* One deterministic alternate path. Branch contracts are one level only —
|
|
531
|
+
* nested `alternatives` are rejected.
|
|
532
|
+
*
|
|
533
|
+
* @experimental
|
|
534
|
+
*/
|
|
535
|
+
interface TraceContractAlternativeBranch {
|
|
536
|
+
/** Unique branch id within `alternatives.anyOf`. */
|
|
537
|
+
id: string;
|
|
538
|
+
description?: string;
|
|
539
|
+
/** Branch body: run/tools/llm/observations only (no nested alternatives). */
|
|
540
|
+
contract: TraceContractBody;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Bounded alternative valid paths for legitimate shortcuts (GitHub #309).
|
|
544
|
+
*
|
|
545
|
+
* @experimental
|
|
546
|
+
*/
|
|
547
|
+
interface TraceContractAlternatives {
|
|
548
|
+
/**
|
|
549
|
+
* One level of named branches. The overall contract passes when the base
|
|
550
|
+
* rules pass and **at least one** complete branch passes.
|
|
551
|
+
*/
|
|
552
|
+
anyOf: TraceContractAlternativeBranch[];
|
|
553
|
+
}
|
|
554
|
+
/** Contract body without alternatives (base or branch). */
|
|
555
|
+
type TraceContractBody = {
|
|
556
|
+
run?: TraceContractRunRules;
|
|
557
|
+
tools?: TraceContractToolRules;
|
|
558
|
+
llm?: TraceContractLlmRules;
|
|
559
|
+
/**
|
|
560
|
+
* Typed cross-kind step ordering (TOOL / LLM endpoints).
|
|
561
|
+
*
|
|
562
|
+
* @experimental Additive in 6.31.
|
|
563
|
+
*/
|
|
564
|
+
steps?: TraceContractStepRules;
|
|
565
|
+
observations?: TraceContractObservationRules;
|
|
566
|
+
/**
|
|
567
|
+
* Declared-versus-enforced control invariants.
|
|
568
|
+
*
|
|
569
|
+
* @experimental Additive in 6.23.
|
|
570
|
+
*/
|
|
571
|
+
controls?: TraceContractControlRules;
|
|
572
|
+
/**
|
|
573
|
+
* Retry / side-effect safety using explicit attempt identity.
|
|
574
|
+
* Additive `retry.operations[]` recovery oracles land in 6.27.
|
|
575
|
+
*
|
|
576
|
+
* @experimental Additive in 6.23; operations in 6.27.
|
|
577
|
+
*/
|
|
578
|
+
retry?: TraceContractRetryRules;
|
|
579
|
+
};
|
|
580
|
+
interface TraceContractInput extends TraceContractBody {
|
|
581
|
+
/**
|
|
582
|
+
* Optional actor/run projection applied before evaluation (#320).
|
|
583
|
+
*
|
|
584
|
+
* @experimental
|
|
585
|
+
*/
|
|
586
|
+
scope?: TraceContractScope;
|
|
587
|
+
alternatives?: TraceContractAlternatives;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Experimental input projection for trace checks.
|
|
592
|
+
*
|
|
593
|
+
* The `read` value must come from `agent-inspect/readers` or an equivalent
|
|
594
|
+
* already-normalized `TraceReadResult`. The checks engine does not read files
|
|
595
|
+
* or reparse source payloads.
|
|
596
|
+
*
|
|
597
|
+
* @experimental Available through `agent-inspect/checks`. Additive changes may ship in minor releases; breaking changes require a future major.
|
|
598
|
+
*/
|
|
599
|
+
interface TraceCheckInput {
|
|
600
|
+
read: TraceReadResult;
|
|
601
|
+
selectedRun?: InspectRunTree;
|
|
602
|
+
sourceLabel?: string;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Experimental Jest matchers for AgentInspect TraceFacts / TraceContract.
|
|
607
|
+
*
|
|
608
|
+
* @experimental Part of the v6.13 TraceFacts train.
|
|
609
|
+
*/
|
|
610
|
+
|
|
611
|
+
type TraceLike = TraceCheckInput | {
|
|
612
|
+
readonly events: TraceCheckInput["read"]["events"];
|
|
613
|
+
} | TraceCheckInput["read"]["events"];
|
|
614
|
+
declare const agentInspectJestMatchers: {
|
|
615
|
+
toPassTraceContract(received: TraceLike, contract: TraceContractInput): {
|
|
616
|
+
pass: boolean;
|
|
617
|
+
message: () => string;
|
|
618
|
+
};
|
|
619
|
+
toHaveRequiredTool(received: TraceLike, toolName: string): {
|
|
620
|
+
pass: boolean;
|
|
621
|
+
message: () => string;
|
|
622
|
+
};
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
type AgentInspectJestStatus = "failed" | "passed" | "skipped";
|
|
626
|
+
/**
|
|
627
|
+
* Experimental trace association read by `@agent-inspect/jest`.
|
|
628
|
+
*
|
|
629
|
+
* Jest does not expose Vitest-style task metadata, so the default path is an
|
|
630
|
+
* explicit `associations` map keyed by test identity, or a `resolveTrace`
|
|
631
|
+
* callback. The reporter never guesses by timestamps.
|
|
632
|
+
*/
|
|
633
|
+
interface AgentInspectJestTraceAssociation {
|
|
634
|
+
/** AgentInspect run/span identifier to show in safe artifacts. */
|
|
635
|
+
readonly runId?: string;
|
|
636
|
+
/** Local trace file path. Only the basename is written to artifacts. */
|
|
637
|
+
readonly tracePath?: string;
|
|
638
|
+
/** Optional stable label for the artifact directory. */
|
|
639
|
+
readonly artifactLabel?: string;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Experimental normalized view of one Jest assertion result.
|
|
643
|
+
*/
|
|
644
|
+
interface AgentInspectJestTestCase {
|
|
645
|
+
readonly id: string;
|
|
646
|
+
readonly title: string;
|
|
647
|
+
readonly fullName: string;
|
|
648
|
+
readonly file?: string;
|
|
649
|
+
readonly status: AgentInspectJestStatus;
|
|
650
|
+
readonly raw: unknown;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Experimental diagnostic emitted when reporter work cannot be completed.
|
|
654
|
+
*
|
|
655
|
+
* Diagnostics are reported instead of thrown so Jest's original test result
|
|
656
|
+
* remains authoritative.
|
|
657
|
+
*/
|
|
658
|
+
interface AgentInspectJestDiagnostic {
|
|
659
|
+
readonly code: "artifact-write-failed" | "github-summary-write-failed" | "no-trace-association" | "on-diagnostic-failed";
|
|
660
|
+
readonly message: string;
|
|
661
|
+
readonly testId?: string;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Experimental options for the AgentInspect Jest reporter.
|
|
665
|
+
*
|
|
666
|
+
* The reporter is local-only: it performs no network I/O and writes bounded,
|
|
667
|
+
* structural artifacts without reading trace contents.
|
|
668
|
+
*/
|
|
669
|
+
interface AgentInspectJestReporterOptions {
|
|
670
|
+
/** Directory for safe Jest artifacts. Defaults to `.agent-inspect/jest-artifacts`. */
|
|
671
|
+
readonly artifactDir?: string;
|
|
672
|
+
/** Optional GitHub step-summary path. Only bounded structural lines are appended. */
|
|
673
|
+
readonly githubSummary?: string;
|
|
674
|
+
/**
|
|
675
|
+
* Keep artifacts for passing tests. `false`/undefined keeps none; `true`
|
|
676
|
+
* keeps up to `maxSuccessfulTraces`; a number keeps up to that many.
|
|
677
|
+
*/
|
|
678
|
+
readonly retainSuccessful?: boolean | number;
|
|
679
|
+
/** Upper bound for retained passing-test artifacts. Defaults to 20. */
|
|
680
|
+
readonly maxSuccessfulTraces?: number;
|
|
681
|
+
/** Redaction profile recorded on generated artifacts. Defaults to `share`. */
|
|
682
|
+
readonly redactionProfile?: TraceArtifactRedactionProfile;
|
|
683
|
+
/** Deterministic manifest timestamp. Defaults to the Unix epoch. */
|
|
684
|
+
readonly generatedAt?: string;
|
|
685
|
+
/** Explicit trace associations keyed by `file::fullName`, `basename::fullName`, or `fullName`. */
|
|
686
|
+
readonly associations?: Record<string, AgentInspectJestTraceAssociation>;
|
|
687
|
+
/** Resolve explicit test-to-trace associations from a normalized Jest case. */
|
|
688
|
+
readonly resolveTrace?: (test: AgentInspectJestTestCase) => AgentInspectJestTraceAssociation | undefined;
|
|
689
|
+
/** Observe non-fatal reporter diagnostics. */
|
|
690
|
+
readonly onDiagnostic?: (diagnostic: AgentInspectJestDiagnostic) => void;
|
|
691
|
+
}
|
|
692
|
+
interface AgentInspectJestArtifact {
|
|
693
|
+
readonly directory: string;
|
|
694
|
+
readonly manifestPath: string;
|
|
695
|
+
readonly summaryPath: string;
|
|
696
|
+
readonly status: AgentInspectJestStatus;
|
|
697
|
+
readonly testId: string;
|
|
698
|
+
readonly manifest: TraceArtifactManifest;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Experimental Jest reporter facade.
|
|
702
|
+
*
|
|
703
|
+
* The hooks mirror Jest reporter lifecycle names, while inputs stay structural
|
|
704
|
+
* to avoid a runtime dependency on Jest internals.
|
|
705
|
+
*/
|
|
706
|
+
interface AgentInspectJestReporterFacade {
|
|
707
|
+
onTestResult(test: unknown, testResult: unknown, aggregatedResult?: unknown): Promise<void>;
|
|
708
|
+
onRunComplete(contexts?: unknown, results?: unknown): Promise<void>;
|
|
709
|
+
getDiagnostics(): readonly AgentInspectJestDiagnostic[];
|
|
710
|
+
getArtifacts(): readonly AgentInspectJestArtifact[];
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Attach an explicit AgentInspect trace association to a Jest assertion result.
|
|
714
|
+
*
|
|
715
|
+
* The reporter does not instrument tests automatically; pass the returned object
|
|
716
|
+
* as `agentInspect` / `meta.agentInspect` or use `associations` / `resolveTrace`.
|
|
717
|
+
*/
|
|
718
|
+
declare function withAgentInspectJestTrace(association: AgentInspectJestTraceAssociation): {
|
|
719
|
+
readonly agentInspect: AgentInspectJestTraceAssociation;
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* Create the experimental AgentInspect Jest reporter.
|
|
723
|
+
*/
|
|
724
|
+
declare function createAgentInspectJestReporter(options?: AgentInspectJestReporterOptions): AgentInspectJestReporterFacade;
|
|
725
|
+
/**
|
|
726
|
+
* Experimental Jest custom reporter class.
|
|
727
|
+
*/
|
|
728
|
+
declare class AgentInspectJestReporter implements AgentInspectJestReporterFacade {
|
|
729
|
+
private readonly reporter;
|
|
730
|
+
constructor(_globalConfig?: unknown, options?: AgentInspectJestReporterOptions);
|
|
731
|
+
onTestResult(test: unknown, testResult: unknown, aggregatedResult?: unknown): Promise<void>;
|
|
732
|
+
onRunComplete(contexts?: unknown, results?: unknown): Promise<void>;
|
|
733
|
+
getDiagnostics(): readonly AgentInspectJestDiagnostic[];
|
|
734
|
+
getArtifacts(): readonly AgentInspectJestArtifact[];
|
|
735
|
+
}
|
|
736
|
+
declare const agentInspectJestReporter: typeof createAgentInspectJestReporter;
|
|
737
|
+
|
|
738
|
+
export { type AgentInspectJestArtifact, type AgentInspectJestDiagnostic, AgentInspectJestReporter, type AgentInspectJestReporterFacade, type AgentInspectJestReporterOptions, type AgentInspectJestStatus, type AgentInspectJestTestCase, type AgentInspectJestTraceAssociation, agentInspectJestMatchers, agentInspectJestReporter, createAgentInspectJestReporter, AgentInspectJestReporter as default, withAgentInspectJestTrace };
|