STATUS: PUBLISHED ON NPMJS. This version was published to the npm registry on 2026-06-23T18:26:39Z with provenance attestation. View on npm: https://www.npmjs.com/package/@takk/bayespredicts/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-23T14:48:26Z
Initial stable release. A universal, zero-runtime-dependency NPM library and CLI for Bayesian survival analysis and predictive maintenance of agents and infrastructure, the reliability-forecasting layer for Massive Intelligence (IM) systems and non-human entities (NHEs). Feed a stream of lifecycle events or right-censored durations; BayesPredicts fits a survival posterior, forecasts time-to-failure conditional on a component's current age with calibrated credible intervals, and recommends whether to restart preemptively, the calibrated answer to "how long until this fails, and should I act now" instead of fixed restart schedules and reactive paging.
Added
The conjugate rate engine
- Gamma posterior (
@takk/bayespredicts/gamma):GammaPosterior, the conjugate posterior over a non-negative failure rate that both survival models are built on, withfromPrior, the posterior mean, variance, and mode, density, cumulative, quantile, an equal-tailed credible interval, and a seeded sample. The default prior isGamma(1, 0), deliberately chosen so the predictive mean lifetime equals total exposure over observed failures, the textbook mean-time-between-failures estimator, while the single pseudo-failure keeps the rate finite before the first real failure.
Survival models
- Exponential model (
@takk/bayespredicts/exponential):ExponentialSurvival, a memoryless, constant-hazard lifetime whose failure rate is the Gamma posterior above. Integrating the survival function over that posterior yields a Lomax (Pareto type II) tail, so survival, cumulative failure, the mean time to failure, lifetime quantiles, and the rate credible interval are exact closed forms rather than simulated. Right-censored observations contribute exposure without a failure. - Weibull model (
@takk/bayespredicts/weibull):WeibullSurvival, an age-dependent hazard that rises with wear-out (shape above one) or falls with infant mortality (shape below one), with the Exponential recovered at shape one. The Weibull is not conjugate in general, so at each shape on a geometric grid the transformed rate is Gamma-conjugate on the transformed exposure, and the grid is weighted into a posterior over the shape by a numerically stable softmax of the marginal likelihood. The fitted posterior is a finite mixture of Gamma-rate components, so survival, hazard, and the mean time to failure are closed form per component and quantiles invert the monotone mixture. Exposes the shape posterior mean, mode, and credible interval. - Survival orchestrator (
@takk/bayespredicts/survival):fitSurvival,fitExponential, andfitWeibull. The automatic choice fits the Weibull and keeps the parsimonious Exponential whenever the shape posterior sits in a practical-equivalence band around one, so a constant hazard is never dressed up as wear-out on thin data.
Event ingestion
- Event collector (
@takk/bayespredicts/events):foldEvents,foldLives,foldEventsByCohort, andtoObservationsfold a stream ofstart,failure,stop, andcensorevents per component into survival observations. A component that starts again after ending is a renewed life, so repeated failures become repeated observations; lives still open at the observation horizon are right-censored; out-of-order streams are sorted; and structurally impossible streams either throw or, in non-strict mode, are repaired.
Prediction conditional on age
- Prediction layer (
@takk/bayespredicts/predict):conditionalSurvival,survivalProbability,failureProbability,hazardAt,timeToFailureProbability,meanResidualLife,residualLifeInterval,sampleResidualLife, andforecast. Every function conditions on the component's current age through the conditional survival, so a component that has already survived its risky infancy is judged on its remaining risk, not its original risk.
Restart advisor
- Maintenance advisor (
@takk/bayespredicts/advisor):advise,optimalRestartAge, andexpectedCostRateunder two policies. The risk-threshold policy restarts once the windowed failure probability or the hazard crosses a limit, the rule for a service-level objective. The cost-optimal policy implements the classic age-replacement model, finding the restart age that minimizes long-run expected cost per unit time by trading the cost of a planned restart against the larger cost of an unplanned failure; for a memoryless lifetime it yields run-to-failure on its own.
Per-cohort and fleet reliability
- Cohort analysis (
@takk/bayespredicts/cohort):fitCohorts,compareCohorts, andrankByReliabilityfit a posterior per cohort (model version, hardware batch, region), pool every cohort into a fleet baseline, rank cohorts worst-first by mean time to failure, and flag the cohorts that are meaningfully shorter-lived than the fleet, so a regressing batch is surfaced rather than averaged away.
Audit, facade, and tool
- Tamper-evident audit trail (
@takk/bayespredicts/audit): an append-onlyAuditChainof predictions with a SHA-256 hash chain youappendto andverifyChain, plussha256Hex. Each entry hashes its payload with the previous entry's hash, so any later edit breaks every link after it. It uses the Web Crypto API, notnode:crypto, so the surface stays node-free. - Calculator (
@takk/bayespredicts/calculator):analyzeruns the full pipeline in one call, from events or observations to a fitted model, a forecast, and an optional restart recommendation.MaintenanceMonitorwraps the same pipeline with the audit chain, so every automated prediction can be replayed and verified later. - Tool adapter (
@takk/bayespredicts/adapter):bayesPredictsTool, a framework-agnostic tool definition (name, description, JSON Schema, handler) matching what MCP servers and LLM tool-calling APIs expect, so a non-human entity (NHE) can forecast its own failures. Input arriving from a model is validated defensively and the output is made JSON-safe.
Persistence and CLI
@takk/bayespredicts/nodeshipsloadEvents,loadObservations,parseCsvObservations, andreadJsonFileovernode:fs, reusing the adapter's defensive parsers, and re-exports the full core. It is the only entry point that touches a Node built-in.- Binary
bayespredictsexposed viapackage.json#bin.bayespredicts fitprints the posterior summary,predictforecasts time-to-failure at a current age,adviserecommends a restart under a policy, andaudit-verifychecks an audit-chain file. Flags--model,--format,--age,--horizon, and--json. Single-process exit codes: 0 ok, 2 usage or input error, 10 restart-now, 20 broken audit chain.
Distribution
- Fourteen entry points, each a subpath export with split
import/requireconditions: the root facade plussurvival,gamma,exponential,weibull,events,predict,advisor,cohort,calculator,adapter,audit,node, andedge. - Dual ESM + CJS bundles built with tsup 8 in a single neutral-platform pass, with separate
.d.tsand.d.ctstype files per entry point, and the CLI shebang preserved from source. - Node-free, platform-neutral core importable in Node, edge runtimes, and the browser;
@takk/bayespredicts/edgere-exports it verbatim, audit trail included, since Web Crypto is present there too. - Zero required runtime dependencies.
@takk/keymeshand@takk/modelchainare optional peer dependencies.
Examples and benchmark
- Five runnable, offline, deterministic examples executed end-to-end against the compiled
dist: a basic forecast, the predictive-maintenance restart advisor with both policies, a cohort comparison that flags a regressing model version, the MCP tool adapter, and node-free edge usage with a verifiable audit chain. - Two real benchmarks executed against the compiled
dist. A throughput benchmark reports fit and forecast performance. A value benchmark scores the restart advisor against naive policies on a simulated wear-out fleet, where the advisor fits its model from a finite, noisy sample and every policy is then scored against the true lifetime distribution by Monte Carlo over renewal cycles: the cost-optimal advisor cuts long-run cost by 75.3% versus run-to-failure and 63.1% versus restarting at the fitted mean time to failure, while suffering roughly ten times fewer unplanned failures. Every number in the documentation comes from real execution, never invented.
Documentation and project site
- A complete project site (
index.html,404.html) and documentation set (README.md,SPEC.md,SECURITY.md,PRIVACY.md,CLA.md,CODE_OF_CONDUCT.md,.github/CONTRIBUTING.md,.github/RELEASING.md), with five JSON-LD structured-data blocks, an Open Graph card, a bespoke hero diagram that traces the survival curve from lifecycle events to the cost-aware restart decision, and a robots and sitemap pair. The documentation states the calibration and value numbers measured above, and phrases every claim honestly: the closed-form guarantee is qualified to the rate given the shape, the advisor produces a recommendation that an orchestrator consumes rather than acting itself, and "calibrated" is backed by the measured coverage.
Quality
- 148 tests across 16 suites passing under Vitest 4, including the special functions verified against known values, the exponential and Weibull survival functions verified against Monte Carlo oracles, parameter recovery on simulated data, the cost-optimal advisor verified to yield a finite restart age for wear-out and run-to-failure for memoryless lifetimes, and the audit chain verified to detect tampering and broken links.
- Simulation-based calibration measures empirical coverage rather than asserting the word "calibrated": the exponential rate 90% credible interval covers the true rate 0.892 of the time over 400 replications, the Weibull shape 90% interval covers 0.868, both close to the nominal 0.90, and a deliberately misspecified fit (the exponential model on Weibull wear-out data) over-covers, demonstrating that model misspecification breaks calibration rather than hiding it.
- Coverage: statements 94.70%, branches 86.82%, functions 99.36%, lines 96.45%.
- Lint clean under Biome 2.5. Typecheck clean under TypeScript 6 in maximum strict mode (
exactOptionalPropertyTypes,noUncheckedIndexedAccess,verbatimModuleSyntax,noPropertyAccessFromIndexSignature,isolatedModules). publintclean and@arethetypeswrong/cligreen across all fourteen subpaths andpackage.json.size-limitunder budget on every bundle (brotli core facade 4.81 kB against a 6 kB limit, exponential model 1.65 kB, Weibull model 2.42 kB, prediction 708 B, edge barrel 7.48 kB, node entry 7.97 kB).- Distribution smoke test exercising the compiled ESM and CJS artifacts and every subpath, with the compiled CLI spawned as a single Node process. The full suite, the smoke test, and the CLI are re-verified on Node 24.
Security
- Every release is published to the npm registry with
npm publish --provenance, carrying a SLSA provenance attestation generated by GitHub Actions over OIDC. Consumers can verify withnpm view @takk/bayespredicts --json | jq .dist.attestations. - Tamper-evident audit trail backed by a SHA-256 hash chain, suitable as compliance evidence that the recorded predictions and decisions were not altered after sealing. It is an integrity seal, not a signature.
- Zero runtime dependencies, the smallest possible supply-chain surface. The node-free core uses the Web Crypto API, not
node:crypto.
Licensing
- Licensed under the Apache License, Version 2.0. The
NOTICEfile ships in the tarball alongsideLICENSE.
Engines
- Node
>=20.0.0. Verified locally on Node 22 and Node 24; the continuous integration matrix covers Node 20, 22, and 24.