STATUS: PUBLISHED ON NPMJS. This version was published to the npm registry on 2026-06-19T23:52:12Z with provenance attestation. View on npm: https://www.npmjs.com/package/@takk/bayestruth/v/1.0.0
STATUS: REVIEW REQUIRED, NOT YET ON NPMJS. This GitHub Release was created by the
release.ymlworkflow. The Creator must review the contents (tag, changelog, attached commit, pack-smoke result in the workflow logs) and then explicitly runnpm-publish.ymlto publish this version to the npm registry.
[1.0.0] - 2026-06-19T20:18:08Z
Initial stable release. Universal, zero-runtime-dependency NPM library and CLI for exact Bayesian trust and reputation scoring of tools, MCP servers, skills, and agents in Massive Intelligence (IM) systems. Every subject carries a Beta posterior over its success rate; each observed call is a Bernoulli trial folded in with the closed-form Beta-Bernoulli conjugate update, so a trust score is a calibrated posterior mean with a credible interval that respects the sample size, not a heuristic threshold.
Added
Bayesian core
- Exact Beta distribution toolkit:
betaMean,betaVariance,betaStddev,betaMode,betaPdf,betaCdf,betaQuantileOf, andcredibleInterval(equal-tailed at any level). - Closed-form conjugate updates:
update(one Bernoulli outcome) andupdateBatch(a batch of successes and failures), each O(1) with zero inference latency. - Built-in priors
UNIFORM_PRIOR(Beta(1, 1)) andJEFFREYS_PRIOR(Beta(0.5, 0.5)), plus fully customizable priors per subject and per category. - Special functions implemented from scratch with no dependency:
lgammavia the Lanczos approximation, the regularized incomplete beta (the Beta CDF) via Lentz's continued fraction, and its inverse (the Beta quantile) via bisection. The credible interval is the true Beta quantile, not a normal approximation. - Seeded sampling (
mulberry32, Box-Muller normal, Marsaglia-Tsang gamma, and Beta sampling) so every stochastic decision is reproducible and auditable.
Trust scoring
initialRecord,observeRecord, andscoreRecordmaintain oneSubjectRecordper subject and summarize it into a calibratedTrustScore(mean, mode, standard deviation, credible interval, counts).rankScoresranks subjects best-first, by the conservative credible-interval lower bound by default, so a single lucky success is not ranked above a long, proven track record.
Decision policies
decideTrustreturnstrust,monitor, ordistrust: a subject is trusted only when its credible-interval lower bound clears the bar, distrusted when its posterior mean falls below the floor, and monitored otherwise, including while the sample is still too small to judge.DEFAULT_TRUST_POLICYships a conservative default;partitionbuckets a set of scores into the three decisions.
Bandit selection
thompsonSelectandcreateBanditroute between competing subjects by Thompson sampling, drawing once from each posterior and picking the maximum. Seeding makes the choice reproducible for testable, auditable routing.
Time-decay and the correlated-failure guard
- Opt-in exponential time-decay (
decayFactor,decayRecord, and thedecayfacade option) pulls stale evidence back toward the prior with a configurable half-life, the escape hatch for slow non-stationarity. The posterior never decays below the prior, so it stays a valid Beta. - Opt-in correlated-failure guard (
coalescefacade option) collapses a run of identical consecutive outcomes inside a window into a single event, so an outage that produces many failures, or a hot path that produces many successes, is not mistaken for that many independent Bernoulli trials. This defends the calibration claim under the bursty, non-i.i.d. traffic of real tools. Explicit batches viaobserveManybypass it.
Calibration diagnostics
brierScore,logLoss,reliabilityBins,expectedCalibrationError, andcalibrationReportlet a consumer verify the calibration claim in their own environment instead of taking it on faith. This is the measurement an EU AI Act Article 12 reviewer asks for, not a promise of calibration but evidence of it.
Empirical-Bayes pooling
fitCategoryPriorfits a shared Beta prior to a group of similar subjects by method of moments on their observed success rates;pooledRecord,pooledScore, andpoolCategoryre-anchor each subject on the fitted prior. A cold-start subject borrows strength from its siblings while a data-rich one barely moves, the partial pooling that a per-subject frequentist interval cannot provide.
Posterior store and persistence
PosteriorStoreinterface with an in-memory default (createMemoryStore) and portable JSON snapshots (encodeStore,decodeStore,loadStore), so trust accumulated in one process can be restored in another and exported as evidence.@takk/bayestruth/nodeshipscreateFileStore, a durable file-backed store usingnode:fswith atomic writes (write to a temporary file, then rename), so trust survives restarts with no database. It is the only entry point that touches a Node built-in.
Audit trail
- Append-only audit log (
createAuditLog) recording every observation, decision, and selection, with a tamper-evident SHA-256 hash chain you cansealand laterverify. The chain uses the Web Crypto API, notnode:crypto, so the audit surface stays node-free and runs in Node, edge runtimes, and the browser. It is an integrity seal, not a digital signature: it proves a log was not altered after sealing, not who produced it.
Observation hooks and MCP
observe,observeSync,wrap, andwrapSyncturn any sync or async call into a Bernoulli outcome, with pluggable success classifiers and a deterministic clock for tests; the facade exposes asinkthat folds those outcomes into the store.@takk/bayestruth/mcpshipsinterceptMcpClient, a transparent Proxy around any Model Context Protocol client that scores everycallToolinvocation per tool, counting a result flaggedisErroras a failure even when the call resolves.
CLI
- Binary
bayestruthexposed viapackage.json#bin. bayestruth score <subject>,rank,inspect <subject>,observe <subject> <success|failure>,verify, andhelp, reading a portable store snapshot from a file or stdin and writing updated stores back atomically.- Standard sysexits-style exit codes: 0 ok, 1 error, 64 usage, 65 data error, 66 missing input.
- Pure command logic in
runCliover an injected IO surface, unit-testable without touching the filesystem or the process.
Distribution
- Fourteen entry points, each a subpath export with split
import/requireconditions: the root facade plusbeta,trust,bandit,decay,store,policy,audit,interceptors,mcp,calibration,pool,node, andedge. - Dual ESM + CJS bundles built with tsup 8, target
es2022, with separate.d.tsand.d.ctstype files per entry point. - Node-free, platform-neutral core (the audit seal uses the Web Crypto API), importable in Node, edge runtimes, and the browser;
@takk/bayestruth/edgere-exports it verbatim. - Zero required runtime dependencies. All
@takksiblings are optional peer dependencies.
Documentation and examples
- Complete project site (
index.html,404.html) and documentation set (README.md,SPEC.md,SECURITY.md,PRIVACY.md,CONTRIBUTING.md,RELEASING.md,CLA.md,CODE_OF_CONDUCT.md), with JSON-LD structured data, an Open Graph card, and a robots and sitemap pair. - Four runnable, offline, deterministic examples (degradation detection, MCP trust scoring, Thompson-sampling routing, calibration check) plus a framework-integration guide for the Vercel AI SDK, the OpenAI Agents SDK, and the Model Context Protocol.
Quality
- 170 tests across 20 suites passing under Vitest 4.
- Coverage: statements 97.48%, branches 93.55%, functions 100%, lines 97.39%.
- Lint clean under Biome 2.5.0.
- Typecheck clean under TypeScript 6.0.3 (with
ignoreDeprecations: "6.0"for the legacy option injected by tsup's dts pipeline). publintclean and@arethetypeswrong/cligreen across all fourteen subpaths andpackage.json.size-limitunder budget on every bundle (brotli core 4.67 kB against a 14 kB limit).- Distribution smoke test (22 checks) exercising the compiled ESM and CJS artifacts and the compiled CLI spawned as a single Node process.
Security
- Published with
--provenance(SLSA attestation by GitHub Actions when released via the publish workflow). Consumers can verify vianpm view @takk/bayestruth --json | jq .dist.attestations. - Tamper-evident audit trail backed by a SHA-256 hash chain, suitable as compliance evidence that trust decisions were made on the recorded evidence. It is an integrity seal, not a signature.
- The correlated-failure guard prevents a single outage from being recorded as many independent failures, which would both crater trust and overstate confidence.
Licensing
- Licensed under the Apache License, Version 2.0. The
NOTICEfile ships in the tarball alongsideLICENSE.
Engines
- Node
>=20.0.0. Tested on Node 20, 22, and 24.