@tangle-network/agent-eval 0.83.0 → 0.85.0

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.
@@ -1,8 +1,9 @@
1
1
  import { c as CalibrationReport } from '../calibration-Cpr3WaX3.js';
2
2
  import { O as OffPolicyEstimate, a as OffPolicyOptions, b as OffPolicyTrajectory } from '../off-policy-DiwuKKg7.js';
3
3
  import { d as CodeAgentSessionSource, a as CodeAgentSessionIntakeOptions, c as CodeAgentSessionMetrics, C as CodeAgentSessionDiagnostic } from '../code-agent-session-BRXmavYv.js';
4
- import { R as RunRecord } from '../run-record-De9VarXR.js';
4
+ import { R as RunRecord, a as RunSplitTag } from '../run-record-De9VarXR.js';
5
5
  import { T as TraceStore } from '../store-CKUAgsJz.js';
6
+ import { R as RuntimeTrajectoryRecord, P as ProjectRuntimeTrajectoryEvidenceOptions, a as RuntimeTrajectoryEvidenceProjection } from '../runtime-trajectory-BLRiaifm.js';
6
7
  import '../schema-m0gsnbt3.js';
7
8
  import '../outcome-store-rnXLEqSn.js';
8
9
  import '../errors-Dwqw-T_m.js';
@@ -521,4 +522,83 @@ declare function runtimeDecisionPointToBeliefShadowProbeInput(point: RuntimeBeli
521
522
  declare function runtimeDecisionPointToBeliefDecisionPoint(point: RuntimeBeliefDecisionPoint, options: RuntimeBeliefDecisionPointOptions): RuntimeBeliefDecisionPointReport;
522
523
  declare function createBeliefRuntimeHookCollector(defaults: RuntimeBeliefShadowProbeInputOptions): BeliefRuntimeHookCollector;
523
524
 
524
- export { type AnalyzeBeliefDecisionCorpusOptions, type AnalyzeBeliefPolicyOpeOptions, type AnalyzeBeliefPolicyOptions, BELIEF_DECISION_KINDS, BELIEF_EVALUATION_CRITERIA, BELIEF_EVIDENCE_QUALITIES, BELIEF_EVIDENCE_SOURCES, type BeliefCalibrationOptions, type BeliefCalibrationRegion, type BeliefCalibrationStatus, type BeliefDecisionCorpusEvaluation, type BeliefDecisionExtractionDiagnostic, type BeliefDecisionExtractionReport, type BeliefDecisionInventoryBucket, type BeliefDecisionInventoryReport, type BeliefDecisionKind, type BeliefDecisionOutcome, type BeliefDecisionPoint, type BeliefDecisionReason, type BeliefDecisionReasonCode, type BeliefDecisionResearchEvidencePacket, type BeliefDecisionTargetSelection, type BeliefEvaluationCriterionId, type BeliefEvaluationStatus, type BeliefEvidenceQuality, type BeliefEvidenceRef, type BeliefEvidenceSource, type BeliefOffPolicyTrajectoryReport, type BeliefOpeOptions, type BeliefOpeReport, type BeliefOpeStatus, type BeliefOpeSupportDiagnostics, type BeliefOpeTargetPolicy, type BeliefPolicyAction, type BeliefPolicyDecision, type BeliefPolicyEvaluationReport, type BeliefResearchClaimScope, type BeliefResearchEvidenceGate, type BeliefResearchEvidenceStatus, type BeliefResearchGateId, type BeliefRuntimeHookCollector, type BeliefSelectivePolicy, type BeliefSelectivePolicyMetrics, type BeliefShadowProbeDiagnostic, type BeliefShadowProbeEvidenceRef, type BeliefShadowProbeInput, type BeliefShadowProbeRecord, type BeliefShadowProbeResponse, type BeliefShadowProbeRun, type BeliefShadowProbeSummary, type BeliefUtilityOptions, type BuildBeliefDecisionResearchEvidencePacketOptions, type BuildCodeAgentBeliefEvidenceCorpusOptions, type CodeAgentBeliefDecisionTargetId, type CodeAgentBeliefEvidenceCorpus, type CodeAgentBeliefSession, type EvaluateBeliefSelectivePolicyOptions, type ExtractBeliefDecisionPointsOptions, type ExtractCodeAgentBeliefDecisionPointsOptions, type RunBeliefShadowProbeOptions, type RuntimeBeliefConversionDiagnostic, type RuntimeBeliefDecisionEvidenceRef, type RuntimeBeliefDecisionPoint, type RuntimeBeliefDecisionPointOptions, type RuntimeBeliefDecisionPointReport, type RuntimeBeliefHookContext, type RuntimeBeliefHookEvent, type RuntimeBeliefHooks, type RuntimeBeliefShadowProbeInputOptions, type RuntimeBeliefShadowProbeInputReport, type SelectBeliefDecisionTargetOptions, analyzeBeliefDecisionCorpus, analyzeBeliefPolicy, beliefDecisionsToOffPolicyTrajectories, buildBeliefDecisionResearchEvidencePacket, buildCodeAgentBeliefEvidenceCorpus, calibrateBeliefDecisions, createBeliefRuntimeHookCollector, embeddedBeliefOpeTargetPolicy, evaluateBeliefOffPolicy, evaluateBeliefSelectivePolicy, extractBeliefDecisionPoints, extractCodeAgentBeliefDecisionPoints, formatBeliefShadowProbePrompt, inventoryBeliefDecisionPoints, isBeliefDecisionKind, isBeliefEvidenceSource, runBeliefShadowProbe, runtimeDecisionPointToBeliefDecisionPoint, runtimeDecisionPointToBeliefShadowProbeInput, selectBeliefDecisionTarget, thresholdSelectivePolicy };
525
+ interface RuntimeBeliefPhase0RunRecord {
526
+ runId: string;
527
+ scenarioId?: string;
528
+ splitTag: RunSplitTag;
529
+ }
530
+ interface RuntimeBeliefDecisionLabel {
531
+ decisionId: string;
532
+ chosenAction: string;
533
+ outcome: BeliefDecisionOutcome;
534
+ confidence?: number;
535
+ behaviorProb?: number;
536
+ targetProb?: number;
537
+ qHat?: number | null;
538
+ costUsd?: number;
539
+ splitTag?: RunSplitTag;
540
+ metadata?: Record<string, unknown>;
541
+ }
542
+ interface BuildRuntimeBeliefPhase0MeasurementOptions extends Omit<BuildBeliefDecisionResearchEvidencePacketOptions, 'points'> {
543
+ runs: RuntimeBeliefPhase0RunRecord[];
544
+ decisions: RuntimeBeliefDecisionPoint[];
545
+ events?: RuntimeBeliefHookEvent[];
546
+ labels: RuntimeBeliefDecisionLabel[];
547
+ baselinePolicyId?: string;
548
+ }
549
+ interface RuntimeBeliefPhase0MeasurementSummary {
550
+ runCount: number;
551
+ producerDecisionCount: number;
552
+ lifecycleEventCount: number;
553
+ labelCount: number;
554
+ completedPointCount: number;
555
+ runJoinRate: number;
556
+ labelJoinRate: number;
557
+ missingRunRecordCount: number;
558
+ missingLabelCount: number;
559
+ withEvidence: number;
560
+ withOutcome: number;
561
+ withSplit: number;
562
+ withBehaviorProb: number;
563
+ withTargetProb: number;
564
+ baselinePolicyId: string;
565
+ packetStatus: BeliefDecisionResearchEvidencePacket['status'];
566
+ claimScope: BeliefDecisionResearchEvidencePacket['claimScope'];
567
+ }
568
+ interface RuntimeBeliefPhase0Measurement {
569
+ points: BeliefDecisionPoint[];
570
+ packet: BeliefDecisionResearchEvidencePacket;
571
+ summary: RuntimeBeliefPhase0MeasurementSummary;
572
+ diagnostics: string[];
573
+ }
574
+ declare function buildRuntimeBeliefPhase0Measurement(options: BuildRuntimeBeliefPhase0MeasurementOptions): RuntimeBeliefPhase0Measurement;
575
+
576
+ type RuntimeBenchmarkTrajectoryRecord = RuntimeTrajectoryRecord & {
577
+ benchmark?: unknown;
578
+ condition?: unknown;
579
+ instanceId?: unknown;
580
+ runtimeDecisionPoints?: unknown;
581
+ };
582
+ interface BuildRuntimeBenchmarkBeliefPhase0MeasurementOptions extends Omit<BuildRuntimeBeliefPhase0MeasurementOptions, 'runs' | 'events' | 'decisions' | 'labels'> {
583
+ records: RuntimeBenchmarkTrajectoryRecord[];
584
+ decisions?: RuntimeBeliefDecisionPoint[];
585
+ defaultSplitTag?: ProjectRuntimeTrajectoryEvidenceOptions['defaultSplitTag'];
586
+ labels?: RuntimeBeliefDecisionLabel[];
587
+ }
588
+ interface RuntimeBenchmarkBeliefPhase0Summary {
589
+ decisionCount: number;
590
+ labelCount: number;
591
+ }
592
+ interface RuntimeBenchmarkBeliefPhase0Measurement {
593
+ runs: RuntimeBeliefPhase0RunRecord[];
594
+ events: RuntimeBeliefHookEvent[];
595
+ decisions: RuntimeBeliefDecisionPoint[];
596
+ labels: RuntimeBeliefDecisionLabel[];
597
+ trajectory: RuntimeTrajectoryEvidenceProjection;
598
+ measurement: RuntimeBeliefPhase0Measurement;
599
+ summary: RuntimeBenchmarkBeliefPhase0Summary;
600
+ diagnostics: string[];
601
+ }
602
+ declare function buildRuntimeBenchmarkBeliefPhase0Measurement(options: BuildRuntimeBenchmarkBeliefPhase0MeasurementOptions): RuntimeBenchmarkBeliefPhase0Measurement;
603
+
604
+ export { type AnalyzeBeliefDecisionCorpusOptions, type AnalyzeBeliefPolicyOpeOptions, type AnalyzeBeliefPolicyOptions, BELIEF_DECISION_KINDS, BELIEF_EVALUATION_CRITERIA, BELIEF_EVIDENCE_QUALITIES, BELIEF_EVIDENCE_SOURCES, type BeliefCalibrationOptions, type BeliefCalibrationRegion, type BeliefCalibrationStatus, type BeliefDecisionCorpusEvaluation, type BeliefDecisionExtractionDiagnostic, type BeliefDecisionExtractionReport, type BeliefDecisionInventoryBucket, type BeliefDecisionInventoryReport, type BeliefDecisionKind, type BeliefDecisionOutcome, type BeliefDecisionPoint, type BeliefDecisionReason, type BeliefDecisionReasonCode, type BeliefDecisionResearchEvidencePacket, type BeliefDecisionTargetSelection, type BeliefEvaluationCriterionId, type BeliefEvaluationStatus, type BeliefEvidenceQuality, type BeliefEvidenceRef, type BeliefEvidenceSource, type BeliefOffPolicyTrajectoryReport, type BeliefOpeOptions, type BeliefOpeReport, type BeliefOpeStatus, type BeliefOpeSupportDiagnostics, type BeliefOpeTargetPolicy, type BeliefPolicyAction, type BeliefPolicyDecision, type BeliefPolicyEvaluationReport, type BeliefResearchClaimScope, type BeliefResearchEvidenceGate, type BeliefResearchEvidenceStatus, type BeliefResearchGateId, type BeliefRuntimeHookCollector, type BeliefSelectivePolicy, type BeliefSelectivePolicyMetrics, type BeliefShadowProbeDiagnostic, type BeliefShadowProbeEvidenceRef, type BeliefShadowProbeInput, type BeliefShadowProbeRecord, type BeliefShadowProbeResponse, type BeliefShadowProbeRun, type BeliefShadowProbeSummary, type BeliefUtilityOptions, type BuildBeliefDecisionResearchEvidencePacketOptions, type BuildCodeAgentBeliefEvidenceCorpusOptions, type BuildRuntimeBeliefPhase0MeasurementOptions, type BuildRuntimeBenchmarkBeliefPhase0MeasurementOptions, type CodeAgentBeliefDecisionTargetId, type CodeAgentBeliefEvidenceCorpus, type CodeAgentBeliefSession, type EvaluateBeliefSelectivePolicyOptions, type ExtractBeliefDecisionPointsOptions, type ExtractCodeAgentBeliefDecisionPointsOptions, type RunBeliefShadowProbeOptions, type RuntimeBeliefConversionDiagnostic, type RuntimeBeliefDecisionEvidenceRef, type RuntimeBeliefDecisionLabel, type RuntimeBeliefDecisionPoint, type RuntimeBeliefDecisionPointOptions, type RuntimeBeliefDecisionPointReport, type RuntimeBeliefHookContext, type RuntimeBeliefHookEvent, type RuntimeBeliefHooks, type RuntimeBeliefPhase0Measurement, type RuntimeBeliefPhase0MeasurementSummary, type RuntimeBeliefPhase0RunRecord, type RuntimeBeliefShadowProbeInputOptions, type RuntimeBeliefShadowProbeInputReport, type RuntimeBenchmarkBeliefPhase0Measurement, type RuntimeBenchmarkBeliefPhase0Summary, type SelectBeliefDecisionTargetOptions, analyzeBeliefDecisionCorpus, analyzeBeliefPolicy, beliefDecisionsToOffPolicyTrajectories, buildBeliefDecisionResearchEvidencePacket, buildCodeAgentBeliefEvidenceCorpus, buildRuntimeBeliefPhase0Measurement, buildRuntimeBenchmarkBeliefPhase0Measurement, calibrateBeliefDecisions, createBeliefRuntimeHookCollector, embeddedBeliefOpeTargetPolicy, evaluateBeliefOffPolicy, evaluateBeliefSelectivePolicy, extractBeliefDecisionPoints, extractCodeAgentBeliefDecisionPoints, formatBeliefShadowProbePrompt, inventoryBeliefDecisionPoints, isBeliefDecisionKind, isBeliefEvidenceSource, runBeliefShadowProbe, runtimeDecisionPointToBeliefDecisionPoint, runtimeDecisionPointToBeliefShadowProbeInput, selectBeliefDecisionTarget, thresholdSelectivePolicy };
@@ -8,6 +8,9 @@ import {
8
8
  import {
9
9
  calibrationFromPairs
10
10
  } from "../chunk-NPCTHQIO.js";
11
+ import {
12
+ projectRuntimeTrajectoryEvidence
13
+ } from "../chunk-T4SQEITX.js";
11
14
  import "../chunk-VI2UW6B6.js";
12
15
  import {
13
16
  offPolicyEstimateAll
@@ -127,7 +130,7 @@ function evaluateBeliefOffPolicy(points, targetPolicy, options = {}) {
127
130
  return { targetPolicyId: targetPolicy.id, ...estimates, support };
128
131
  }
129
132
  function supportDiagnostics(estimate, options) {
130
- const ratio = estimate.n > 0 ? estimate.effectiveSampleSize / estimate.n : 0;
133
+ const ratio2 = estimate.n > 0 ? estimate.effectiveSampleSize / estimate.n : 0;
131
134
  const reasons = [...options.diagnostics];
132
135
  if (estimate.n === 0) {
133
136
  reasons.push("no valid OPE trajectories");
@@ -140,9 +143,9 @@ function supportDiagnostics(estimate, options) {
140
143
  `effective sample size ${estimate.effectiveSampleSize.toFixed(2)} below ${options.minEffectiveSampleSize}`
141
144
  );
142
145
  }
143
- if (ratio < options.minEffectiveSampleRatio) {
146
+ if (ratio2 < options.minEffectiveSampleRatio) {
144
147
  reasons.push(
145
- `effective sample ratio ${ratio.toFixed(2)} below ${options.minEffectiveSampleRatio}`
148
+ `effective sample ratio ${ratio2.toFixed(2)} below ${options.minEffectiveSampleRatio}`
146
149
  );
147
150
  }
148
151
  if (estimate.maxImportanceWeight > 10) {
@@ -153,7 +156,7 @@ function supportDiagnostics(estimate, options) {
153
156
  n: estimate.n,
154
157
  dropped: options.dropped,
155
158
  effectiveSampleSize: estimate.effectiveSampleSize,
156
- effectiveSampleRatio: ratio,
159
+ effectiveSampleRatio: ratio2,
157
160
  maxImportanceWeight: estimate.maxImportanceWeight,
158
161
  reasons
159
162
  };
@@ -1622,6 +1625,290 @@ function nonNegativeNumberOrUndefined(value) {
1622
1625
  return number !== void 0 && number >= 0 ? number : void 0;
1623
1626
  }
1624
1627
 
1628
+ // src/belief-state/phase0-measurement.ts
1629
+ var DEFAULT_BASELINE_POLICY_ID = "always-accept-observed-action";
1630
+ function buildRuntimeBeliefPhase0Measurement(options) {
1631
+ const runsById = new Map(options.runs.map((run) => [run.runId, run]));
1632
+ const labelsByDecisionId = /* @__PURE__ */ new Map();
1633
+ const diagnostics = [];
1634
+ for (const label of options.labels) {
1635
+ if (labelsByDecisionId.has(label.decisionId)) {
1636
+ diagnostics.push(`${label.decisionId}: duplicate label; using the last label`);
1637
+ }
1638
+ labelsByDecisionId.set(label.decisionId, label);
1639
+ }
1640
+ const points = [];
1641
+ let missingRunRecordCount = 0;
1642
+ let missingLabelCount = 0;
1643
+ for (const decision of options.decisions) {
1644
+ const run = runsById.get(decision.runId);
1645
+ if (!run) {
1646
+ missingRunRecordCount += 1;
1647
+ diagnostics.push(`${decision.id}: missing RunRecord join for runId ${decision.runId}`);
1648
+ continue;
1649
+ }
1650
+ const label = labelsByDecisionId.get(decision.id);
1651
+ if (!label) {
1652
+ missingLabelCount += 1;
1653
+ diagnostics.push(`${decision.id}: missing observed action/outcome label`);
1654
+ continue;
1655
+ }
1656
+ const splitTag = label.splitTag ?? run.splitTag;
1657
+ const report = runtimeDecisionPointToBeliefDecisionPoint(
1658
+ { ...decision, scenarioId: decision.scenarioId ?? run.scenarioId },
1659
+ {
1660
+ chosenAction: label.chosenAction,
1661
+ confidence: label.confidence,
1662
+ behaviorProb: label.behaviorProb,
1663
+ targetProb: label.targetProb,
1664
+ qHat: label.qHat,
1665
+ costUsd: label.costUsd,
1666
+ outcome: label.outcome,
1667
+ lifecycleEvents: options.events,
1668
+ metadata: compactMetadata2({
1669
+ baselinePolicyId: options.baselinePolicyId ?? DEFAULT_BASELINE_POLICY_ID,
1670
+ splitTag,
1671
+ ...label.metadata
1672
+ })
1673
+ }
1674
+ );
1675
+ diagnostics.push(...report.diagnostics.map((item) => `${item.decisionId}: ${item.reason}`));
1676
+ if (report.point) points.push(report.point);
1677
+ }
1678
+ const packet = buildBeliefDecisionResearchEvidencePacket({
1679
+ ...options,
1680
+ points
1681
+ });
1682
+ return {
1683
+ points,
1684
+ packet,
1685
+ summary: summarizePhase0Measurement(options, points, packet, {
1686
+ missingRunRecordCount,
1687
+ missingLabelCount
1688
+ }),
1689
+ diagnostics
1690
+ };
1691
+ }
1692
+ function summarizePhase0Measurement(options, points, packet, counts) {
1693
+ const producerDecisionCount = options.decisions.length;
1694
+ return {
1695
+ runCount: options.runs.length,
1696
+ producerDecisionCount,
1697
+ lifecycleEventCount: options.events?.length ?? 0,
1698
+ labelCount: options.labels.length,
1699
+ completedPointCount: points.length,
1700
+ runJoinRate: ratio(producerDecisionCount - counts.missingRunRecordCount, producerDecisionCount),
1701
+ labelJoinRate: ratio(points.length, producerDecisionCount),
1702
+ missingRunRecordCount: counts.missingRunRecordCount,
1703
+ missingLabelCount: counts.missingLabelCount,
1704
+ withEvidence: points.filter((point) => point.evidence.length > 0).length,
1705
+ withOutcome: points.filter((point) => point.outcome).length,
1706
+ withSplit: points.filter((point) => typeof point.metadata?.splitTag === "string").length,
1707
+ withBehaviorProb: points.filter((point) => point.behaviorProb !== void 0).length,
1708
+ withTargetProb: points.filter((point) => point.targetProb !== void 0).length,
1709
+ baselinePolicyId: options.baselinePolicyId ?? DEFAULT_BASELINE_POLICY_ID,
1710
+ packetStatus: packet.status,
1711
+ claimScope: packet.claimScope
1712
+ };
1713
+ }
1714
+ function ratio(numerator, denominator) {
1715
+ return denominator > 0 ? numerator / denominator : 0;
1716
+ }
1717
+ function compactMetadata2(values) {
1718
+ const entries = Object.entries(values).filter(([, value]) => value !== void 0);
1719
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
1720
+ }
1721
+
1722
+ // src/belief-state/runtime-benchmark-corpus.ts
1723
+ var MAX_STRING_LENGTH = 12e3;
1724
+ var MAX_CONTEXT_LENGTH = 2e4;
1725
+ var MAX_EVIDENCE_DETAIL_LENGTH = 2e3;
1726
+ var MAX_CANDIDATE_ACTIONS = 50;
1727
+ var MAX_EVIDENCE_REFS = 50;
1728
+ var MAX_METADATA_DEPTH = 4;
1729
+ var MAX_METADATA_KEYS = 100;
1730
+ var SENSITIVE_KEY_RE = /(?:authorization|api[_-]?key|token|secret|password|cookie|credential|bearer)/i;
1731
+ var SENSITIVE_VALUE_RES = [
1732
+ /\bBearer\s+[A-Za-z0-9._~+/=-]+/gi,
1733
+ /\b(?:sk|gh[pousr])_[A-Za-z0-9_]{20,}\b/g,
1734
+ /\b(?:sk|ghp|gho|ghu|ghs|ghr)-[A-Za-z0-9_-]{20,}\b/g
1735
+ ];
1736
+ var SENSITIVE_ASSIGNMENT_RE = /\b(api[_-]?key|token|secret|password|cookie)\s*[:=]\s*["']?[^"'\s,;}]+/gi;
1737
+ function buildRuntimeBenchmarkBeliefPhase0Measurement(options) {
1738
+ const diagnostics = [];
1739
+ const trajectory = projectRuntimeTrajectoryEvidence({
1740
+ records: options.records,
1741
+ defaultSplitTag: options.defaultSplitTag,
1742
+ recordIdOf: runtimeBenchmarkRecordId,
1743
+ scenarioIdOf: runtimeBenchmarkScenarioId
1744
+ });
1745
+ const decisions = options.decisions ?? runtimeBenchmarkDecisionPoints(options.records, diagnostics);
1746
+ const labels = options.labels ?? [];
1747
+ if (decisions.length === 0) {
1748
+ diagnostics.push(
1749
+ "no runtime decision points supplied or found on records; benchmark lifecycle events alone cannot produce belief decision rows"
1750
+ );
1751
+ }
1752
+ if (labels.length === 0 && decisions.length > 0) {
1753
+ diagnostics.push(
1754
+ "no decision labels supplied; observed action/outcome joins will be incomplete"
1755
+ );
1756
+ }
1757
+ const measurement = buildRuntimeBeliefPhase0Measurement({
1758
+ ...options,
1759
+ runs: trajectory.runs,
1760
+ events: trajectory.events,
1761
+ decisions,
1762
+ labels
1763
+ });
1764
+ return {
1765
+ runs: trajectory.runs,
1766
+ events: trajectory.events,
1767
+ decisions,
1768
+ labels,
1769
+ trajectory,
1770
+ measurement,
1771
+ summary: {
1772
+ decisionCount: decisions.length,
1773
+ labelCount: labels.length
1774
+ },
1775
+ diagnostics: [...trajectory.diagnostics, ...diagnostics, ...measurement.diagnostics]
1776
+ };
1777
+ }
1778
+ function runtimeBenchmarkRecordId(record2) {
1779
+ const parts = [
1780
+ nonEmptyString(record2.benchmark),
1781
+ nonEmptyString(record2.instanceId),
1782
+ nonEmptyString(record2.condition)
1783
+ ].filter((part) => part !== void 0);
1784
+ return parts.length > 0 ? parts.join(":") : void 0;
1785
+ }
1786
+ function runtimeBenchmarkScenarioId(record2) {
1787
+ return nonEmptyString(record2.instanceId);
1788
+ }
1789
+ function runtimeBenchmarkDecisionPoints(records, diagnostics) {
1790
+ const decisions = [];
1791
+ for (let recordIndex = 0; recordIndex < records.length; recordIndex += 1) {
1792
+ const record2 = records[recordIndex];
1793
+ const raw = record2.runtimeDecisionPoints;
1794
+ if (raw === void 0) continue;
1795
+ const recordId = runtimeBenchmarkRecordId(record2) ?? `record[${recordIndex}]`;
1796
+ if (!Array.isArray(raw)) {
1797
+ diagnostics.push(`${recordId}: runtimeDecisionPoints is not an array`);
1798
+ continue;
1799
+ }
1800
+ for (let pointIndex = 0; pointIndex < raw.length; pointIndex += 1) {
1801
+ const point = runtimeBenchmarkDecisionPoint(raw[pointIndex], {
1802
+ diagnostics,
1803
+ path: `${recordId}: runtimeDecisionPoints[${pointIndex}]`
1804
+ });
1805
+ if (!point) {
1806
+ diagnostics.push(
1807
+ `${recordId}: runtimeDecisionPoints[${pointIndex}] is not a RuntimeDecisionPoint`
1808
+ );
1809
+ continue;
1810
+ }
1811
+ decisions.push(point);
1812
+ }
1813
+ }
1814
+ return decisions;
1815
+ }
1816
+ function runtimeBenchmarkDecisionPoint(input, context) {
1817
+ if (!isRecord3(input)) return null;
1818
+ if (typeof input.id !== "string" || input.id.length === 0) return null;
1819
+ if (typeof input.runId !== "string" || input.runId.length === 0) return null;
1820
+ if (typeof input.stepIndex !== "number" || !Number.isInteger(input.stepIndex) || input.stepIndex < 0) {
1821
+ return null;
1822
+ }
1823
+ if (typeof input.kind !== "string" || input.kind.length === 0) return null;
1824
+ return {
1825
+ id: sanitizeString(input.id, MAX_STRING_LENGTH),
1826
+ runId: sanitizeString(input.runId, MAX_STRING_LENGTH),
1827
+ scenarioId: sanitizeOptionalString(input.scenarioId, MAX_STRING_LENGTH),
1828
+ stepIndex: input.stepIndex,
1829
+ kind: sanitizeString(input.kind, MAX_STRING_LENGTH),
1830
+ candidateActions: stringArray(input.candidateActions, {
1831
+ ...context,
1832
+ maxItems: MAX_CANDIDATE_ACTIONS,
1833
+ label: "candidateActions"
1834
+ }),
1835
+ context: sanitizeOptionalString(input.context, MAX_CONTEXT_LENGTH),
1836
+ evidence: runtimeBenchmarkEvidence(input.evidence, context),
1837
+ metadata: sanitizeMetadataRecord(input.metadata)
1838
+ };
1839
+ }
1840
+ function runtimeBenchmarkEvidence(input, context) {
1841
+ if (!Array.isArray(input)) return [];
1842
+ if (input.length > MAX_EVIDENCE_REFS) {
1843
+ context.diagnostics.push(`${context.path}: evidence truncated to ${MAX_EVIDENCE_REFS} refs`);
1844
+ }
1845
+ return input.slice(0, MAX_EVIDENCE_REFS).flatMap((item) => {
1846
+ if (!isRecord3(item)) return [];
1847
+ const source = sanitizeOptionalString(item.source, MAX_STRING_LENGTH);
1848
+ const id = sanitizeOptionalString(item.id, MAX_STRING_LENGTH);
1849
+ if (!source || !id) return [];
1850
+ return [
1851
+ {
1852
+ source,
1853
+ id,
1854
+ detail: sanitizeOptionalString(item.detail, MAX_EVIDENCE_DETAIL_LENGTH),
1855
+ metadata: sanitizeMetadataRecord(item.metadata)
1856
+ }
1857
+ ];
1858
+ });
1859
+ }
1860
+ function stringArray(input, context) {
1861
+ if (!Array.isArray(input)) return void 0;
1862
+ if (input.length > context.maxItems) {
1863
+ context.diagnostics.push(`${context.path}: ${context.label} truncated to ${context.maxItems}`);
1864
+ }
1865
+ const values = input.slice(0, context.maxItems).filter((value) => typeof value === "string" && value.length > 0).map((value) => sanitizeString(value, MAX_STRING_LENGTH));
1866
+ return values.length > 0 ? values : void 0;
1867
+ }
1868
+ function sanitizeMetadataRecord(metadata) {
1869
+ if (!isRecord3(metadata)) return void 0;
1870
+ const sanitized = sanitizeMetadata(metadata);
1871
+ if (!sanitized || typeof sanitized !== "object" || Array.isArray(sanitized)) return void 0;
1872
+ return sanitized;
1873
+ }
1874
+ function sanitizeMetadata(value, depth = 0) {
1875
+ if (value == null) return value;
1876
+ if (typeof value === "string") return sanitizeString(value, MAX_STRING_LENGTH);
1877
+ if (typeof value === "number" || typeof value === "boolean") return value;
1878
+ if (Array.isArray(value)) {
1879
+ if (depth >= MAX_METADATA_DEPTH) return "[MaxDepth]";
1880
+ return value.slice(0, MAX_METADATA_KEYS).map((item) => sanitizeMetadata(item, depth + 1));
1881
+ }
1882
+ if (!isRecord3(value)) return void 0;
1883
+ if (depth >= MAX_METADATA_DEPTH) return "[MaxDepth]";
1884
+ const sanitized = {};
1885
+ for (const [key, nested] of Object.entries(value).slice(0, MAX_METADATA_KEYS)) {
1886
+ sanitized[key] = SENSITIVE_KEY_RE.test(key) ? "[REDACTED]" : sanitizeMetadata(nested, depth + 1);
1887
+ }
1888
+ return sanitized;
1889
+ }
1890
+ function sanitizeOptionalString(value, maxLength) {
1891
+ return typeof value === "string" && value.length > 0 ? sanitizeString(value, maxLength) : void 0;
1892
+ }
1893
+ function sanitizeString(value, maxLength) {
1894
+ let sanitized = value;
1895
+ for (const pattern of SENSITIVE_VALUE_RES) {
1896
+ sanitized = sanitized.replace(pattern, "[REDACTED]");
1897
+ }
1898
+ sanitized = sanitized.replace(
1899
+ SENSITIVE_ASSIGNMENT_RE,
1900
+ (_match, key) => `${key}=[REDACTED]`
1901
+ );
1902
+ if (sanitized.length <= maxLength) return sanitized;
1903
+ return sanitized.slice(0, maxLength);
1904
+ }
1905
+ function isRecord3(value) {
1906
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1907
+ }
1908
+ function nonEmptyString(value) {
1909
+ return typeof value === "string" && value.length > 0 ? value : void 0;
1910
+ }
1911
+
1625
1912
  // src/belief-state/shadow-probe.ts
1626
1913
  var DEFAULT_CONCURRENCY = 4;
1627
1914
  var DEFAULT_MAX_CONTEXT_CHARS2 = 12e3;
@@ -1842,6 +2129,8 @@ export {
1842
2129
  beliefDecisionsToOffPolicyTrajectories,
1843
2130
  buildBeliefDecisionResearchEvidencePacket,
1844
2131
  buildCodeAgentBeliefEvidenceCorpus,
2132
+ buildRuntimeBeliefPhase0Measurement,
2133
+ buildRuntimeBenchmarkBeliefPhase0Measurement,
1845
2134
  calibrateBeliefDecisions,
1846
2135
  createBeliefRuntimeHookCollector,
1847
2136
  embeddedBeliefOpeTargetPolicy,