agent-inspect 6.17.4 → 6.17.5
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/docs/ADAPTERS.md +3 -3
- package/docs/API.md +13 -7
- package/docs/CLI.md +2 -0
- package/docs/LIMITATIONS.md +1 -0
- package/docs/TRACE-CONTRACTS.md +90 -0
- package/package.json +5 -2
- package/packages/cli/dist/{chunk-YX6RFLV5.mjs → chunk-GOHYSE7W.mjs} +86 -17
- package/packages/cli/dist/chunk-GOHYSE7W.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +480 -80
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +399 -68
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-X6SLMBNH.mjs → src-OYGG7QAZ.mjs} +3 -3
- package/packages/cli/dist/{src-X6SLMBNH.mjs.map → src-OYGG7QAZ.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +85 -16
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.d.cts +1 -1
- package/packages/core/dist/advanced.d.ts +1 -1
- package/packages/core/dist/advanced.mjs +15 -5
- package/packages/core/dist/advanced.mjs.map +1 -1
- package/packages/core/dist/checks.cjs +119 -26
- package/packages/core/dist/checks.cjs.map +1 -1
- package/packages/core/dist/checks.d.cts +28 -2
- package/packages/core/dist/checks.d.ts +28 -2
- package/packages/core/dist/checks.mjs +1 -1
- package/packages/core/dist/{chunk-HN377P23.mjs → chunk-DIZPIPY2.mjs} +121 -28
- package/packages/core/dist/chunk-DIZPIPY2.mjs.map +1 -0
- package/packages/core/dist/{index-Xk9X-yjY.d.cts → index-DWu54Y28.d.cts} +107 -122
- package/packages/core/dist/{index-BsCcOKxy.d.ts → index-DlwbVqEs.d.ts} +107 -122
- package/packages/cli/dist/chunk-YX6RFLV5.mjs.map +0 -1
- package/packages/core/dist/chunk-HN377P23.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LogicalProjectionDiagnostic, a as LogicalTraceEvent, T as TraceCheckInput, b as TraceCheckResult } from './index-
|
|
2
|
-
export { B as BaselineRegressionRuleOptions, D as DecisionRuleOptions, G as GuardrailRuleOptions, c as LlmUsageRuleOptions, M as MaxStepDurationRuleOptions, O as ObservedOutcomeRuleOptions, R as RetrievalRuleOptions, d as RunDepthRuleOptions, e as RunDurationRuleOptions, f as RunEventCountRuleOptions, g as RunStatusRuleOptions, h as RunTraceChecksOptions, S as SafetyFindingCategory, i as SafetyFindingConfidence, j as SafetyOversizedAttributeRuleOptions, k as SafetyRawContentRuleOptions, l as SafetyRedactionRuleOptions, m as SafetySecretPattern, n as SafetySecretPatternRuleOptions, o as StallDetectionRuleOptions, p as StructureIncompleteRuleOptions, q as StructureOrphanRuleOptions, r as StructureParallelWidthRuleOptions, s as StructureRelationshipRuleOptions, t as ToolFailureRuleOptions, u as ToolOrderingRuleOptions, v as ToolUsageRuleOptions, w as TraceCheckContext, x as TraceCheckDiagnostic, y as TraceCheckDiagnosticCode, z as TraceCheckEvidence, A as TraceCheckFacts, C as TraceCheckFinding, E as TraceCheckFindingStatus, F as TraceCheckRule, H as TraceCheckRuleCategory, I as
|
|
1
|
+
import { L as LogicalProjectionDiagnostic, a as LogicalTraceEvent, T as TraceCheckInput, b as TraceCheckResult } from './index-DWu54Y28.cjs';
|
|
2
|
+
export { B as BaselineRegressionRuleOptions, D as DecisionRuleOptions, G as GuardrailRuleOptions, c as LlmUsageRuleOptions, M as MaxStepDurationRuleOptions, O as ObservedOutcomeRuleOptions, R as RetrievalRuleOptions, d as RunDepthRuleOptions, e as RunDurationRuleOptions, f as RunEventCountRuleOptions, g as RunStatusRuleOptions, h as RunTraceChecksOptions, S as SafetyFindingCategory, i as SafetyFindingConfidence, j as SafetyOversizedAttributeRuleOptions, k as SafetyRawContentRuleOptions, l as SafetyRedactionRuleOptions, m as SafetySecretPattern, n as SafetySecretPatternRuleOptions, o as StallDetectionRuleOptions, p as StructureIncompleteRuleOptions, q as StructureOrphanRuleOptions, r as StructureParallelWidthRuleOptions, s as StructureRelationshipRuleOptions, t as ToolFailureRuleOptions, u as ToolOrderingRuleOptions, v as ToolUsageRuleOptions, w as TraceCheckContext, x as TraceCheckDiagnostic, y as TraceCheckDiagnosticCode, z as TraceCheckEvidence, A as TraceCheckFacts, C as TraceCheckFinding, E as TraceCheckFindingStatus, F as TraceCheckRule, H as TraceCheckRuleCategory, I as TraceCheckRuleExecution, J as TraceCheckRuleExecutionStatus, K as TraceCheckSeverity, N as TraceCheckStatus, P as TraceCheckSummary, Q as TraceSignalRuleOptions, U as createBaselineRegressionRule, V as createDecisionRule, W as createGuardrailRule, X as createLlmUsageRule, Y as createMaxStepDurationRule, Z as createObservedOutcomeRule, _ as createRequireCompletedRule, $ as createRetrievalRule, a0 as createRunDepthRule, a1 as createRunDurationRule, a2 as createRunEventCountRule, a3 as createRunStatusRule, a4 as createSafetyOversizedAttributeRule, a5 as createSafetyRawContentRule, a6 as createSafetyRedactionRule, a7 as createSafetySecretPatternRule, a8 as createStallDetectionRule, a9 as createStructureCycleRule, aa as createStructureIncompleteRule, ab as createStructureOrphanRule, ac as createStructureParallelWidthRule, ad as createStructureRelationshipRule, ae as createToolFailureRule, af as createToolOrderingRule, ag as createToolUsageRule, ah as projectLogicalEvents, ai as resolveCanonicalToolName, aj as runTraceChecks } from './index-DWu54Y28.cjs';
|
|
3
3
|
export { PROGRAMMATIC_DIAGNOSTIC_SPECS, ProgrammaticDiagnosticCode, ProgrammaticDiagnosticSpec, formatProgrammaticDiagnostic } from './readers.cjs';
|
|
4
4
|
import { T as TraceReadResult } from './index-B259NKkH.cjs';
|
|
5
5
|
import { P as PersistedInspectEvent } from './persisted-inspect-event-CVZWZldL.cjs';
|
|
@@ -66,6 +66,13 @@ interface TraceContractRunRules {
|
|
|
66
66
|
maxDurationMs?: number;
|
|
67
67
|
}
|
|
68
68
|
interface TraceContractToolRules {
|
|
69
|
+
/**
|
|
70
|
+
* Unconditional tool presence invariant. Every named tool must appear at least
|
|
71
|
+
* once. Do not use for cache-hit or alternate-path shortcuts — prefer
|
|
72
|
+
* `observations.required` until `alternatives.anyOf` ships (planned 6.20.0).
|
|
73
|
+
*
|
|
74
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
75
|
+
*/
|
|
69
76
|
required?: string[];
|
|
70
77
|
/** Alias of `required` (TraceContract v2 normalization). */
|
|
71
78
|
requiredTools?: string[];
|
|
@@ -74,6 +81,25 @@ interface TraceContractToolRules {
|
|
|
74
81
|
forbiddenTools?: string[];
|
|
75
82
|
allowed?: string[];
|
|
76
83
|
maxCalls?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Required tool order as adjacent first-occurrence pairs (start/encounter order).
|
|
86
|
+
*
|
|
87
|
+
* `[A, B, C]` expands to “A before B” and “B before C”, each comparing the
|
|
88
|
+
* first occurrence of the named tool. Unlisted intermediate tools are
|
|
89
|
+
* allowed. Later repetitions do not invalidate an earlier valid order.
|
|
90
|
+
*
|
|
91
|
+
* TraceContract `requiredOrder` **implies presence**: every listed name is
|
|
92
|
+
* added to the effective required-tool set. Low-level `createToolOrderingRule`
|
|
93
|
+
* alone may still pass vacuously when an endpoint is missing.
|
|
94
|
+
*
|
|
95
|
+
* This is **not** causal happens-before. Overlapping intervals emit a
|
|
96
|
+
* non-failing overlap warning. Planned modes (6.20.0, GitHub #308):
|
|
97
|
+
* `happens-before`, `all-occurrences`.
|
|
98
|
+
*
|
|
99
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
100
|
+
* @beta Available through `agent-inspect/checks`. Additive changes may ship
|
|
101
|
+
* in minor releases; breaking changes require a future major.
|
|
102
|
+
*/
|
|
77
103
|
requiredOrder?: string[];
|
|
78
104
|
}
|
|
79
105
|
interface TraceContractLlmRules {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LogicalProjectionDiagnostic, a as LogicalTraceEvent, T as TraceCheckInput, b as TraceCheckResult } from './index-
|
|
2
|
-
export { B as BaselineRegressionRuleOptions, D as DecisionRuleOptions, G as GuardrailRuleOptions, c as LlmUsageRuleOptions, M as MaxStepDurationRuleOptions, O as ObservedOutcomeRuleOptions, R as RetrievalRuleOptions, d as RunDepthRuleOptions, e as RunDurationRuleOptions, f as RunEventCountRuleOptions, g as RunStatusRuleOptions, h as RunTraceChecksOptions, S as SafetyFindingCategory, i as SafetyFindingConfidence, j as SafetyOversizedAttributeRuleOptions, k as SafetyRawContentRuleOptions, l as SafetyRedactionRuleOptions, m as SafetySecretPattern, n as SafetySecretPatternRuleOptions, o as StallDetectionRuleOptions, p as StructureIncompleteRuleOptions, q as StructureOrphanRuleOptions, r as StructureParallelWidthRuleOptions, s as StructureRelationshipRuleOptions, t as ToolFailureRuleOptions, u as ToolOrderingRuleOptions, v as ToolUsageRuleOptions, w as TraceCheckContext, x as TraceCheckDiagnostic, y as TraceCheckDiagnosticCode, z as TraceCheckEvidence, A as TraceCheckFacts, C as TraceCheckFinding, E as TraceCheckFindingStatus, F as TraceCheckRule, H as TraceCheckRuleCategory, I as
|
|
1
|
+
import { L as LogicalProjectionDiagnostic, a as LogicalTraceEvent, T as TraceCheckInput, b as TraceCheckResult } from './index-DlwbVqEs.js';
|
|
2
|
+
export { B as BaselineRegressionRuleOptions, D as DecisionRuleOptions, G as GuardrailRuleOptions, c as LlmUsageRuleOptions, M as MaxStepDurationRuleOptions, O as ObservedOutcomeRuleOptions, R as RetrievalRuleOptions, d as RunDepthRuleOptions, e as RunDurationRuleOptions, f as RunEventCountRuleOptions, g as RunStatusRuleOptions, h as RunTraceChecksOptions, S as SafetyFindingCategory, i as SafetyFindingConfidence, j as SafetyOversizedAttributeRuleOptions, k as SafetyRawContentRuleOptions, l as SafetyRedactionRuleOptions, m as SafetySecretPattern, n as SafetySecretPatternRuleOptions, o as StallDetectionRuleOptions, p as StructureIncompleteRuleOptions, q as StructureOrphanRuleOptions, r as StructureParallelWidthRuleOptions, s as StructureRelationshipRuleOptions, t as ToolFailureRuleOptions, u as ToolOrderingRuleOptions, v as ToolUsageRuleOptions, w as TraceCheckContext, x as TraceCheckDiagnostic, y as TraceCheckDiagnosticCode, z as TraceCheckEvidence, A as TraceCheckFacts, C as TraceCheckFinding, E as TraceCheckFindingStatus, F as TraceCheckRule, H as TraceCheckRuleCategory, I as TraceCheckRuleExecution, J as TraceCheckRuleExecutionStatus, K as TraceCheckSeverity, N as TraceCheckStatus, P as TraceCheckSummary, Q as TraceSignalRuleOptions, U as createBaselineRegressionRule, V as createDecisionRule, W as createGuardrailRule, X as createLlmUsageRule, Y as createMaxStepDurationRule, Z as createObservedOutcomeRule, _ as createRequireCompletedRule, $ as createRetrievalRule, a0 as createRunDepthRule, a1 as createRunDurationRule, a2 as createRunEventCountRule, a3 as createRunStatusRule, a4 as createSafetyOversizedAttributeRule, a5 as createSafetyRawContentRule, a6 as createSafetyRedactionRule, a7 as createSafetySecretPatternRule, a8 as createStallDetectionRule, a9 as createStructureCycleRule, aa as createStructureIncompleteRule, ab as createStructureOrphanRule, ac as createStructureParallelWidthRule, ad as createStructureRelationshipRule, ae as createToolFailureRule, af as createToolOrderingRule, ag as createToolUsageRule, ah as projectLogicalEvents, ai as resolveCanonicalToolName, aj as runTraceChecks } from './index-DlwbVqEs.js';
|
|
3
3
|
export { PROGRAMMATIC_DIAGNOSTIC_SPECS, ProgrammaticDiagnosticCode, ProgrammaticDiagnosticSpec, formatProgrammaticDiagnostic } from './readers.js';
|
|
4
4
|
import { T as TraceReadResult } from './index-B9ZGvUVL.js';
|
|
5
5
|
import { P as PersistedInspectEvent } from './persisted-inspect-event-BVucFVrP.js';
|
|
@@ -66,6 +66,13 @@ interface TraceContractRunRules {
|
|
|
66
66
|
maxDurationMs?: number;
|
|
67
67
|
}
|
|
68
68
|
interface TraceContractToolRules {
|
|
69
|
+
/**
|
|
70
|
+
* Unconditional tool presence invariant. Every named tool must appear at least
|
|
71
|
+
* once. Do not use for cache-hit or alternate-path shortcuts — prefer
|
|
72
|
+
* `observations.required` until `alternatives.anyOf` ships (planned 6.20.0).
|
|
73
|
+
*
|
|
74
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
75
|
+
*/
|
|
69
76
|
required?: string[];
|
|
70
77
|
/** Alias of `required` (TraceContract v2 normalization). */
|
|
71
78
|
requiredTools?: string[];
|
|
@@ -74,6 +81,25 @@ interface TraceContractToolRules {
|
|
|
74
81
|
forbiddenTools?: string[];
|
|
75
82
|
allowed?: string[];
|
|
76
83
|
maxCalls?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Required tool order as adjacent first-occurrence pairs (start/encounter order).
|
|
86
|
+
*
|
|
87
|
+
* `[A, B, C]` expands to “A before B” and “B before C”, each comparing the
|
|
88
|
+
* first occurrence of the named tool. Unlisted intermediate tools are
|
|
89
|
+
* allowed. Later repetitions do not invalidate an earlier valid order.
|
|
90
|
+
*
|
|
91
|
+
* TraceContract `requiredOrder` **implies presence**: every listed name is
|
|
92
|
+
* added to the effective required-tool set. Low-level `createToolOrderingRule`
|
|
93
|
+
* alone may still pass vacuously when an endpoint is missing.
|
|
94
|
+
*
|
|
95
|
+
* This is **not** causal happens-before. Overlapping intervals emit a
|
|
96
|
+
* non-failing overlap warning. Planned modes (6.20.0, GitHub #308):
|
|
97
|
+
* `happens-before`, `all-occurrences`.
|
|
98
|
+
*
|
|
99
|
+
* @see docs/TRACE-CONTRACTS.md
|
|
100
|
+
* @beta Available through `agent-inspect/checks`. Additive changes may ship
|
|
101
|
+
* in minor releases; breaking changes require a future major.
|
|
102
|
+
*/
|
|
77
103
|
requiredOrder?: string[];
|
|
78
104
|
}
|
|
79
105
|
interface TraceContractLlmRules {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildTraceFacts, createBaselineRegressionRule, createDecisionRule, createGuardrailRule, createLlmUsageRule, createMaxStepDurationRule, createObservedOutcomeRule, createRequireCompletedRule, createRetrievalRule, createRunDepthRule, createRunDurationRule, createRunEventCountRule, createRunStatusRule, createSafetyOversizedAttributeRule, createSafetyRawContentRule, createSafetyRedactionRule, createSafetySecretPatternRule, createStallDetectionRule, createStructureCycleRule, createStructureIncompleteRule, createStructureOrphanRule, createStructureParallelWidthRule, createStructureRelationshipRule, createToolFailureRule, createToolOrderingRule, createToolUsageRule, defineTraceContract, evaluateTraceContract, evaluateTraceContractRead, projectLogicalEvents, resolveCanonicalToolName, runTraceChecks, summarizeSemanticParity } from './chunk-
|
|
1
|
+
export { buildTraceFacts, createBaselineRegressionRule, createDecisionRule, createGuardrailRule, createLlmUsageRule, createMaxStepDurationRule, createObservedOutcomeRule, createRequireCompletedRule, createRetrievalRule, createRunDepthRule, createRunDurationRule, createRunEventCountRule, createRunStatusRule, createSafetyOversizedAttributeRule, createSafetyRawContentRule, createSafetyRedactionRule, createSafetySecretPatternRule, createStallDetectionRule, createStructureCycleRule, createStructureIncompleteRule, createStructureOrphanRule, createStructureParallelWidthRule, createStructureRelationshipRule, createToolFailureRule, createToolOrderingRule, createToolUsageRule, defineTraceContract, evaluateTraceContract, evaluateTraceContractRead, projectLogicalEvents, resolveCanonicalToolName, runTraceChecks, summarizeSemanticParity } from './chunk-DIZPIPY2.mjs';
|
|
2
2
|
import './chunk-VFO76UH3.mjs';
|
|
3
3
|
import './chunk-ULCGIRTC.mjs';
|
|
4
4
|
import './chunk-VU6O5QAH.mjs';
|
|
@@ -559,10 +559,11 @@ function emptySummary() {
|
|
|
559
559
|
passed: 0,
|
|
560
560
|
failed: 0,
|
|
561
561
|
warnings: 0,
|
|
562
|
-
errors: 0
|
|
562
|
+
errors: 0,
|
|
563
|
+
rulesEvaluated: 0
|
|
563
564
|
};
|
|
564
565
|
}
|
|
565
|
-
function errorResult(input, diagnostics, selectedRun) {
|
|
566
|
+
function errorResult(input, diagnostics, selectedRun, ruleExecutions = []) {
|
|
566
567
|
return {
|
|
567
568
|
ok: false,
|
|
568
569
|
status: "error",
|
|
@@ -570,10 +571,12 @@ function errorResult(input, diagnostics, selectedRun) {
|
|
|
570
571
|
...selectedRun ? { runId: selectedRun.runId } : {},
|
|
571
572
|
summary: {
|
|
572
573
|
...emptySummary(),
|
|
573
|
-
errors: diagnostics.filter((item) => item.severity === "error").length
|
|
574
|
+
errors: diagnostics.filter((item) => item.severity === "error").length,
|
|
575
|
+
rulesEvaluated: ruleExecutions.length
|
|
574
576
|
},
|
|
575
577
|
findings: [],
|
|
576
|
-
diagnostics: [...diagnostics]
|
|
578
|
+
diagnostics: [...diagnostics],
|
|
579
|
+
ruleExecutions: [...ruleExecutions]
|
|
577
580
|
};
|
|
578
581
|
}
|
|
579
582
|
function flattenNodes(nodes) {
|
|
@@ -729,7 +732,7 @@ function normalizeFinding(rule, finding) {
|
|
|
729
732
|
...finding.action !== void 0 ? { action: finding.action } : {}
|
|
730
733
|
};
|
|
731
734
|
}
|
|
732
|
-
function summarize(findings, diagnostics) {
|
|
735
|
+
function summarize(findings, diagnostics, rulesEvaluated) {
|
|
733
736
|
return {
|
|
734
737
|
passed: findings.filter((finding) => finding.status === "pass").length,
|
|
735
738
|
failed: findings.filter(
|
|
@@ -738,9 +741,21 @@ function summarize(findings, diagnostics) {
|
|
|
738
741
|
warnings: findings.filter(
|
|
739
742
|
(finding) => finding.status === "warning" || finding.severity === "warning"
|
|
740
743
|
).length,
|
|
741
|
-
errors: diagnostics.filter((item) => item.severity === "error").length
|
|
744
|
+
errors: diagnostics.filter((item) => item.severity === "error").length,
|
|
745
|
+
rulesEvaluated
|
|
742
746
|
};
|
|
743
747
|
}
|
|
748
|
+
function classifyRuleExecution(findings, threw) {
|
|
749
|
+
if (findings.some((finding) => finding.status === "fail" && finding.severity === "error")) {
|
|
750
|
+
return "fail";
|
|
751
|
+
}
|
|
752
|
+
if (findings.some(
|
|
753
|
+
(finding) => finding.status === "warning" || finding.severity === "warning"
|
|
754
|
+
)) {
|
|
755
|
+
return "warning";
|
|
756
|
+
}
|
|
757
|
+
return "pass";
|
|
758
|
+
}
|
|
744
759
|
function stringAttr(event, keys) {
|
|
745
760
|
for (const key of keys) {
|
|
746
761
|
const value = event.attributes?.[key];
|
|
@@ -837,6 +852,9 @@ function finishedEvents(context, kind) {
|
|
|
837
852
|
(event) => (kind === void 0 || event.kind === kind) && event.status !== "running"
|
|
838
853
|
);
|
|
839
854
|
}
|
|
855
|
+
function toolInvocationEvents(context) {
|
|
856
|
+
return semanticEvents(context).filter((event) => event.kind === "TOOL");
|
|
857
|
+
}
|
|
840
858
|
function firstIndexByName(events) {
|
|
841
859
|
const index = /* @__PURE__ */ new Map();
|
|
842
860
|
for (const [position, event] of events.entries()) {
|
|
@@ -1284,7 +1302,7 @@ function createToolUsageRule(options) {
|
|
|
1284
1302
|
category: "tool",
|
|
1285
1303
|
defaultSeverity: "error",
|
|
1286
1304
|
evaluate(context) {
|
|
1287
|
-
const tools =
|
|
1305
|
+
const tools = toolInvocationEvents(context);
|
|
1288
1306
|
const names = tools.map(toolName);
|
|
1289
1307
|
const nameSet = new Set(names);
|
|
1290
1308
|
const findings = [];
|
|
@@ -1325,8 +1343,9 @@ function createToolUsageRule(options) {
|
|
|
1325
1343
|
};
|
|
1326
1344
|
}
|
|
1327
1345
|
function createToolOrderingRule(options) {
|
|
1346
|
+
const ruleId = options.id ?? "tool.order";
|
|
1328
1347
|
return {
|
|
1329
|
-
id:
|
|
1348
|
+
id: ruleId,
|
|
1330
1349
|
category: "tool",
|
|
1331
1350
|
defaultSeverity: "error",
|
|
1332
1351
|
evaluate(context) {
|
|
@@ -1334,18 +1353,42 @@ function createToolOrderingRule(options) {
|
|
|
1334
1353
|
const index = firstIndexByName(tools);
|
|
1335
1354
|
const beforeIndex = index.get(options.before);
|
|
1336
1355
|
const afterIndex = index.get(options.after);
|
|
1337
|
-
if (beforeIndex === void 0 || afterIndex === void 0
|
|
1356
|
+
if (beforeIndex === void 0 || afterIndex === void 0) {
|
|
1338
1357
|
return [];
|
|
1339
1358
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1359
|
+
if (beforeIndex >= afterIndex) {
|
|
1360
|
+
return [
|
|
1361
|
+
failFinding(
|
|
1362
|
+
ruleId,
|
|
1363
|
+
`Tool ${options.before} must appear before ${options.after}.`,
|
|
1364
|
+
[eventEvidence(tools[beforeIndex]), eventEvidence(tools[afterIndex])],
|
|
1365
|
+
{ before: options.before, after: options.after },
|
|
1366
|
+
tools.map(toolName)
|
|
1367
|
+
)
|
|
1368
|
+
];
|
|
1369
|
+
}
|
|
1370
|
+
const beforeEvent = tools[beforeIndex];
|
|
1371
|
+
const afterEvent = tools[afterIndex];
|
|
1372
|
+
const beforeEnd = eventEndMs(beforeEvent);
|
|
1373
|
+
const afterStart = eventStartMs(afterEvent);
|
|
1374
|
+
if (beforeEnd !== void 0 && afterStart !== void 0 && beforeEnd > afterStart) {
|
|
1375
|
+
return [
|
|
1376
|
+
{
|
|
1377
|
+
ruleId,
|
|
1378
|
+
severity: "warning",
|
|
1379
|
+
status: "warning",
|
|
1380
|
+
message: `Tool order ${options.before} before ${options.after} satisfied start/encounter order, but intervals overlap so causal completion before the next tool was not established.`,
|
|
1381
|
+
expected: { before: options.before, after: options.after, mode: "first-occurrence" },
|
|
1382
|
+
actual: {
|
|
1383
|
+
code: "tool.order.overlap",
|
|
1384
|
+
beforeEndedAt: beforeEvent.endedAt,
|
|
1385
|
+
afterStartedAt: afterEvent.startedAt ?? afterEvent.timestamp
|
|
1386
|
+
},
|
|
1387
|
+
evidence: [eventEvidence(beforeEvent), eventEvidence(afterEvent)]
|
|
1388
|
+
}
|
|
1389
|
+
];
|
|
1390
|
+
}
|
|
1391
|
+
return [];
|
|
1349
1392
|
}
|
|
1350
1393
|
};
|
|
1351
1394
|
}
|
|
@@ -2142,12 +2185,24 @@ function createBaselineRegressionRule(options) {
|
|
|
2142
2185
|
}
|
|
2143
2186
|
function createObservedOutcomeRule(options = {}) {
|
|
2144
2187
|
const failOn = options.failOn ?? ["failed"];
|
|
2188
|
+
const requireAny = options.requireAny === true;
|
|
2145
2189
|
return {
|
|
2146
2190
|
id: "outcome.status",
|
|
2147
2191
|
category: "run",
|
|
2148
2192
|
defaultSeverity: "error",
|
|
2149
2193
|
evaluate(context) {
|
|
2150
2194
|
const outcomes = extractOutcomesFromPersistedEvents(context.events);
|
|
2195
|
+
if (requireAny && outcomes.length === 0) {
|
|
2196
|
+
return [
|
|
2197
|
+
failFinding(
|
|
2198
|
+
"outcome.status",
|
|
2199
|
+
"Expected at least one observed outcome.",
|
|
2200
|
+
runEvidence(context.selectedRun),
|
|
2201
|
+
{ requireAny: true, expected: "at least one observed outcome" },
|
|
2202
|
+
{ code: "outcome.missing", actual: 0 }
|
|
2203
|
+
)
|
|
2204
|
+
];
|
|
2205
|
+
}
|
|
2151
2206
|
const matching = outcomesMatchingStatus(outcomes, failOn);
|
|
2152
2207
|
if (matching.length === 0) return [];
|
|
2153
2208
|
return [
|
|
@@ -2183,6 +2238,18 @@ function runTraceChecks(input, options = {}) {
|
|
|
2183
2238
|
if (rules.diagnostics.length > 0) {
|
|
2184
2239
|
return errorResult(input, rules.diagnostics, selected.run);
|
|
2185
2240
|
}
|
|
2241
|
+
if (rules.rules.length === 0) {
|
|
2242
|
+
return errorResult(
|
|
2243
|
+
input,
|
|
2244
|
+
[
|
|
2245
|
+
diagnostic(
|
|
2246
|
+
"AI_CHECK_NO_RULES_EVALUATED",
|
|
2247
|
+
"No trace check rules were evaluated. Configure at least one rule, contract, or CLI check option."
|
|
2248
|
+
)
|
|
2249
|
+
],
|
|
2250
|
+
selected.run
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2186
2253
|
const facts = buildFacts(input, selected.run);
|
|
2187
2254
|
const context = {
|
|
2188
2255
|
...facts,
|
|
@@ -2191,22 +2258,38 @@ function runTraceChecks(input, options = {}) {
|
|
|
2191
2258
|
};
|
|
2192
2259
|
const diagnostics = [];
|
|
2193
2260
|
const findings = [];
|
|
2261
|
+
const ruleExecutions = [];
|
|
2194
2262
|
for (const rule of rules.rules) {
|
|
2195
2263
|
try {
|
|
2196
|
-
|
|
2264
|
+
const ruleFindings = rule.evaluate(context).map((finding) => normalizeFinding(rule, finding));
|
|
2265
|
+
findings.push(...ruleFindings);
|
|
2266
|
+
ruleExecutions.push({
|
|
2267
|
+
ruleId: rule.id,
|
|
2268
|
+
category: rule.category,
|
|
2269
|
+
status: classifyRuleExecution(ruleFindings, false),
|
|
2270
|
+
findingCount: ruleFindings.length,
|
|
2271
|
+
...selected.run ? { runId: selected.run.runId } : {}
|
|
2272
|
+
});
|
|
2197
2273
|
} catch (error) {
|
|
2198
2274
|
const message = error instanceof Error ? error.message : String(error);
|
|
2199
2275
|
diagnostics.push(
|
|
2200
2276
|
diagnostic("AI_CHECK_INTERNAL_ERROR", `Rule ${rule.id} failed: ${message}`, rule.id)
|
|
2201
2277
|
);
|
|
2278
|
+
ruleExecutions.push({
|
|
2279
|
+
ruleId: rule.id,
|
|
2280
|
+
category: rule.category,
|
|
2281
|
+
status: "error",
|
|
2282
|
+
findingCount: 0,
|
|
2283
|
+
...selected.run ? { runId: selected.run.runId } : {}
|
|
2284
|
+
});
|
|
2202
2285
|
}
|
|
2203
2286
|
}
|
|
2204
2287
|
if (diagnostics.length > 0) {
|
|
2205
|
-
return errorResult(input, diagnostics, selected.run);
|
|
2288
|
+
return errorResult(input, diagnostics, selected.run, ruleExecutions);
|
|
2206
2289
|
}
|
|
2207
2290
|
const eventById = new Map(input.read.events.map((event) => [event.eventId, event]));
|
|
2208
2291
|
const sortedFindings = findings.sort(compareFindings(eventById));
|
|
2209
|
-
const summary = summarize(sortedFindings, diagnostics);
|
|
2292
|
+
const summary = summarize(sortedFindings, diagnostics, ruleExecutions.length);
|
|
2210
2293
|
const status = summary.failed > 0 ? "fail" : "pass";
|
|
2211
2294
|
return {
|
|
2212
2295
|
ok: status === "pass",
|
|
@@ -2215,7 +2298,8 @@ function runTraceChecks(input, options = {}) {
|
|
|
2215
2298
|
...selected.run ? { runId: selected.run.runId } : {},
|
|
2216
2299
|
summary,
|
|
2217
2300
|
findings: sortedFindings,
|
|
2218
|
-
diagnostics
|
|
2301
|
+
diagnostics,
|
|
2302
|
+
ruleExecutions
|
|
2219
2303
|
};
|
|
2220
2304
|
}
|
|
2221
2305
|
|
|
@@ -2310,9 +2394,13 @@ function contractToRules(contract) {
|
|
|
2310
2394
|
rules.push(createStructureIncompleteRule({ requireEndedAtForStarted: true }));
|
|
2311
2395
|
}
|
|
2312
2396
|
if (contract.tools) {
|
|
2397
|
+
const order = contract.tools.requiredOrder ?? [];
|
|
2313
2398
|
const required = [
|
|
2314
|
-
|
|
2315
|
-
|
|
2399
|
+
.../* @__PURE__ */ new Set([
|
|
2400
|
+
...contract.tools.required ?? [],
|
|
2401
|
+
...contract.tools.requiredTools ?? [],
|
|
2402
|
+
...order
|
|
2403
|
+
])
|
|
2316
2404
|
];
|
|
2317
2405
|
const forbidden = [
|
|
2318
2406
|
...contract.tools.forbidden ?? [],
|
|
@@ -2326,9 +2414,14 @@ function contractToRules(contract) {
|
|
|
2326
2414
|
...contract.tools.maxCalls !== void 0 ? { maxCount: contract.tools.maxCalls } : {}
|
|
2327
2415
|
})
|
|
2328
2416
|
);
|
|
2329
|
-
const order = contract.tools.requiredOrder ?? [];
|
|
2330
2417
|
for (let i = 0; i < order.length - 1; i += 1) {
|
|
2331
|
-
rules.push(
|
|
2418
|
+
rules.push(
|
|
2419
|
+
createToolOrderingRule({
|
|
2420
|
+
before: order[i],
|
|
2421
|
+
after: order[i + 1],
|
|
2422
|
+
id: `contract.tool.order.${i}`
|
|
2423
|
+
})
|
|
2424
|
+
);
|
|
2332
2425
|
}
|
|
2333
2426
|
}
|
|
2334
2427
|
if (contract.llm) {
|
|
@@ -2396,5 +2489,5 @@ function evaluateTraceContractRead(read, contract, options = {}) {
|
|
|
2396
2489
|
}
|
|
2397
2490
|
|
|
2398
2491
|
export { buildTraceFacts, createBaselineRegressionRule, createDecisionRule, createGuardrailRule, createLlmUsageRule, createMaxStepDurationRule, createObservedOutcomeRule, createRequireCompletedRule, createRetrievalRule, createRunDepthRule, createRunDurationRule, createRunEventCountRule, createRunStatusRule, createSafetyOversizedAttributeRule, createSafetyRawContentRule, createSafetyRedactionRule, createSafetySecretPatternRule, createStallDetectionRule, createStructureCycleRule, createStructureIncompleteRule, createStructureOrphanRule, createStructureParallelWidthRule, createStructureRelationshipRule, createToolFailureRule, createToolOrderingRule, createToolUsageRule, defineTraceContract, evaluateTraceContract, evaluateTraceContractRead, projectLogicalEvents, resolveCanonicalToolName, runTraceChecks, summarizeSemanticParity };
|
|
2399
|
-
//# sourceMappingURL=chunk-
|
|
2400
|
-
//# sourceMappingURL=chunk-
|
|
2492
|
+
//# sourceMappingURL=chunk-DIZPIPY2.mjs.map
|
|
2493
|
+
//# sourceMappingURL=chunk-DIZPIPY2.mjs.map
|