/** * Provenance Semiring — Unified Conflict Resolution System * * Replaces the fragmented conflict resolution mechanisms: * - TraitDependencyGraph (warns) * - TraitComposer (Object.assign proceeding) * - TraitCompositionCompiler (hard throw) * - TraitCompositor (4-rule visual composition) * - ConfabulationValidator (schema-based risk scoring) * - QualityGates (regex matching) * * Implements a commutative semiring algebra for trait composition where: * - Addition (⊕) merges independent, non-conflicting trait configurations. * - Multiplication (⊗) resolves conflicts using domain provenance and precedence * rules, ensuring `A ⊕ B == B ⊕ A` (commutativity). * * L3 Batch 1 fixes (C1+C3): * - C1: Authority modulates weight within rules, not bypasses them * - C3: Unified DeadElement type with subsystem projections * * @version 2.0.0 */ /** * Universal ZERO element representing a "dead" or stripped trait * (Addition identity: A ⊕ 0 = A, Multiplication annihilator: A ⊗ 0 = 0) */ export declare const TRAIT_ZERO: unique symbol; /** * Unified dead element — five subsystems previously defined "dead" differently. * This type unifies them: * - TreeShaker: unreachable node (no dependents, not entry point) * - CRDT liveness: zero accesses + age > threshold * - Semiring: TRAIT_ZERO symbol (annihilator) * - Particle system: lifetime <= 0 or alpha <= 0 * - Network: stale peer (no heartbeat > TTL) * * Each subsystem projects from DeadElement to its local zero check. */ export interface DeadElement { /** Which subsystem considers this element dead */ subsystem: 'tree-shaker' | 'crdt-liveness' | 'semiring' | 'particle' | 'network'; /** Human-readable reason for death */ reason: string; /** Timestamp when death was determined */ determinedAt: number; /** The element identifier (trait name, node id, peer DID, etc.) */ elementId: string; /** Original value before zeroing (for audit trail) */ originalValue?: unknown; } /** * Check whether a value represents the universal zero in any subsystem. * Consolidates the five scattered "is this dead?" checks. */ export declare function isDeadElement(value: unknown): value is typeof TRAIT_ZERO; /** * Create a DeadElement record for audit logging when an element is zeroed. */ export declare function createDeadElement(subsystem: DeadElement['subsystem'], elementId: string, reason: string, originalValue?: unknown): DeadElement; /** * Authority tier definitions — replaces magic numbers with named levels. * Authority modulates weight within conflict rules (C1 fix) rather than * bypassing rules entirely. */ export declare enum AuthorityTier { GUEST = 0, AGENT = 25, MEMBER = 50, ADMIN = 75, FOUNDER = 100 } /** * Authority weight calculation for semiring multiplication. * Returns a multiplier in [0.5, 2.0] that MODULATES rule outcomes * rather than overriding them. This ensures authority changes the * WEIGHT of a resolution, not the MECHANISM. * * Before (C1 bug): authority > other => skip all rules, return winner * After (C1 fix): authority difference => weight multiplier on rule result */ export declare function authorityWeight(level: number, reputationScore?: number): number; export interface ProvenanceContext { /** Authority weight (e.g., Founder=100, Agent=50, Guest=0) */ authorityLevel: number; agentId?: string; /** Stable operation identifier for deterministic CRDT tie-breaking. */ opId?: string; sourceType?: 'user' | 'agent' | 'system'; /** Optional reputation score from HoloMesh (0-100) — threads reputation into algebra */ reputationScore?: number; } export interface ProvenanceValue { /** The assigned value */ value: unknown; /** The trait that supplied this value */ source: string; /** Explicit override flag */ override?: boolean; /** Context carrying authority and origin data */ context?: ProvenanceContext; /** Dead element audit record (if this value was zeroed) */ deadRecord?: DeadElement; } export type ProvenanceConfig = Record; export interface TraitApplication { name: string; config: Record; layer?: number; context?: ProvenanceContext; } /** * A numeric vector (fixed-length array of numbers). * Used for stress tensors, velocity fields, displacement vectors, etc. */ export type VectorValue = number[]; /** Return true when value is a non-empty VectorValue (array of numbers). */ export declare function isVectorValue(v: unknown): v is VectorValue; /** L2-magnitude of a VectorValue. */ export declare function vecMagnitude(v: VectorValue): number; /** Component-wise addition: a + b (same dimensionality required). */ export declare function vecAdd(a: VectorValue, b: VectorValue): VectorValue; /** Component-wise max: max(a_i, b_i). */ export declare function vecComponentMax(a: VectorValue, b: VectorValue): VectorValue; /** Component-wise min: min(a_i, b_i). */ export declare function vecComponentMin(a: VectorValue, b: VectorValue): VectorValue; /** * Authority-weighted blend: picks the vector from the higher-authority source. * When authority is equal, falls back to magnitude tiebreak then lexicographic. */ export declare function vecAuthorityPick(a: VectorValue, weightA: number, b: VectorValue, weightB: number): VectorValue; export interface ConflictResolutionRule { /** Domain property (e.g., 'type', 'mass', 'color') */ property: string; /** Strategy to apply when settling values */ strategy: 'max' | 'min' | 'sum' | 'multiply' | 'tropical-min-plus' | 'tropical-max-plus' | 'strict-error' | 'domain-override' | 'authority-weighted' | 'vec-component-max' | 'vec-component-min' | 'vec-component-sum' | 'vec-magnitude-max' | 'vec-authority-weighted'; /** If domain-override, defines the precedence of trait sources */ precedence?: string[]; } export interface CompositionResult { config: Record; provenance: ProvenanceConfig; conflicts: string[]; errors: string[]; /** Dead elements encountered during composition (C3 audit trail) */ deadElements: DeadElement[]; } export declare class ProvenanceSemiring { private rules; constructor(rules?: ConflictResolutionRule[]); private loadDefaultRules; /** * Commutative addition (⊕) * Merges multiple traits into a unified provenanced configuration map. */ add(traits: TraitApplication[]): CompositionResult; /** * Semiring multiplication (⊗) * Resolves conflicts based on loaded domain rules, enforcing commutativity. * * C1 FIX: Authority no longer bypasses rules. Instead, authority modulates * the weight within rule resolution. Higher authority = higher weight in * numeric strategies, tiebreaker in domain-override. This ensures the * algebraic structure is preserved — crossing an authority threshold * changes the WEIGHT of a resolution, not the MECHANISM. */ private multiply; }