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
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@ jobs:
cache-dependency-path: pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- run: git diff --exit-code -- pnpm-lock.yaml
- name: Locate Chromium
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
browser="$(command -v google-chrome || command -v chromium || command -v chromium-browser)"
test -n "$browser"
echo "RETENTION_BROWSER=$browser" >> "$GITHUB_ENV"
- run: pnpm check
env:
RETENTION_CANDIDATE_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/upload-artifact@v4
with:
name: retention-candidate-${{ matrix.os }}-${{ github.event.pull_request.head.sha || github.sha }}-${{ github.run_attempt }}
path: .candidate/
include-hidden-files: true
if-no-files-found: error
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- Keep the package private in its manifest until publication approval. 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.
- 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.
- No merge, tag, publication, deployment, maintainer signing, relicensing or repository ownership/visibility change without explicit maintainer authorization.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Notable changes to Retention are recorded here. The format follows [Keep a Chang
- Optional versioned eligibility-policy validation and internal eligible-only qualification with reset or ignore classification.
- Public full-history review rebuild and complete-prefix advance, practice scheduling, eligible-only candidate readiness and structured explanations.
- Public due ranking with bounded weighted features, validated concept relations and deterministic limits.
- Public npm package metadata, an executable quick start, integration guides and exact packed-artifact verification with independent Node/TypeScript and Chromium consumers.
85 changes: 77 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,75 @@
# 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)

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.

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.

> Status: in development. The design below describes the planned first release, `@0xbuff/[email protected]`. Installation and usage instructions will accompany the implemented package.
Retention has no runtime dependencies. The first release candidate is `@0xbuff/[email protected]`. Registry publication is subject to maintainer approval.

## Installation

Use Node.js 24 or later and ESM. After publication, install from npm:

```sh
npm install @0xbuff/[email protected]
```

Before publication, install the verified candidate tarball with `npm install /path/to/0xbuff-retention-0.0.1.tgz`.

## 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.

```ts
import {
rebuildReview,
scheduleDue,
type Policy,
type PracticeObservation,
} from "@0xbuff/retention";

const day = 86_400_000;
const policy: Policy = {
schemaVersion: 1,
algorithmVersion: "1",
policyId: "flashcards",
policyVersion: "v1",
scheduling: {
intervalsDays: [1, 3, 7],
retryDays: 1,
maintenanceDays: 30,
supportAfterMisses: 2,
longProbeAction: "restart",
dateArithmetic: "elapsed_milliseconds",
},
};

const event: PracticeObservation = {
schemaVersion: 1,
scopeId: "deck",
eventId: "review-1",
sequence: 0,
atMs: 0,
kind: "practice_observation",
conceptId: "binary-search",
sessionId: "session-1",
outcome: "pass",
};

const review = rebuildReview(policy, "deck", [event], day);
if (!review.ok) {
throw new Error("Review failed");
}
const due = scheduleDue(policy, "deck", review.value, day);
if (!due.ok || due.value[0]?.dueAtMs !== day) {
throw new Error("Expected a due review");
}
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

Expand Down Expand Up @@ -78,38 +143,42 @@ An eligibility policy might require three fresh successes in at least two sessio

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

## API status
## API

| Operation | Purpose |
| ------------------- | ------------------------------------------------------------------------- |
| `validatePolicy` | Implemented: validate scheduling and optional eligibility policy. |
| `validateEvents` | Implemented: validate scoped events and detect identity conflicts. |
| `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](docs/priority.md), [policy validation](docs/policies.md), [event validation](docs/events.md) and [replay and readiness](docs/replay.md) for implemented behavior and limitations.
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.

## 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).

## Development

The repository has an ESM package foundation with policy and event validation, checked time arithmetic, canonical history reconciliation, practice scheduling and eligible-only readiness and due ranking. Install Node.js 24+ and pnpm 11.2.2, then run:
Install Node.js 24+ and pnpm 11.2.2, then run:

```sh
corepack enable
pnpm install --frozen-lockfile
pnpm check
```

The check covers architecture, TypeScript, Biome, Vitest and distribution verification. See [development](docs/development.md), [contributing](CONTRIBUTING.md) and the [security policy](SECURITY.md).
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.

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.

## License

Licensed under [Apache-2.0](LICENSE). See [source rights](docs/source-rights.md) for provenance and publication requirements.
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.
17 changes: 17 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# API

Import from `@0xbuff/retention`. The root exports seven synchronous operations and their contract types; internal paths are not public.

| Operation | Result |
| ------------------------------------------------------------------ | ---------------------------------------------------- |
| `validatePolicy(policy)` | Validated policy |
| `validateEvents(scopeId, events)` | Validated distinct events |
| `rebuildReview(policy, scopeId, events, nowMs)` | Complete review result |
| `advanceReview(policy, scopeId, identity, prior, appended, nowMs)` | Rebuilt review after prefix verification |
| `evaluateReadiness(policy, scopeId, conceptId, events, nowMs)` | Candidate projection or null |
| `scheduleDue(policy, scopeId, review, nowMs, relations?, limit?)` | Ranked due recommendations |
| `explainReview(review)` | Structured practice, candidate and lifecycle reasons |

Inputs are inert JSON data. Every operation returns `Result<T>`: either `{ ok: true, value }` or `{ ok: false, errors }`. Treat errors as stable codes and safe field names, not user-facing prose. No operation accepts an implicit clock, and no success authenticates evidence.

See [policies](policies.md), [events](events.md), [replay](replay.md) and [due ranking](priority.md) for the input shapes, failure semantics and bounds.
3 changes: 2 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Retention is a standalone review-scheduling engine. The engine takes an explicit
- `src/explanation/`: fixed reason codes and lifecycle explanations.
- `src/readiness/`: internal eligible-only qualification and candidate streak aggregation.
- `tests/unit/` and `tests/fixtures/`: policy, time, event, lifecycle, qualification, identity and export-boundary tests.
- `scripts/`: architecture and distribution checks.
- `scripts/`: architecture, distribution and independent packed-consumer checks.
- `tests/consumer/`: independent package consumer fixtures compiled against the installed archive.
- Root configuration and CI: strict TypeScript, Vitest, tsdown, Biome and frozen pnpm dependencies.

## Replay and projection layers
Expand Down
6 changes: 3 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pnpm check
| `pnpm test:watch` | Watch tests during development. |
| `pnpm build` | Build ESM and declarations and verify distribution. |
| `pnpm verify:dist` | Check existing distribution and root exports. |
| `pnpm check` | Run all currently configured quality checks. |
| `pnpm check` | Run quality checks, build and packed consumer verification. |

CI runs the same commands on Ubuntu and Windows. The export-boundary test checks that the entry point exposes only implemented operations. Update its expected export list as approved operations are implemented; do not remove the boundary test.

The source build targets ES2022, with no Node ambient types or DOM APIs. Test and build tools may use Node APIs. The root export map must match emitted files. The build emits only ESM and declarations, without source maps. Do not edit generated distribution files.

The compatibility target is Node.js 24 or later and ES2022-capable browsers (initial verification targets: Chromium 109+, Firefox 115+, Safari 16.4+). Browser support is not verified yet.
The build targets ES2022. CI checks Node.js 24 on Ubuntu and Windows, and runs a packed consumer in the installed Chromium browser on Ubuntu. See exact run evidence for browser versions; older Chromium, Firefox and Safari versions have not been established by these checks.

Release-candidate work includes exact archive verification, independent browser and Node consumers, and security and source-rights checks. Passing foundation checks does not establish runtime support or release readiness.
Run `pnpm verify:package` after building to verify the exact tarball and independent offline Node/TypeScript consumer. Set `RETENTION_BROWSER` to a Chromium executable on Linux to exercise the browser consumer too. See [release policy](releasing.md) for evidence and approval gates.
15 changes: 15 additions & 0 deletions docs/integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Integration

A local study tool can pass practice observations directly. Bind the scope, assign durable unique event IDs and sequences, and supply a clock in integer Unix milliseconds. Persist the complete history outside Retention and rebuild whenever the policy changes. Use the [README quick start](../README.md) for a practice-only example.

For advisory candidate readiness, configure an eligibility policy and supply only independently admitted credited retrievals. A successful practice event cannot satisfy eligibility. A model report, a tag or the canonical watermark cannot establish evidence authenticity. The [packed consumer fixture](../tests/consumer/consumer.ts) includes synthetic practice and credited observations to illustrate the distinction.

For corrections, revocations and deletion, supply the complete durable history including controls. A scheduler result must not update official grades or credentials. The host owns stale-generation checks, history completeness, tenant authorization, physical erasure and delivery.

## Failures and privacy

Check `result.ok` before consuming a value. On failure, retain authoritative host records unchanged; do not apply a partial projection. Do not log raw payloads or canonical history watermarks. Bound incoming serialized data before materializing it; the validator is not a JavaScript sandbox. See the [security policy](../SECURITY.md).

## Runtime

Use the ESM root in Node.js 24 or a browser with ES2022 support and a bundler or import map. The package has no mandatory runtime dependencies. The release evidence records actual tested browser versions.
24 changes: 21 additions & 3 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# Release policy

The planned first release is `@0xbuff/[email protected]`. The manifest remains private and no publication workflow is configured.
The first candidate is `@0xbuff/[email protected]`. The manifest targets public npm access. No automatic publication workflow is configured.

Before publication, all seven implementation tickets must be accepted. Inspect the actual ESM and declaration archive against its allowlist. Test installation in independent offline Node/TypeScript and browser consumers, verify supported runtime claims, and complete conformance, security and source-rights checks. Record the exact commit, commands, results and limitations.
## Verify the candidate

Maintainers authorize publication after verifying the exact candidate artifact, Apache-2.0 license and notices, registry identity, version and provenance. Host integration is independent. No tag, signing or publication is authorized by passing CI.
From a clean checkout with Node.js 24 and pnpm 11.2.2:

```sh
corepack enable
pnpm install --frozen-lockfile
pnpm check
```

The package check packs the built files with npm, checks the exact archive allowlist and integrity, and installs the tarball offline outside the checkout. It compiles and executes a TypeScript consumer and the README quick start against the installed root export. It rejects unexpected files, runtime dependencies, install hooks and external module imports.

On Linux with Chromium or Google Chrome installed, set `RETENTION_BROWSER` to the browser executable before running the checks. CI exercises the same installed module in Chromium over a loopback-only HTTP server, with a content security policy blocking external resources. Record the actual browser version. Browser compatibility claims are limited to tested versions.

CI retains the tested tarball and an evidence record (source SHA, archive SHA-256 and SHA-512 integrity, runtime versions, file list and consumer checks). The artifact is the candidate; rebuilding later creates a new candidate requiring verification.

## Release approval

Before accepting a candidate, review all library acceptance cases, the exact source, the package artifact, security and source rights. Record verified runtime versions and limitations. Confirm ownership and contributor rights, license and notices, registry scope access and version availability. The maintainer must authorize publication separately. CI never publishes, tags or signs a release.

Host admission, authorization, grade invariance, deletion, delivery and stale-generation tests belong to a later integration.
Loading
Loading