Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pnpm install --frozen-lockfile
pnpm check
```

Use `pnpm exec vitest run <test-path>` for a focused existing test. Run `pnpm check:architecture`, `pnpm build` and `pnpm verify:dist` as needed; run `pnpm verify:package` when the packed-consumer gate is implemented. Check the manifest for available scripts. Report checks you could not run; packed-consumer verification belongs to release-candidate work.
Use `pnpm exec vitest run <test-path>` for focused tests. Run `pnpm check:architecture`, `pnpm build` and `pnpm verify:dist` as needed. `pnpm verify:package` checks the built archive and independent consumers; `pnpm check` includes it. Report checks you could not run.

- Add positive, negative and boundary tests for every behavior change. Use independently derived golden vectors, seeded permutation/duplicate properties, advance/rebuild equivalence, calendar fold/gap/leap-day cases, correction/deletion replay, eligibility separation, ranking ties and resource-limit tests as relevant.
- Use synthetic fixtures and private-data canaries, never actual learner records, credentials or restricted product material. Keep tests reproducible; do not weaken assertions, skip cases or relax architecture guards to obtain a pass.
Expand All @@ -62,5 +62,5 @@ Use `pnpm exec vitest run <test-path>` for a focused existing test. Run `pnpm ch

- Prioritize nondeterminism, incorrect time arithmetic, invalid lifecycle acceptance, deleted-history resurrection, practice-to-credit leakage, policy/prefix mismatch, resource-bound bypasses, unsafe diagnostics, dependency violations and weakened gates. Include file/line, triggering condition, impact and a testable correction.
- PRs must identify the ticket where applicable, requirement coverage, changes, tests and outstanding limitations. Do not mark tickets complete without required review, merge and acceptance evidence.
- The maintainer has authorized publishable manifest metadata for the first candidate. Keep publication separately gated; a public manifest is not permission to publish. Preserve Apache-2.0 and copyright notices. Verify ownership and contributor rights before release. RV-I04 requires the exact packed ESM/types artifact, explicit archive/export allowlists, and independent offline Node/TypeScript and browser consumers. Host integration and registry publication are separate gates.
- Obtain maintainer approval for each publication. Preserve Apache-2.0 and copyright notices, and verify source and contributor rights. Follow [release policy](docs/releasing.md): check the exact ESM/types archive, explicit archive/export allowlists and independent offline Node/TypeScript and browser consumers. Host integration requires separate acceptance.
- No merge, tag, publication, deployment, maintainer signing, relicensing or repository ownership/visibility change without explicit maintainer authorization.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog

Notable changes to Retention are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the planned package uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Notable changes to Retention are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the package uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.0.1] - 2026-11-29

### Added

- Repository development instructions, contribution and security policies, issue and pull request templates.
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

Retention welcomes reproducible bug reports, documentation corrections and technical proposals. Discuss public contract or architecture changes before implementation. Follow the [security policy](SECURITY.md) for confidential reports.
Retention welcomes reproducible bug reports, documentation corrections and technical proposals. Open an issue before changing a public contract or the architecture. Follow the [security policy](SECURITY.md) for confidential reports.

## Development

Expand All @@ -12,11 +12,11 @@ pnpm install --frozen-lockfile
pnpm check
```

Use a focused branch and add reproducible positive, negative and boundary tests. The check runs architecture, TypeScript, Biome, Vitest and distribution verification. See [development](docs/development.md) and [repository instructions](AGENTS.md).
Use a focused branch and add reproducible positive, negative and boundary tests. The check covers architecture, TypeScript, Biome, Vitest, the build and independent packed consumers. See [development](docs/development.md) and [repository instructions](AGENTS.md).

## Pull requests

Explain the change and link the relevant issue or ticket. Record the requirements covered, tested commit, checks and anything you could not run. Use synthetic data and preserve the independent deterministic core. Contract changes require maintainer approval.
Explain the change and link the relevant issue. Record the tested commit, checks and anything you could not run. Use synthetic learner data and keep private material out of public changes. Preserve the independent, deterministic core and its zero runtime dependencies. Contract changes require maintainer approval.

## Source rights

Expand Down
122 changes: 35 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# Retention

[![CI](https://github.com/0xbuffdev/retention/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/0xbuffdev/retention/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/0xbuffdev/retention/blob/main/LICENSE)
[![CI](https://github.com/0xbuffdev/retention/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/0xbuffdev/retention/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/%400xbuff%2Fretention)](https://www.npmjs.com/package/@0xbuff/retention) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/0xbuffdev/retention/blob/main/LICENSE) [![Node.js](https://img.shields.io/badge/node-%3E%3D24-blue)](https://github.com/0xbuffdev/retention/blob/main/package.json)

Retention is a review-scheduling engine for learning applications. It uses past learning observations and a review policy to decide what is due, when to revisit it and when to recommend further practice.
Retention is a review-scheduling engine for learning applications. It uses a review policy and a history of learning observations to calculate when concepts are due for review, when learners need more practice and which reviews to prioritize.

Use it in a flashcard app, to revisit mathematical concepts or to reinforce programming skills. Retention works without a server, database, model provider or account. Applications retain ownership of their learning records and assessment decisions.

Retention has no runtime dependencies. The first release candidate is `@0xbuff/[email protected]`. Registry publication is subject to maintainer approval.
Use it in flashcard apps or learning tools for mathematics and programming. Retention works offline, has no runtime dependencies and gives the same result for the same policy, history and clock. Applications own the learning records and any official assessment decisions.

## Installation

Use Node.js 24 or later and ESM. After publication, install from npm:
Retention requires Node.js 24 or later and ESM. Browser applications can use the ESM entry with an ES2022-compatible environment.

```sh
npm install @0xbuff/retention@0.0.1
npm install @0xbuff/retention
```

Before publication, install the verified candidate tarball with `npm install /path/to/0xbuff-retention-0.0.1.tgz`.
Pin the version you have tested when deploying an application.

## Quick start

Schedule a flashcard from a successful practice observation. Supply your own policy and clock; the example uses a fixed clock one day after the observation.
Schedule a review for a successfully recalled concept. This example uses elapsed days and evaluates the history one day after the observation.

```ts
import {
Expand Down Expand Up @@ -69,116 +67,66 @@ if (!due.ok || due.value[0]?.dueAtMs !== day) {
console.log(due.value);
```

The recommendation is due exactly one day after the observation. The application can present the queue without granting credit or changing the learner's official records.

## How it works

Suppose a learner successfully recalls a concept on Monday. A review policy can schedule the next attempt for Tuesday, then increase the interval after each successful review. If the learner struggles, the policy can schedule an earlier retry or recommend additional practice.

For example, with intervals of 1, 3, 7, 16 and 35 elapsed days, a learner who passes each review when due follows this schedule:

| Retrieval succeeds on | Next review |
| --------------------- | ----------------------------------------- |
| Day 0 | Day 1 |
| Day 1 | Day 4 |
| Day 4 | Day 11 |
| Day 11 | Day 27 |
| Day 27 | Day 62 |
| Day 62 | After the configured maintenance interval |

Practicing early does not advance an existing interval. A missed review follows the configured retry, restart and support rules. Choose intervals and maintenance rules appropriate to the material. This example is not a universal learning standard.
The concept is due one day after the observation. The application can present the returned queue to the learner.

## Capabilities
## Features

- Configurable spaced retrieval, retry intervals and maintenance reviews.
- Support recommendations and delayed retrieval probes.
- Due-review ranking across concepts, with optional priority weights and relationships.
- Elapsed-time or local-calendar scheduling using explicit timezone rules.
- Replay of duplicated, reordered, corrected, revoked or deleted observations.
- Configurable review intervals, retries, maintenance and support recommendations.
- Delayed retrieval probes and deterministic due-review ranking.
- Elapsed-time or local-calendar scheduling with explicit timezone rules.
- History replay with duplicate detection, corrections, revocations and deletion controls.
- Optional advisory readiness based on independently admitted evidence.

Given the same validated history, policy, algorithm revision and clock, Retention produces the same result. Retention does not inspect answers, authenticate learners, issue grades, certify mastery or deliver notifications.

## Architecture

The application records practice, supplies a policy and calls Retention with an explicit clock. Retention reconciles the history and calculates review projections. The application decides how to present and store the results.

```mermaid
flowchart LR
H["History, policy, clock"] --> R["Reconcile"]
R --> S["Schedule and rank"]
R --> P["Practice schedule"]
R --> C["Optional readiness"]
S --> A["Application"]
C --> A
```

### Replay

Review histories can arrive out of order. An application may also need to correct a previous result or remove a learner's data. Retention validates the scope, schema and limits, then uses stable event identities and a durable sequence to reconcile corrections, revocations and deletions. It orders surviving observations and excludes future observations before rebuilding the practice and optional candidate projections. Invalid inputs return typed errors.

```mermaid
flowchart LR
H["Scoped history"] --> V["Validate and deduplicate"]
V --> C["Apply lifecycle controls"]
C --> R["Replay active observations"]
P --> Q["Review result"]
C --> Q
Q --> D["Rank due reviews"]
```

Identical duplicate events have no effect. Conflicting identities and invalid correction chains produce typed failures. A correction replaces the original observation and contributes no extra success. Deletion controls suppress affected history during replay; the application remains responsible for physical erasure and preventing obsolete histories from returning.

Full replay is the reference calculation. The advance operation verifies the previous projection identity and complete event prefix before rebuilding. Policy changes require explicit replay.

### Readiness and evidence

Practice observations and admitted evidence can influence due dates and support recommendations. Only host-admitted evidence enters the separate advisory readiness calculation under an eligibility policy.
The host supplies the complete history, policy and clock. Retention validates the input, applies lifecycle controls and replays surviving observations. Ranking selects due concepts from the resulting projection.

```mermaid
flowchart LR
P["Practice"] --> S["Review schedule"]
P["Practice"] --> S["Practice schedule"]
E["Admitted evidence"] --> S
E --> C["Eligible-only readiness"]
E --> C["Candidate readiness"]
K["Eligibility policy"] --> C
```

An eligibility policy might require three fresh successes in at least two sessions over a minimum span of 24 hours. Only qualifying admitted observations start and extend that streak. A local study tool can omit this policy entirely.

Retention cannot establish whether evidence is authentic. The application admits evidence and makes any official assessment or credit decision independently.

## API

| Operation | Purpose |
| ------------------- | ------------------------------------------------------------------------- |
| `validatePolicy` | validate scheduling and optional eligibility policy. |
| `validateEvents` | validate scoped events and detect identity conflicts. |
| `rebuildReview` | Reconstruct review projections from complete history. |
| `advanceReview` | Verify the prior identity and event prefix, then rebuild with new events. |
| `evaluateReadiness` | Calculate advisory readiness from reconciled eligible evidence. |
| `scheduleDue` | Select and rank due concepts. |
| `explainReview` | Return structured reasons for a recommendation. |

See [due ranking](https://github.com/0xbuffdev/retention/blob/main/docs/priority.md), [policy validation](https://github.com/0xbuffdev/retention/blob/main/docs/policies.md), [event validation](https://github.com/0xbuffdev/retention/blob/main/docs/events.md) and [replay and readiness](https://github.com/0xbuffdev/retention/blob/main/docs/replay.md) for implemented behavior and limitations.

The [review scheduling specification](https://github.com/0xbuffdev/context/blob/main/repos/retention/specs/0001-review-scheduling.md) defines the event schemas, policy fields, transition rules, resource limits and error behavior.
Only admitted credited evidence can qualify for candidate readiness. Retention cannot authenticate evidence, grant credit or certify mastery. The host handles persistence, authorization, erasure and notifications. See the [architecture guide](https://github.com/0xbuffdev/retention/blob/main/docs/architecture.md).

## Documentation

See the [documentation homepage](https://docs.0xbuff.com/docs/retention) and the repository guides for [API usage](https://github.com/0xbuffdev/retention/blob/main/docs/api.md), [integration](https://github.com/0xbuffdev/retention/blob/main/docs/integration.md) and [release verification](https://github.com/0xbuffdev/retention/blob/main/docs/releasing.md).
| Guide | Contents |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| [API](https://github.com/0xbuffdev/retention/blob/main/docs/api.md) | Public operations and results |
| [Policies](https://github.com/0xbuffdev/retention/blob/main/docs/policies.md) | Review intervals, time arithmetic and eligibility |
| [Events](https://github.com/0xbuffdev/retention/blob/main/docs/events.md) | Observations, lifecycle controls and validation |
| [Replay](https://github.com/0xbuffdev/retention/blob/main/docs/replay.md) | History reconstruction, readiness and explanations |
| [Due ranking](https://github.com/0xbuffdev/retention/blob/main/docs/priority.md) | Priority weights, concept relations and queue ordering |
| [Integration](https://github.com/0xbuffdev/retention/blob/main/docs/integration.md) | Application responsibilities, failures and privacy |
| [Architecture](https://github.com/0xbuffdev/retention/blob/main/docs/architecture.md) | Module boundaries and data flow |

## Development

Install Node.js 24+ and pnpm 11.2.2, then run:

```sh
git clone https://github.com/0xbuffdev/retention.git
cd retention
corepack enable
pnpm install --frozen-lockfile
pnpm check
```

The check covers architecture, TypeScript, Biome, Vitest, distribution verification and independent offline package installation. CI also exercises the packed library in Chromium. See [development](https://github.com/0xbuffdev/retention/blob/main/docs/development.md), [contributing](https://github.com/0xbuffdev/retention/blob/main/CONTRIBUTING.md) and the [security policy](https://github.com/0xbuffdev/retention/blob/main/SECURITY.md).

See the [source architecture](https://github.com/0xbuffdev/context/blob/main/repos/retention/architecture.md) for the repository layout, module dependencies, build configuration and testing conventions. The [implementation tickets](https://github.com/0xbuffdev/context/blob/main/repos/retention/tickets.md) track progress toward the first release, including independent Node.js and browser consumer checks.
Use Node.js 24 or later and pnpm 11.2.2. The full check covers architecture, typechecking, Biome, tests, the build and independent offline package consumers. CI also tests the installed package in Chromium.

To contribute before the first release, review the [architecture decision](https://github.com/0xbuffdev/context/blob/main/repos/retention/adr/0001-deterministic-scheduling.md) and [implementation plan](https://github.com/0xbuffdev/context/tree/main/repos/retention), then use the repository's [issue tracker](https://github.com/0xbuffdev/retention/issues) for questions or proposed changes.
See the [development guide](https://github.com/0xbuffdev/retention/blob/main/docs/development.md), [contribution guidelines](https://github.com/0xbuffdev/retention/blob/main/CONTRIBUTING.md), [security policy](https://github.com/0xbuffdev/retention/blob/main/SECURITY.md) and [release policy](https://github.com/0xbuffdev/retention/blob/main/docs/releasing.md). Report bugs or propose changes through the [issue tracker](https://github.com/0xbuffdev/retention/issues).

## License

Licensed under [Apache-2.0](LICENSE). See [source rights](https://github.com/0xbuffdev/retention/blob/main/docs/source-rights.md) for provenance and publication requirements.
[Apache-2.0](https://github.com/0xbuffdev/retention/blob/main/LICENSE). See [copyright and attribution](https://github.com/0xbuffdev/retention/blob/main/COPYRIGHT.md).
Loading
Loading