import type { AutonomyLevel } from './intent.js'; /** * Reputation state per (principal, agent, scope) tuple. * Uses Bayesian (mu, sigma) model inspired by TrueSkill. * mu = estimated capability, sigma = uncertainty. * Effective score = mu - k * sigma. */ export interface ScopedReputation { principalId: string; agentId: string; scope: string; mu: number; sigma: number; receiptCount: number; lastUpdatedAt: string; /** Evidence diversity metadata — sybil resistance through diversity requirements. * High score + low diversity = low confidence = restricted effective authority. */ evidenceDiversity?: EvidenceDiversity; /** Computed confidence (0-1). Low with few/homogeneous interactions, * high with many/diverse interactions. Sybil defense: farming cheap * interactions from one source keeps confidence low. */ confidence?: number; /** ISO timestamp of the first evidence event for this scope. * Used for temporal spread calculation — confidence is penalized * when all evidence is clustered in a short window. */ firstObservedAt?: string; /** Ring buffer of most recent evidence events. Optional for backward * compatibility — existing reputations without this field return * no-history drift results from computeReputationDrift. New reputations * populate this automatically via updateReputationFromResult. Capped * at RECENT_OBSERVATIONS_CAP (FIFO eviction). Ordered oldest to newest. */ recentObservations?: ReputationObservation[]; } /** A single evidence event captured in the ScopedReputation ring buffer. * Stores effective deltas — the actual change to mu/sigma after rounding * and clamping, not the raw REPUTATION_UPDATES table values — so that * drift calculations summing recent muDeltas match the actual mu trajectory. */ export interface ReputationObservation { /** ISO 8601 timestamp of the event */ timestamp: string; /** Whether the action succeeded */ success: boolean; /** Difficulty class assigned by the delegator */ evidenceClass: EvidenceClass; /** Effective mu change applied by this event (signed; post-rounding, post-clamp) */ muDelta: number; /** Effective sigma change applied by this event (signed; post-rounding, post-clamp) */ sigmaDelta: number; } /** * Evidence diversity tracks HOW VARIED an agent's track record is. * An agent with 100 tasks from one principal has low diversity. * An agent with 30 tasks from 10 principals across 5 task types has high diversity. * This is the sybil defense: diverse evidence is hard to fake. */ export interface EvidenceDiversity { /** Number of distinct principals who delegated to this agent */ distinctPrincipals: number; /** Number of distinct task types completed */ distinctTaskTypes: number; /** Number of distinct evidence classes received */ distinctEvidenceClasses: number; /** Number of successful interactions */ successCount: number; /** Number of failed interactions */ failureCount: number; /** Set of principal IDs (for dedup — stored as hashes for privacy) */ principalHashes: string[]; /** Set of task type strings seen */ taskTypesSeen: string[]; /** Set of evidence classes seen */ evidenceClassesSeen: string[]; } /** How a tier was granted. Only 'earned' agents can promote others. */ export type TierOrigin = 'fiat' | 'earned' | 'provisional'; export interface AuthorityTier { tier: number; name: string; origin: TierOrigin; autonomyLevel: AutonomyLevel; maxDelegationDepth: number; maxSpendPerAction: number; promotedAt?: string; demotionCount: number; } /** * Default tier definitions. Deployments can customize thresholds. * Promotion threshold increases by (demotionCount * SCARRING_PENALTY). */ export interface TierDefinition { tier: number; name: string; promoteAt: number; demoteAt: number; autonomyLevel: AutonomyLevel; maxDelegationDepth: number; maxSpendPerAction: number; } /** Evidence class for a completed action. Determined by delegator/reviewer, never self-reported. */ export type EvidenceClass = 'trivial' | 'standard' | 'complex' | 'critical'; /** * Metadata attached to a task by the DELEGATOR (not the executor). * This prevents agents from self-reporting complexity to game promotions. */ export interface TaskClassification { stake: 'low' | 'medium' | 'high'; workflowDepth: 'simple' | 'multi-step' | 'branched'; externality: 'none' | 'internal' | 'external-reversible' | 'external-irreversible'; oversightRequired: 'none' | 'review' | 'human-gated'; } /** * Evidence portfolio required for promotion. * Minimum diversity constraints prevent farming. */ export interface EvidencePortfolio { scope: string; totalReceipts: number; classCounts: Record; distinctReviewers: number; distinctTaskTypes: number; failureRate: number; interventionRate: number; } export interface RuntimeProfile { modelFamily: string; modelVersion: string; provider: string; toolsetHash: string; policyProfileHash: string; } export type RuntimeChangeClass = 'minor' | 'major' | 'architecture'; export type DemotionCause = 'behavioral' | 'administrative' | 'environmental'; export interface DemotionEvent { agentId: string; principalId: string; scope: string; fromTier: number; toTier: number; cause: DemotionCause; reason: string; timestamp: string; affectsReputation: boolean; } export interface PromotionRequirements { minReceipts: number; minStandardPct: number; minComplexPct: number; minDistinctReviewers: number; minDistinctTaskTypes: number; maxFailureRate: number; maxInterventionRate: number; minTimeInCurrentTier: number; } export interface PromotionReview { reviewId: string; agentId: string; principalId: string; scope: string; fromTier: number; toTier: number; reviewerId: string; reviewerTier: number; reviewerOrigin: TierOrigin; evidence: EvidencePortfolio; effectiveScore: number; verdict: 'promoted' | 'denied'; reasoning: string; probationEndsAt?: string; timestamp: string; signature: string; } /** * Context for tier checking during policy evaluation. * Optional — if not provided, tier check is skipped (backwards-compatible). */ export interface TierCheckContext { agentTier: AuthorityTier; effectiveScore: number; } /** * Returned when an action is within delegation scope but above earned tier. * Attached to PolicyEvaluationResult to signal the agent needs promotion. */ export interface TierEscalation { currentTier: number; requiredTier: number; effectiveScore: number; effectiveAutonomy: number; requestedAutonomy: number; effectiveSpend: number; requestedSpend?: number; recommendation: 'needs_promotion' | 'needs_human_approval'; } //# sourceMappingURL=reputation-authority.d.ts.map