0xBUFF / retention

Policies

Configure intervals, calendar arithmetic, priority weights and eligibility.

validatePolicy(input) returns a discriminated result with a detached, immutable normalized policy or safe structured diagnostics. Use the normalized policy with the public replay operations.

import { validatePolicy } from "@0xbuff/retention";

const result = validatePolicy({
  schemaVersion: 1,
  algorithmVersion: "1",
  policyId: "flashcards",
  policyVersion: "v1",
  scheduling: {
    intervalsDays: [1, 3, 7],
    retryDays: 1,
    maintenanceDays: 30,
    supportAfterMisses: 2,
    longProbeAction: "support",
    dateArithmetic: "elapsed_milliseconds",
  },
});

All scheduling fields are required. Use schema version 1 and algorithm version "1". Policy and version identifiers are bounded ASCII identifiers.

  • Supply 1 to 64 intervals, in the order you want them applied. Interval, retry and maintenance durations are integers from 1 to 3650 days.
  • Set the miss threshold (1 to 1000) at which support activates.
  • Set longProbeAction to restart, support or keep; see practice scheduling.
  • Optionally supply priority with all four integer weights: overdue, support, relation, and stage (0 to 1000). If omitted, all ranking weights are zero. See due ranking.

For local_calendar_days, include scheduling.calendarProfile with zoneId, rulesVersion, coverageStartMs, coverageEndMs, initialOffsetMinutes and transitions. Each transition has atMs and offsetMinutes. Supply no more than 4,096 transitions. Coverage ends exclusively. Offsets are integer minutes in ±1440; transitions are strictly ordered and inside coverage. The caller supplies the rules; no system timezone data is consulted. The profile must cover the entire possible target window, including the shifted target when resolving a gap (a local time skipped by an offset change). For a fold (a repeated local time), Retention chooses the earliest valid instant.

Elapsed arithmetic uses exactly 86,400,000 milliseconds per day. Local arithmetic adds civil days to a local wall-time scalar before resolving the offset. Internal time helpers are not public APIs. Public replay enforces policy identity when advancing.

Optional eligibility

Omit eligibility for practice-only use. To configure the separate advisory candidate projection, supply all of these fields alongside scheduling:

const eligibility = {
  eligibilityPolicyVersion: "v1",
  minSuccesses: 3,
  minSessions: 2,
  minSpanMs: 86_400_000,
  requireFresh: true,
  maxHints: 0,
  minLadder: 3,
  onFailure: "reset",
  onNonqualifying: "ignore",
};

These values are illustrative, not defaults. Successes range from 1 to 1000, sessions from 1 to minSuccesses, span from zero to the largest safe integer in milliseconds, and hint and ladder thresholds from zero to 1000. The version is a bounded ASCII identifier. Freshness must be a boolean; both actions must be reset or ignore.

Qualification considers only surviving credited observations from reconciliation. A matching-version pass qualifies when freshness (if required), maximum hints and minimum ladder are satisfied. A matching-version failure uses onFailure; a version mismatch or nonqualifying pass uses onNonqualifying. Practice observations never enter this classification, even with equivalent metadata. Validation and qualification cannot authenticate a credited tag or model claim. The host must independently admit evidence before supplying a history. Streaks count qualifying successes and distinct sessions from the first qualifying instant; reset clears the entire streak. See replay and readiness.

Validation and identity

The validator accepts the closed current schema, dense ordinary arrays and own enumerable data properties. Do not pass getters or proxies.

The validator checks array lengths before reading entries and stops its enumerable-key inspection at the first unexpected property. It must still inspect all own keys to reject nonenumerable and symbol properties. JavaScript engines may allocate key lists even when enumeration stops early; there is no portable bounded own-key iterator.

Schema limits bound value traversal and accepted data, but cannot bound the engine's inspection cost for arbitrary malformed objects already in memory. If your application accepts untrusted serialized data, enforce input-size and shape budgets before materializing it. Retention still validates the resulting data against its closed schema.

Canonical identity uses the complete normalized content, preserving array order and sorting object keys. A version label alone cannot establish that two policies match. Identity does not authenticate a policy.

On this page