@uvrn/measure
v4.0.0
Published
Pluggable relationship measurements for UVRN evidence
Maintainers
Readme
@uvrn/measure
Pluggable relationship measurements for UVRN evidence. This package implements the first-party agree, disagree, conflict, and potential modules over the Measurement contract exported by @uvrn/core.
Package provides: first-party measurement objects, MeasurementRegistry, defaultRegistry, and convenience re-exports of the core measurement types. Pure logic only: no storage, signer, network call, or provider default.
You provide: a claim, evidence sources, and optional measurement context such as thresholds or agreement history.
Install
npm install @uvrn/measure @uvrn/coreOr with pnpm:
pnpm add @uvrn/measure @uvrn/coreMeasurements
- Agree: emits
agreewhen comparable sources converge at or abovecontext.agreeThreshold(default0.9), otherwiseno-agreement. Fewer than two comparable sources emitsinsufficient-data. - Disagree: emits
disagreewhen numeric spread exceedscontext.divergenceThreshold(default0.1), otherwisenone. Pure numeric spread is neverconflict. Fewer than two numeric values emitsinsufficient-data. - Conflict: emits
conflictwhen two sources on the same field assert mutually exclusive categorical/boolean values or ranges separated by more thancontext.conflictRangeTolerance(default0), otherwisenone. Fewer than two categorical, boolean, or range assertions emitsinsufficient-data. - Potential: emits
potentialwhen at leastcontext.minObservations(default3) agreement observations are rising over the lastcontext.windowSize(default3) points but still below the agree threshold. Confidence is scaled by sample size and trend strength; thin history or a signal belowcontext.confidenceFloor(default0.25) emitsinsufficient-dataso weak early signals are never overstated.
Every measurement emits insufficient-data per SPEC/uvrn-measurement-v1.md §4 when it cannot measure, with an explanation stating what was missing. UIs should render it as "Not enough evidence", never as agreement or as an error.
Context keys
| Key | Default | Used by |
|---|---|---|
| agreeThreshold | 0.9 | agree, potential |
| divergenceThreshold | 0.1 | disagree |
| conflictRangeTolerance | 0 | conflict |
| minObservations | 3 | potential |
| windowSize | 3 | potential |
| history / agreementHistory | — | potential (scores 0..1, oldest first) |
| confidenceFloor | 0.25 | potential |
Usage
import { defaultRegistry } from '@uvrn/measure';
const registry = defaultRegistry();
const results = registry.runAll({
claim: 'Two sources report similar revenue.',
sources: [
{ id: 'source-a', kind: 'numeric', value: 100, label: 'Source A' },
{ id: 'source-b', kind: 'numeric', value: 104, label: 'Source B' },
],
context: {
agreeThreshold: 0.9,
divergenceThreshold: 0.1,
history: [0.55, 0.62, 0.74],
},
});Custom measurements
Core owns the interface; this package owns starter implementations. A host can add or replace measurement logic by implementing Measurement and registering it.
import { Measurement, MeasurementRegistry } from '@uvrn/measure';
const customMeasurement: Measurement = {
type: 'custom',
evaluate(input) {
return {
type: 'custom',
verdict: input.sources.length > 0 ? 'observed' : 'none',
confidence: input.sources.length > 0 ? 1 : 0,
explanation: 'Custom measurement checked whether any evidence was present.',
evidenceRefs: input.sources.map((source) => source.id),
};
},
};
const registry = new MeasurementRegistry();
registry.register(customMeasurement);Package Boundary
@uvrn/measure depends only on the shared measurement contract from @uvrn/core. Hosts can adapt consensus, compare, drift, or other package outputs into measurement input before calling this package, but v1 ships no adapter-backed peer surface.
Links
Source code and issues: GitHub (uvrn-packages). Project landing: UVRN.
