import { type AnomalyOptions, type AnomalyScore } from './anomaly.ts'; import { type TrustAssessment } from './assess.ts'; import { type BehaviorFeatures, type DiversityThresholds, type VelocityThresholds } from './behavior.ts'; import { type Clock } from './clock.ts'; import { type Invariant, type Violation } from './constraints.ts'; import { type Decision } from './decision.ts'; import { type AssessmentEvent, type AssessmentIdentity } from './event.ts'; import { type WeakSignal } from './signals.ts'; import { type Policy } from './policy.ts'; import { type StateStore } from './store.ts'; export type EvidenceStrength = 'weak' | 'strong'; export type Observation = { /** * Which declared scope this observation belongs to. Invariants outside it are * not consulted, and an undeclared scope yields no violations, unknown, not * forbidden. D32. */ readonly scope?: string; /** Whatever the host's invariants know how to read. Never inspected by SG. */ readonly data?: unknown; /** Evidence the host attributes to this interaction. D4. */ readonly evidence?: { readonly positive?: EvidenceStrength; readonly negative?: EvidenceStrength; }; /** * Weak signals the host observed, by catalogue id. D42. * * Measurement, not proof: these become negative trust mass and nothing else. * Ids the catalogue does not know are ignored rather than guessed at, so a * newer host cannot widen SG's vocabulary by inventing tokens. */ readonly signals?: readonly string[]; }; export type EvaluationContext = { /** * Endpoint sensitivity and anything else the host wants recorded against the * decision. Part of `C` in `T = PI(A, C)`, not part of the state key, since * trust is global per entity. D2. */ readonly [key: string]: unknown; }; export type Assessment = { readonly entity: string; readonly decision: Decision; readonly trust: TrustAssessment; /** Behavioral features over the retained window. D36. */ readonly behavior: BehaviorFeatures; /** * Whether behavior was varied enough to believe low variance. D37. * `undefined` when the window is too small to judge. */ readonly diversity: boolean | undefined; /** * Whether this entity looks like it is farming trust: a high observation rate * *and* a monotonous shape. D50, corrected by D54. * * `undefined` when there is too little in the window to measure a rate. */ readonly farming: boolean | undefined; /** * Distance from the reference behavior profile. D18. * * Reported on every evaluation whether or not it drives the decision, so an * adopter can compare the classifier against the threshold conjunction on their * own traffic before switching. */ readonly anomaly: AnomalyScore; readonly violations: readonly Violation[]; /** True when a proven violation set the outcome, bypassing the trust ceiling. */ readonly hardViolated: boolean; /** True when state was absent or past its retention horizon. D6, D21. */ readonly coldStart: boolean; readonly context: EvaluationContext | undefined; /** Why this outcome, in order of what actually decided it. D23. */ readonly trace: readonly string[]; }; export type GuardOptions = { readonly store?: StateStore; readonly clock?: Clock; readonly policy?: Partial; readonly invariants?: readonly Invariant[]; /** See D37. Defaults to withholding escalation with no anomaly data. */ readonly allowEscalationWithoutAnomaly?: boolean; /** Thresholds for the diversity signal. D36. */ readonly diversity?: DiversityThresholds; /** Observations retained per entity for behavioral features. D36. */ readonly windowSize?: number; /** Thresholds for the farming check, and for the D55 positive discount. */ readonly velocity?: VelocityThresholds; /** * Discount positive evidence earned with machine-regular gaps. D55. * * On by default: it is what closes the patient farmer, and it cannot advise worse * than `OBSERVE` for a client that only earns positives. Turn it off for a * deployment whose legitimate traffic is predominantly automated and whose * operators would rather it accrue trust at full rate. */ readonly discountRegularPositives?: boolean; /** * Use the anomaly classifier (D18) for the D37 concurrence instead of the three * threshold comparisons in `diversityConcurs`. * * Defaults to `false`: the classifier is new, the conjunction is what the D37 gate * was reasoned against, and which reads better against a real population is not * something generated traffic can settle. The score is reported either way. */ readonly useAnomalyClassifier?: boolean; /** Reference profile and weights for the classifier. D18. */ readonly anomaly?: AnomalyOptions; /** Override the weak-signal catalogue. D42. Defaults to the published one. */ readonly signals?: readonly WeakSignal[]; /** * Called once per evaluation with a structured event. D61. * * Reporting only. The event is built after the decision is final and the guard * does not wait for the sink, so a slow collector cannot slow the advice and a * broken one cannot fail the request. */ readonly onAssessment?: (event: AssessmentEvent) => void | Promise; /** * How that event identifies the entity. D61. * * Defaults to omitting the reference, so an event log cannot quietly become a * second copy of the host user table. A hashed identity keys the event to an * entity without carrying it: keep the salt as configuration, and rotating it * breaks correlation in the log rather than in the state. */ readonly identity?: AssessmentIdentity; }; export type EvaluateInput = { readonly entity: string; readonly observation?: Observation; readonly context?: EvaluationContext; /** * Override the computed diversity verdict. D37. * * Normally omitted: SG derives concurrence from the entity's own observation * window (D36). Supply this only when the host holds a better signal. */ readonly anomalyConcurs?: boolean; }; /** * The guard. Advisory only: it returns a point on the decision spectrum and the * reasoning behind it, and the host decides what to do. D9, D14. */ export declare function createGuard(options?: GuardOptions): { evaluate(input: EvaluateInput): Promise; /** Forget one entity outright. D22. Same operation retention uses. */ forget(entity: string): Promise; }; export type Guard = ReturnType; //# sourceMappingURL=guard.d.ts.map