@mnemom/agent-alignment-protocol 0.5.0 → 0.6.1

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/README.md CHANGED
@@ -75,7 +75,7 @@ A structured declaration of an agent's alignment posture:
75
75
 
76
76
  ```json
77
77
  {
78
- "aap_version": "0.1.0",
78
+ "aap_version": "0.5.0",
79
79
  "agent_id": "did:web:my-agent.example.com",
80
80
  "principal": {
81
81
  "type": "human",
package/dist/index.d.mts CHANGED
@@ -501,6 +501,76 @@ interface FleetCoherenceResult {
501
501
  /** Per-agent coherence summaries */
502
502
  agent_summaries: AgentCoherenceSummary[];
503
503
  }
504
+ /** Classification of a fault line's nature. */
505
+ type FaultLineClassification = 'resolvable' | 'priority_mismatch' | 'incompatible' | 'complementary';
506
+ /** A single fault line — a value dimension that splits the fleet. */
507
+ interface FaultLine {
508
+ /** Deterministic ID for this fault line */
509
+ id: string;
510
+ /** The value in question */
511
+ value: string;
512
+ /** How the fault line is classified */
513
+ classification: FaultLineClassification;
514
+ /** Severity based on impact_score */
515
+ severity: Severity;
516
+ /** Agent IDs that declare this value */
517
+ agents_declaring: string[];
518
+ /** Agent IDs missing this value */
519
+ agents_missing: string[];
520
+ /** Agent IDs whose conflicts_with includes this value */
521
+ agents_conflicting: string[];
522
+ /** Weighted impact score (0.0 to 1.0) */
523
+ impact_score: number;
524
+ /** Plain-English resolution hint */
525
+ resolution_hint: string;
526
+ /** Bounded actions shared by all involved agents */
527
+ affects_capabilities: string[];
528
+ }
529
+ /** Aggregated summary of fault lines by classification. */
530
+ interface FaultLineSummary {
531
+ /** Total number of fault lines */
532
+ total: number;
533
+ /** Count of resolvable fault lines */
534
+ resolvable: number;
535
+ /** Count of priority_mismatch fault lines */
536
+ priority_mismatch: number;
537
+ /** Count of incompatible fault lines */
538
+ incompatible: number;
539
+ /** Count of complementary fault lines */
540
+ complementary: number;
541
+ /** Count of critical-severity fault lines */
542
+ critical_count: number;
543
+ }
544
+ /** A pattern where the same set of agents is consistently isolated across multiple fault lines. */
545
+ interface FaultLineAlignment {
546
+ /** Deterministic ID */
547
+ id: string;
548
+ /** IDs of the fault lines that form this alignment */
549
+ fault_line_ids: string[];
550
+ /** Agents consistently missing from this group of fault lines */
551
+ minority_agents: string[];
552
+ /** Agents consistently declaring this group of fault lines */
553
+ majority_agents: string[];
554
+ /** Mean Jaccard similarity within the alignment group */
555
+ alignment_score: number;
556
+ /** Severity of the alignment pattern */
557
+ severity: Severity;
558
+ /** Human-readable description */
559
+ description: string;
560
+ }
561
+ /** Full fault line analysis result. */
562
+ interface FaultLineAnalysis {
563
+ /** Deterministic analysis identifier */
564
+ analysis_id: string;
565
+ /** Fleet coherence score (from FleetCoherenceResult) */
566
+ fleet_score: number;
567
+ /** Detected fault lines, sorted by severity then impact_score desc */
568
+ fault_lines: FaultLine[];
569
+ /** Detected alignment patterns */
570
+ alignments: FaultLineAlignment[];
571
+ /** Counts by classification */
572
+ summary: FaultLineSummary;
573
+ }
504
574
 
505
575
  /**
506
576
  * AAP Verification API - The three public entry points.
@@ -586,6 +656,38 @@ declare function checkFleetCoherence(cards: Array<{
586
656
  * @returns List of DriftAlert objects for detected drift events
587
657
  */
588
658
  declare function detectDrift(card: AlignmentCard, traces: APTrace[], similarityThreshold?: number, sustainedThreshold?: number): DriftAlert[];
659
+ /**
660
+ * Analyze fault lines in a fleet based on a FleetCoherenceResult.
661
+ *
662
+ * @param coherenceResult - Result from checkFleetCoherence
663
+ * @param cards - Same agent cards passed to checkFleetCoherence
664
+ * @param options - Optional reputationScores and taskContext
665
+ * @returns FaultLineAnalysis with fault lines and alignment patterns
666
+ */
667
+ declare function analyzeFaultLines(coherenceResult: FleetCoherenceResult, cards: Array<{
668
+ agentId: string;
669
+ card: AlignmentCard;
670
+ }>, options?: {
671
+ reputationScores?: Record<string, number>;
672
+ taskContext?: string;
673
+ }): FaultLineAnalysis;
674
+ /**
675
+ * Convenience wrapper: run fleet coherence then fault line analysis in one call.
676
+ *
677
+ * @param cards - Array of agent cards
678
+ * @param options - Optional reputationScores and taskContext
679
+ * @returns Both FleetCoherenceResult and FaultLineAnalysis
680
+ */
681
+ declare function checkFleetFaultLines(cards: Array<{
682
+ agentId: string;
683
+ card: AlignmentCard;
684
+ }>, options?: {
685
+ reputationScores?: Record<string, number>;
686
+ taskContext?: string;
687
+ }): {
688
+ coherence: FleetCoherenceResult;
689
+ analysis: FaultLineAnalysis;
690
+ };
589
691
 
590
692
  /**
591
693
  * Value Coherence Handshake messages - Agent-to-agent alignment verification.
@@ -857,4 +959,4 @@ declare const EU_COMPLIANCE_EXTENSIONS: {
857
959
  /** Recommended declared values for Article 50 transparency obligations. */
858
960
  declare const EU_COMPLIANCE_VALUES: readonly ["transparency", "honesty", "user_control", "principal_benefit"];
859
961
 
860
- export { ALGORITHM_VERSION, type APTrace, type Action, type ActionCategory, type ActionTarget, type ActionType, type AgentCoherenceSummary, type AlignmentCard, type AlignmentCardRequest, type AlignmentCardResponse, type Alternative, type AuditCommitment, type AuditStorage, type AutonomyEnvelope, type AutonomyScope, CLUSTER_COMPATIBILITY_THRESHOLD, CONFLICT_PENALTY_MULTIPLIER, type Coherence, type CoherenceResult, type CoherenceResultMessage, DEFAULT_SIMILARITY_THRESHOLD, DEFAULT_SUSTAINED_TURNS_THRESHOLD, type DataSharing, type Decision, type DriftAlert, type DriftAnalysis, type DriftDirection, type DriftIndicator, EU_COMPLIANCE_AUDIT_COMMITMENT, EU_COMPLIANCE_EXTENSIONS, EU_COMPLIANCE_VALUES, type Escalation, type EscalationStatus, type EscalationTrigger, type FleetCluster, type FleetCoherenceResult, type FleetOutlier, type HierarchyType, MAX_TFIDF_FEATURES, MIN_COHERENCE_FOR_PROCEED, MIN_WORD_LENGTH, type MonetaryValue, NEAR_BOUNDARY_THRESHOLD, OUTLIER_STD_DEV_THRESHOLD, type PairwiseEntry, type Principal, type PrincipalResponse, type PrincipalType, type ProposedCollaboration, type ProposedResolution, type RelationshipType, type RequesterInfo, type Severity, type Signature, type StorageType, type TamperEvidence, type TaskContext, type TraceContext, type TriggerAction, type TriggerCheck, VIOLATION_SEVERITY, type ValueAlignment, type ValueAlignmentDetail, type ValueCoherenceCheck, type ValueCoherenceMessage, type ValueConflict, type ValueConflictResult, type ValueDefinition, type ValueDivergence, type Values, type VerificationMetadata, type VerificationResult, type Violation, type ViolationType, type Warning, checkCoherence, checkFleetCoherence, computeCentroid, cosineSimilarity, createViolation, detectDrift, extractCardFeatures, extractTraceFeatures, getSelectedAlternative, hadViolations, hasValue, isActionBounded, isActionForbidden, isCardExpired, verifyTrace, wasEscalated };
962
+ export { ALGORITHM_VERSION, type APTrace, type Action, type ActionCategory, type ActionTarget, type ActionType, type AgentCoherenceSummary, type AlignmentCard, type AlignmentCardRequest, type AlignmentCardResponse, type Alternative, type AuditCommitment, type AuditStorage, type AutonomyEnvelope, type AutonomyScope, CLUSTER_COMPATIBILITY_THRESHOLD, CONFLICT_PENALTY_MULTIPLIER, type Coherence, type CoherenceResult, type CoherenceResultMessage, DEFAULT_SIMILARITY_THRESHOLD, DEFAULT_SUSTAINED_TURNS_THRESHOLD, type DataSharing, type Decision, type DriftAlert, type DriftAnalysis, type DriftDirection, type DriftIndicator, EU_COMPLIANCE_AUDIT_COMMITMENT, EU_COMPLIANCE_EXTENSIONS, EU_COMPLIANCE_VALUES, type Escalation, type EscalationStatus, type EscalationTrigger, type FaultLine, type FaultLineAlignment, type FaultLineAnalysis, type FaultLineClassification, type FaultLineSummary, type FleetCluster, type FleetCoherenceResult, type FleetOutlier, type HierarchyType, MAX_TFIDF_FEATURES, MIN_COHERENCE_FOR_PROCEED, MIN_WORD_LENGTH, type MonetaryValue, NEAR_BOUNDARY_THRESHOLD, OUTLIER_STD_DEV_THRESHOLD, type PairwiseEntry, type Principal, type PrincipalResponse, type PrincipalType, type ProposedCollaboration, type ProposedResolution, type RelationshipType, type RequesterInfo, type Severity, type Signature, type StorageType, type TamperEvidence, type TaskContext, type TraceContext, type TriggerAction, type TriggerCheck, VIOLATION_SEVERITY, type ValueAlignment, type ValueAlignmentDetail, type ValueCoherenceCheck, type ValueCoherenceMessage, type ValueConflict, type ValueConflictResult, type ValueDefinition, type ValueDivergence, type Values, type VerificationMetadata, type VerificationResult, type Violation, type ViolationType, type Warning, analyzeFaultLines, checkCoherence, checkFleetCoherence, checkFleetFaultLines, computeCentroid, cosineSimilarity, createViolation, detectDrift, extractCardFeatures, extractTraceFeatures, getSelectedAlternative, hadViolations, hasValue, isActionBounded, isActionForbidden, isCardExpired, verifyTrace, wasEscalated };
package/dist/index.d.ts CHANGED
@@ -501,6 +501,76 @@ interface FleetCoherenceResult {
501
501
  /** Per-agent coherence summaries */
502
502
  agent_summaries: AgentCoherenceSummary[];
503
503
  }
504
+ /** Classification of a fault line's nature. */
505
+ type FaultLineClassification = 'resolvable' | 'priority_mismatch' | 'incompatible' | 'complementary';
506
+ /** A single fault line — a value dimension that splits the fleet. */
507
+ interface FaultLine {
508
+ /** Deterministic ID for this fault line */
509
+ id: string;
510
+ /** The value in question */
511
+ value: string;
512
+ /** How the fault line is classified */
513
+ classification: FaultLineClassification;
514
+ /** Severity based on impact_score */
515
+ severity: Severity;
516
+ /** Agent IDs that declare this value */
517
+ agents_declaring: string[];
518
+ /** Agent IDs missing this value */
519
+ agents_missing: string[];
520
+ /** Agent IDs whose conflicts_with includes this value */
521
+ agents_conflicting: string[];
522
+ /** Weighted impact score (0.0 to 1.0) */
523
+ impact_score: number;
524
+ /** Plain-English resolution hint */
525
+ resolution_hint: string;
526
+ /** Bounded actions shared by all involved agents */
527
+ affects_capabilities: string[];
528
+ }
529
+ /** Aggregated summary of fault lines by classification. */
530
+ interface FaultLineSummary {
531
+ /** Total number of fault lines */
532
+ total: number;
533
+ /** Count of resolvable fault lines */
534
+ resolvable: number;
535
+ /** Count of priority_mismatch fault lines */
536
+ priority_mismatch: number;
537
+ /** Count of incompatible fault lines */
538
+ incompatible: number;
539
+ /** Count of complementary fault lines */
540
+ complementary: number;
541
+ /** Count of critical-severity fault lines */
542
+ critical_count: number;
543
+ }
544
+ /** A pattern where the same set of agents is consistently isolated across multiple fault lines. */
545
+ interface FaultLineAlignment {
546
+ /** Deterministic ID */
547
+ id: string;
548
+ /** IDs of the fault lines that form this alignment */
549
+ fault_line_ids: string[];
550
+ /** Agents consistently missing from this group of fault lines */
551
+ minority_agents: string[];
552
+ /** Agents consistently declaring this group of fault lines */
553
+ majority_agents: string[];
554
+ /** Mean Jaccard similarity within the alignment group */
555
+ alignment_score: number;
556
+ /** Severity of the alignment pattern */
557
+ severity: Severity;
558
+ /** Human-readable description */
559
+ description: string;
560
+ }
561
+ /** Full fault line analysis result. */
562
+ interface FaultLineAnalysis {
563
+ /** Deterministic analysis identifier */
564
+ analysis_id: string;
565
+ /** Fleet coherence score (from FleetCoherenceResult) */
566
+ fleet_score: number;
567
+ /** Detected fault lines, sorted by severity then impact_score desc */
568
+ fault_lines: FaultLine[];
569
+ /** Detected alignment patterns */
570
+ alignments: FaultLineAlignment[];
571
+ /** Counts by classification */
572
+ summary: FaultLineSummary;
573
+ }
504
574
 
505
575
  /**
506
576
  * AAP Verification API - The three public entry points.
@@ -586,6 +656,38 @@ declare function checkFleetCoherence(cards: Array<{
586
656
  * @returns List of DriftAlert objects for detected drift events
587
657
  */
588
658
  declare function detectDrift(card: AlignmentCard, traces: APTrace[], similarityThreshold?: number, sustainedThreshold?: number): DriftAlert[];
659
+ /**
660
+ * Analyze fault lines in a fleet based on a FleetCoherenceResult.
661
+ *
662
+ * @param coherenceResult - Result from checkFleetCoherence
663
+ * @param cards - Same agent cards passed to checkFleetCoherence
664
+ * @param options - Optional reputationScores and taskContext
665
+ * @returns FaultLineAnalysis with fault lines and alignment patterns
666
+ */
667
+ declare function analyzeFaultLines(coherenceResult: FleetCoherenceResult, cards: Array<{
668
+ agentId: string;
669
+ card: AlignmentCard;
670
+ }>, options?: {
671
+ reputationScores?: Record<string, number>;
672
+ taskContext?: string;
673
+ }): FaultLineAnalysis;
674
+ /**
675
+ * Convenience wrapper: run fleet coherence then fault line analysis in one call.
676
+ *
677
+ * @param cards - Array of agent cards
678
+ * @param options - Optional reputationScores and taskContext
679
+ * @returns Both FleetCoherenceResult and FaultLineAnalysis
680
+ */
681
+ declare function checkFleetFaultLines(cards: Array<{
682
+ agentId: string;
683
+ card: AlignmentCard;
684
+ }>, options?: {
685
+ reputationScores?: Record<string, number>;
686
+ taskContext?: string;
687
+ }): {
688
+ coherence: FleetCoherenceResult;
689
+ analysis: FaultLineAnalysis;
690
+ };
589
691
 
590
692
  /**
591
693
  * Value Coherence Handshake messages - Agent-to-agent alignment verification.
@@ -857,4 +959,4 @@ declare const EU_COMPLIANCE_EXTENSIONS: {
857
959
  /** Recommended declared values for Article 50 transparency obligations. */
858
960
  declare const EU_COMPLIANCE_VALUES: readonly ["transparency", "honesty", "user_control", "principal_benefit"];
859
961
 
860
- export { ALGORITHM_VERSION, type APTrace, type Action, type ActionCategory, type ActionTarget, type ActionType, type AgentCoherenceSummary, type AlignmentCard, type AlignmentCardRequest, type AlignmentCardResponse, type Alternative, type AuditCommitment, type AuditStorage, type AutonomyEnvelope, type AutonomyScope, CLUSTER_COMPATIBILITY_THRESHOLD, CONFLICT_PENALTY_MULTIPLIER, type Coherence, type CoherenceResult, type CoherenceResultMessage, DEFAULT_SIMILARITY_THRESHOLD, DEFAULT_SUSTAINED_TURNS_THRESHOLD, type DataSharing, type Decision, type DriftAlert, type DriftAnalysis, type DriftDirection, type DriftIndicator, EU_COMPLIANCE_AUDIT_COMMITMENT, EU_COMPLIANCE_EXTENSIONS, EU_COMPLIANCE_VALUES, type Escalation, type EscalationStatus, type EscalationTrigger, type FleetCluster, type FleetCoherenceResult, type FleetOutlier, type HierarchyType, MAX_TFIDF_FEATURES, MIN_COHERENCE_FOR_PROCEED, MIN_WORD_LENGTH, type MonetaryValue, NEAR_BOUNDARY_THRESHOLD, OUTLIER_STD_DEV_THRESHOLD, type PairwiseEntry, type Principal, type PrincipalResponse, type PrincipalType, type ProposedCollaboration, type ProposedResolution, type RelationshipType, type RequesterInfo, type Severity, type Signature, type StorageType, type TamperEvidence, type TaskContext, type TraceContext, type TriggerAction, type TriggerCheck, VIOLATION_SEVERITY, type ValueAlignment, type ValueAlignmentDetail, type ValueCoherenceCheck, type ValueCoherenceMessage, type ValueConflict, type ValueConflictResult, type ValueDefinition, type ValueDivergence, type Values, type VerificationMetadata, type VerificationResult, type Violation, type ViolationType, type Warning, checkCoherence, checkFleetCoherence, computeCentroid, cosineSimilarity, createViolation, detectDrift, extractCardFeatures, extractTraceFeatures, getSelectedAlternative, hadViolations, hasValue, isActionBounded, isActionForbidden, isCardExpired, verifyTrace, wasEscalated };
962
+ export { ALGORITHM_VERSION, type APTrace, type Action, type ActionCategory, type ActionTarget, type ActionType, type AgentCoherenceSummary, type AlignmentCard, type AlignmentCardRequest, type AlignmentCardResponse, type Alternative, type AuditCommitment, type AuditStorage, type AutonomyEnvelope, type AutonomyScope, CLUSTER_COMPATIBILITY_THRESHOLD, CONFLICT_PENALTY_MULTIPLIER, type Coherence, type CoherenceResult, type CoherenceResultMessage, DEFAULT_SIMILARITY_THRESHOLD, DEFAULT_SUSTAINED_TURNS_THRESHOLD, type DataSharing, type Decision, type DriftAlert, type DriftAnalysis, type DriftDirection, type DriftIndicator, EU_COMPLIANCE_AUDIT_COMMITMENT, EU_COMPLIANCE_EXTENSIONS, EU_COMPLIANCE_VALUES, type Escalation, type EscalationStatus, type EscalationTrigger, type FaultLine, type FaultLineAlignment, type FaultLineAnalysis, type FaultLineClassification, type FaultLineSummary, type FleetCluster, type FleetCoherenceResult, type FleetOutlier, type HierarchyType, MAX_TFIDF_FEATURES, MIN_COHERENCE_FOR_PROCEED, MIN_WORD_LENGTH, type MonetaryValue, NEAR_BOUNDARY_THRESHOLD, OUTLIER_STD_DEV_THRESHOLD, type PairwiseEntry, type Principal, type PrincipalResponse, type PrincipalType, type ProposedCollaboration, type ProposedResolution, type RelationshipType, type RequesterInfo, type Severity, type Signature, type StorageType, type TamperEvidence, type TaskContext, type TraceContext, type TriggerAction, type TriggerCheck, VIOLATION_SEVERITY, type ValueAlignment, type ValueAlignmentDetail, type ValueCoherenceCheck, type ValueCoherenceMessage, type ValueConflict, type ValueConflictResult, type ValueDefinition, type ValueDivergence, type Values, type VerificationMetadata, type VerificationResult, type Violation, type ViolationType, type Warning, analyzeFaultLines, checkCoherence, checkFleetCoherence, checkFleetFaultLines, computeCentroid, cosineSimilarity, createViolation, detectDrift, extractCardFeatures, extractTraceFeatures, getSelectedAlternative, hadViolations, hasValue, isActionBounded, isActionForbidden, isCardExpired, verifyTrace, wasEscalated };
package/dist/index.js CHANGED
@@ -34,8 +34,10 @@ __export(index_exports, {
34
34
  NEAR_BOUNDARY_THRESHOLD: () => NEAR_BOUNDARY_THRESHOLD,
35
35
  OUTLIER_STD_DEV_THRESHOLD: () => OUTLIER_STD_DEV_THRESHOLD,
36
36
  VIOLATION_SEVERITY: () => VIOLATION_SEVERITY,
37
+ analyzeFaultLines: () => analyzeFaultLines,
37
38
  checkCoherence: () => checkCoherence,
38
39
  checkFleetCoherence: () => checkFleetCoherence,
40
+ checkFleetFaultLines: () => checkFleetFaultLines,
39
41
  computeCentroid: () => computeCentroid,
40
42
  cosineSimilarity: () => cosineSimilarity,
41
43
  createViolation: () => createViolation,
@@ -710,6 +712,297 @@ function detectDrift(card, traces, similarityThreshold = DEFAULT_SIMILARITY_THRE
710
712
  }
711
713
  return alerts;
712
714
  }
715
+ function deterministicHex(input, length) {
716
+ let hash = 0;
717
+ for (let i = 0; i < input.length; i++) {
718
+ const char = input.charCodeAt(i);
719
+ hash = (hash << 5) - hash + char;
720
+ hash = hash & hash;
721
+ }
722
+ return Math.abs(hash).toString(16).padStart(length, "0").slice(0, length);
723
+ }
724
+ function jaccardSimilarity(a, b) {
725
+ const setA = new Set(a);
726
+ const setB = new Set(b);
727
+ const intersection = [...setA].filter((x) => setB.has(x)).length;
728
+ const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
729
+ return union === 0 ? 0 : intersection / union;
730
+ }
731
+ var ROLE_KEYWORDS = [
732
+ "safety",
733
+ "executive",
734
+ "cfo",
735
+ "analyst",
736
+ "compliance",
737
+ "legal",
738
+ "risk",
739
+ "finance",
740
+ "security",
741
+ "ethics",
742
+ "audit",
743
+ "ops",
744
+ "operations"
745
+ ];
746
+ function hasRoleKeyword(agentId) {
747
+ const lower = agentId.toLowerCase();
748
+ return ROLE_KEYWORDS.some((kw) => lower.includes(kw));
749
+ }
750
+ function getClpiRole(card) {
751
+ const ext = card.extensions;
752
+ if (!ext) return null;
753
+ const clpi = ext["clpi"];
754
+ if (!clpi || typeof clpi["role"] !== "string") return null;
755
+ return clpi["role"] || null;
756
+ }
757
+ function analyzeFaultLines(coherenceResult, cards, options) {
758
+ const reputationScores = options?.reputationScores;
759
+ const agentBoundedActions = /* @__PURE__ */ new Map();
760
+ for (const { agentId, card } of cards) {
761
+ agentBoundedActions.set(agentId, card.autonomy_envelope?.bounded_actions ?? []);
762
+ }
763
+ const agentConflictMap = /* @__PURE__ */ new Map();
764
+ for (const { agentId, card } of cards) {
765
+ agentConflictMap.set(agentId, new Set(card.values.conflicts_with ?? []));
766
+ }
767
+ const agentRoleMap = /* @__PURE__ */ new Map();
768
+ for (const { agentId, card } of cards) {
769
+ agentRoleMap.set(agentId, getClpiRole(card));
770
+ }
771
+ const faultLines = [];
772
+ for (const divergence of coherenceResult.divergence_report) {
773
+ const {
774
+ value,
775
+ agents_declaring,
776
+ agents_missing,
777
+ agents_conflicting,
778
+ impact_on_fleet_score
779
+ } = divergence;
780
+ const involvedAgents = [
781
+ .../* @__PURE__ */ new Set([...agents_declaring, ...agents_missing, ...agents_conflicting])
782
+ ];
783
+ let classification;
784
+ if (agents_conflicting.length > 0) {
785
+ classification = "incompatible";
786
+ } else if (agents_declaring.length >= 2 && (() => {
787
+ for (let i = 0; i < agents_declaring.length; i++) {
788
+ for (let j = i + 1; j < agents_declaring.length; j++) {
789
+ const idA = agents_declaring[i];
790
+ const idB = agents_declaring[j];
791
+ const entry = coherenceResult.pairwise_matrix.find(
792
+ (p) => p.agent_a === idA && p.agent_b === idB || p.agent_a === idB && p.agent_b === idA
793
+ );
794
+ if (entry && entry.result.score < 0.5) {
795
+ return true;
796
+ }
797
+ }
798
+ }
799
+ return false;
800
+ })()) {
801
+ classification = "priority_mismatch";
802
+ } else if (agents_declaring.length >= 1 && agents_missing.length >= 1 && (() => {
803
+ const declaringRoles = new Set(agents_declaring.map((id2) => agentRoleMap.get(id2) ?? null).filter(Boolean));
804
+ const missingRoles = new Set(agents_missing.map((id2) => agentRoleMap.get(id2) ?? null).filter(Boolean));
805
+ if (declaringRoles.size > 0) {
806
+ const declaringRoleArr = [...declaringRoles];
807
+ const isRoleExclusive = declaringRoleArr.every((role) => !missingRoles.has(role));
808
+ if (isRoleExclusive) return true;
809
+ }
810
+ const allInvolved = [...agents_declaring, ...agents_missing];
811
+ return allInvolved.some((id2) => hasRoleKeyword(id2));
812
+ })()) {
813
+ classification = "complementary";
814
+ } else {
815
+ classification = "resolvable";
816
+ }
817
+ let coordinationOverlap;
818
+ if (involvedAgents.length < 2) {
819
+ coordinationOverlap = 0.5;
820
+ } else {
821
+ const actionSets = involvedAgents.map((id2) => agentBoundedActions.get(id2) ?? []);
822
+ const nonEmpty = actionSets.filter((s) => s.length > 0);
823
+ if (nonEmpty.length < 2) {
824
+ coordinationOverlap = 0.5;
825
+ } else {
826
+ let total = 0;
827
+ let count = 0;
828
+ for (let i = 0; i < nonEmpty.length; i++) {
829
+ for (let j = i + 1; j < nonEmpty.length; j++) {
830
+ total += jaccardSimilarity(nonEmpty[i], nonEmpty[j]);
831
+ count++;
832
+ }
833
+ }
834
+ coordinationOverlap = count > 0 ? total / count : 0.5;
835
+ }
836
+ }
837
+ let impactScore = impact_on_fleet_score * coordinationOverlap;
838
+ if (reputationScores && involvedAgents.length > 0) {
839
+ const repValues = involvedAgents.map((id2) => (reputationScores[id2] ?? 500) / 1e3).map((r) => Math.max(1e-3, r));
840
+ const logSum = repValues.reduce((sum, r) => sum + Math.log(r), 0);
841
+ const geoMean = Math.exp(logSum / repValues.length);
842
+ impactScore *= geoMean;
843
+ }
844
+ impactScore = Math.min(1, Math.max(0, impactScore));
845
+ let severity;
846
+ if (impactScore >= 0.7) {
847
+ severity = "critical";
848
+ } else if (impactScore >= 0.4) {
849
+ severity = "high";
850
+ } else if (impactScore >= 0.2) {
851
+ severity = "medium";
852
+ } else {
853
+ severity = "low";
854
+ }
855
+ let resolutionHint;
856
+ switch (classification) {
857
+ case "resolvable":
858
+ resolutionHint = `Add value '${value}' to ${agents_missing.join(", ")} alignment card(s).`;
859
+ break;
860
+ case "priority_mismatch":
861
+ resolutionHint = `Align priority/definition of '${value}' across all declaring agents.`;
862
+ break;
863
+ case "incompatible":
864
+ resolutionHint = `Value '${value}' conflicts with ${agents_conflicting.join(", ")}. Requires human review.`;
865
+ break;
866
+ case "complementary":
867
+ resolutionHint = `Value '${value}' divergence appears intentional given agent specializations.`;
868
+ break;
869
+ }
870
+ let affectsCapabilities = [];
871
+ if (involvedAgents.length > 0) {
872
+ const firstActions = agentBoundedActions.get(involvedAgents[0]) ?? [];
873
+ affectsCapabilities = firstActions.filter(
874
+ (action) => involvedAgents.every((id2) => (agentBoundedActions.get(id2) ?? []).includes(action))
875
+ );
876
+ }
877
+ const idInput = [value, ...involvedAgents.sort()].join("|");
878
+ const id = deterministicHex(idInput, 12);
879
+ faultLines.push({
880
+ id,
881
+ value,
882
+ classification,
883
+ severity,
884
+ agents_declaring,
885
+ agents_missing,
886
+ agents_conflicting,
887
+ impact_score: Math.round(impactScore * 1e4) / 1e4,
888
+ resolution_hint: resolutionHint,
889
+ affects_capabilities: affectsCapabilities
890
+ });
891
+ }
892
+ const severityOrder = {
893
+ critical: 0,
894
+ high: 1,
895
+ medium: 2,
896
+ low: 3
897
+ };
898
+ faultLines.sort((a, b) => {
899
+ const sev = severityOrder[a.severity] - severityOrder[b.severity];
900
+ if (sev !== 0) return sev;
901
+ return b.impact_score - a.impact_score;
902
+ });
903
+ const alignments = [];
904
+ const grouped = /* @__PURE__ */ new Map();
905
+ const groupAssignment = /* @__PURE__ */ new Map();
906
+ let nextGroupId = 0;
907
+ for (let i = 0; i < faultLines.length; i++) {
908
+ for (let j = i + 1; j < faultLines.length; j++) {
909
+ const sim = jaccardSimilarity(faultLines[i].agents_missing, faultLines[j].agents_missing);
910
+ if (sim > 0.6) {
911
+ const gi = groupAssignment.get(i);
912
+ const gj = groupAssignment.get(j);
913
+ if (gi === void 0 && gj === void 0) {
914
+ const gid = nextGroupId++;
915
+ grouped.set(gid, [i, j]);
916
+ groupAssignment.set(i, gid);
917
+ groupAssignment.set(j, gid);
918
+ } else if (gi !== void 0 && gj === void 0) {
919
+ grouped.get(gi).push(j);
920
+ groupAssignment.set(j, gi);
921
+ } else if (gi === void 0 && gj !== void 0) {
922
+ grouped.get(gj).push(i);
923
+ groupAssignment.set(i, gj);
924
+ } else if (gi !== gj) {
925
+ const smaller = gi < gj ? gj : gi;
926
+ const larger = gi < gj ? gi : gj;
927
+ const smallerMembers = grouped.get(smaller) ?? [];
928
+ const largerMembers = grouped.get(larger) ?? [];
929
+ const merged = [.../* @__PURE__ */ new Set([...largerMembers, ...smallerMembers])];
930
+ grouped.set(larger, merged);
931
+ grouped.delete(smaller);
932
+ for (const idx of smallerMembers) {
933
+ groupAssignment.set(idx, larger);
934
+ }
935
+ }
936
+ }
937
+ }
938
+ }
939
+ for (const [, members] of grouped) {
940
+ if (members.length < 2) continue;
941
+ const unique = [...new Set(members)];
942
+ const groupFaultLines = unique.map((i) => faultLines[i]);
943
+ const minorityAgents = [
944
+ ...new Set(groupFaultLines.flatMap((fl) => fl.agents_missing))
945
+ ];
946
+ const majorityAgents = [
947
+ ...new Set(groupFaultLines.flatMap((fl) => fl.agents_declaring))
948
+ ];
949
+ let jaccardSum = 0;
950
+ let jaccardCount = 0;
951
+ for (let i = 0; i < unique.length; i++) {
952
+ for (let j = i + 1; j < unique.length; j++) {
953
+ jaccardSum += jaccardSimilarity(
954
+ groupFaultLines[i].agents_missing,
955
+ groupFaultLines[j].agents_missing
956
+ );
957
+ jaccardCount++;
958
+ }
959
+ }
960
+ const alignmentScore = jaccardCount > 0 ? jaccardSum / jaccardCount : 0;
961
+ const hasHigherSeverity = groupFaultLines.some(
962
+ (fl) => fl.severity === "critical" || fl.severity === "high"
963
+ );
964
+ let severity = unique.length >= 3 ? "high" : "medium";
965
+ if (hasHigherSeverity && severity === "medium") {
966
+ severity = "high";
967
+ }
968
+ const sortedFaultLineIds = groupFaultLines.map((fl) => fl.id).sort();
969
+ const alignmentId = deterministicHex(sortedFaultLineIds.join("|"), 12);
970
+ alignments.push({
971
+ id: alignmentId,
972
+ fault_line_ids: sortedFaultLineIds,
973
+ minority_agents: minorityAgents,
974
+ majority_agents: majorityAgents,
975
+ alignment_score: Math.round(alignmentScore * 1e4) / 1e4,
976
+ severity,
977
+ description: `${groupFaultLines.length} fault lines consistently isolate ${minorityAgents.join(", ")} from the team`
978
+ });
979
+ }
980
+ const summary = {
981
+ total: faultLines.length,
982
+ resolvable: faultLines.filter((fl) => fl.classification === "resolvable").length,
983
+ priority_mismatch: faultLines.filter((fl) => fl.classification === "priority_mismatch").length,
984
+ incompatible: faultLines.filter((fl) => fl.classification === "incompatible").length,
985
+ complementary: faultLines.filter((fl) => fl.classification === "complementary").length,
986
+ critical_count: faultLines.filter((fl) => fl.severity === "critical").length
987
+ };
988
+ const analysisIdInput = [
989
+ String(coherenceResult.fleet_score),
990
+ ...faultLines.map((fl) => fl.id).sort()
991
+ ].join("|");
992
+ const analysisId = deterministicHex(analysisIdInput, 16);
993
+ return {
994
+ analysis_id: analysisId,
995
+ fleet_score: coherenceResult.fleet_score,
996
+ fault_lines: faultLines,
997
+ alignments,
998
+ summary
999
+ };
1000
+ }
1001
+ function checkFleetFaultLines(cards, options) {
1002
+ const coherence = checkFleetCoherence(cards);
1003
+ const analysis = analyzeFaultLines(coherence, cards, options);
1004
+ return { coherence, analysis };
1005
+ }
713
1006
  function evaluateCondition(condition, trace) {
714
1007
  if (!condition) {
715
1008
  return false;
@@ -720,7 +1013,7 @@ function evaluateCondition(condition, trace) {
720
1013
  const actual = trace.action.type ?? "";
721
1014
  return actual === expected;
722
1015
  }
723
- const numericMatch = condition.match(/(\w+)\s*([><=!]+)\s*(\d+(?:\.\d+)?)/);
1016
+ const numericMatch = condition.match(/^\s*(\w+)\s*([><=!]+)\s*(\d+(?:\.\d+)?)\s*$/);
724
1017
  if (numericMatch) {
725
1018
  const [, field, op, valueStr] = numericMatch;
726
1019
  const value = parseFloat(valueStr);
@@ -886,8 +1179,10 @@ var EU_COMPLIANCE_VALUES = [
886
1179
  NEAR_BOUNDARY_THRESHOLD,
887
1180
  OUTLIER_STD_DEV_THRESHOLD,
888
1181
  VIOLATION_SEVERITY,
1182
+ analyzeFaultLines,
889
1183
  checkCoherence,
890
1184
  checkFleetCoherence,
1185
+ checkFleetFaultLines,
891
1186
  computeCentroid,
892
1187
  cosineSimilarity,
893
1188
  createViolation,