> For AI agents: the complete documentation index is available at https://open-spaced-repetition.github.io/ts-fsrs/llms.txt, the full documentation bundle is available at https://open-spaced-repetition.github.io/ts-fsrs/llms-full.txt.

# Built-in policies

The following policies are available from `ts-fsrs/middlewares` and the `ts-fsrs` root entry:

| Middleware                             | Behavior                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `schedulerDesiredRetentionMiddleware`  | Applies configured `desiredRetention` before interval calculation. Acceptable values: `(0, 1)`.                                                                                                                                                                                                                                                                                                                                                                             |
| `schedulerLearningStepsMiddleware`     | Applies explicit `learningSteps` and `relearningSteps` when `enableShortTerm` is enabled; maintains `learningStep`. Independently of that flag, maps final intervals below `graduatingInterval` (default one day) to `Learning`/`Relearning`, including model intervals. When steps are configured, graduation and Hard, Good, or Easy on a `Review` card use at least `graduatingInterval`; `allowModelOverride` uses a longer model interval instead of the current step. |
| `schedulerFuzzingMiddleware`           | Spreads intervals when `enableFuzz` is enabled, using `cardId` and the review count for reproducible results. `createSchedulerFuzzingMiddleware()` accepts custom ranges and RNG.                                                                                                                                                                                                                                                                                           |
| `schedulerMaximumIntervalMiddleware`   | Caps the day interval at `maximumInterval`. Explicit learning steps can override this cap as the chain unwinds.                                                                                                                                                                                                                                                                                                                                                             |
| `schedulerStatsMiddleware`             | Maintains `reps` and `lapses`; `clearStatsOnForget` controls whether forgetting clears them. A lapse is an Again rating on a Review card.                                                                                                                                                                                                                                                                                                                                   |
| `schedulerMonotonicIntervalMiddleware` | Orders day intervals across ratings, subject to `maximumInterval`; intervals can coincide at the cap.                                                                                                                                                                                                                                                                                                                                                                       |
| `schedulerScheduledDaysMiddleware`     | Stores the final interval as nonnegative `scheduledDays` on the card and saves its previous value in the revlog. With the default `fractionalDays: false`, intervals are floored to whole days, so sub-day steps become `0`. With `fractionalDays: true`, fractional intervals such as `0.5` are preserved.                                                                                                                                                                 |
| `schedulerLeechMiddleware`             | Sets `scheduleStatus` to `suspended` on each positive `leechThreshold` multiple of lapses. The default threshold `0` disables suspension. Your application must respect this status when selecting cards.                                                                                                                                                                                                                                                                   |
| `schedulerCostAdrMiddleware`           | Adapts retention to memory state and review cost using `costAdrPolicy` and `goalCostWeight`. When defining a custom scheduler, use it instead of `schedulerDesiredRetentionMiddleware`, not alongside it.                                                                                                                                                                                                                                                                   |

`DefaultScheduler` already includes the first seven policies. Its order is desired retention → fuzzing → stats → scheduled days → learning steps → maximum interval → monotonic interval. Leech is opt-in when creating your own definition. See [Lifecycle](https://open-spaced-repetition.github.io/ts-fsrs/guide/middleware/lifecycle.md) for why the order matters and the [Overview](https://open-spaced-repetition.github.io/ts-fsrs/guide/middleware/index.md) for how middleware runs.

Use [Quick start](https://open-spaced-repetition.github.io/ts-fsrs/guide/quick-start.md) for the ready-made scheduler or [Architecture](https://open-spaced-repetition.github.io/ts-fsrs/guide/architecture.md) to choose only the policies your application needs.
