@0xbuff/retention 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/COPYRIGHT.md +7 -0
- package/LICENSE +201 -0
- package/README.md +183 -2
- package/dist/index.d.ts +219 -0
- package/dist/index.js +1427 -0
- package/package.json +62 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
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).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Repository development instructions, contribution and security policies, issue and pull request templates.
|
|
10
|
+
- Pinned TypeScript, pnpm, Biome, Vitest and tsdown, with CI on Ubuntu and Windows and initial architecture and distribution checks.
|
|
11
|
+
- Apache-2.0 license and copyright notice.
|
|
12
|
+
- Versioned scheduling-policy validation, canonical policy identity and checked elapsed and explicit calendar-day arithmetic.
|
|
13
|
+
- Current-version scoped event contracts, bounded validation and canonical duplicate/conflict detection.
|
|
14
|
+
- Internal full-history reconciliation, including credited decision replacement and revocation, deletion controls, deterministic replay ordering and canonical history watermarks.
|
|
15
|
+
- Optional versioned eligibility-policy validation and internal eligible-only qualification with reset or ignore classification.
|
|
16
|
+
- Public full-history review rebuild and complete-prefix advance, practice scheduling, eligible-only candidate readiness and structured explanations.
|
|
17
|
+
- Public due ranking with bounded weighted features, validated concept relations and deterministic limits.
|
|
18
|
+
- Public npm package metadata, an executable quick start, integration guides and exact packed-artifact verification with independent Node/TypeScript and Chromium consumers.
|
package/COPYRIGHT.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,184 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Retention
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/0xbuffdev/retention/actions/workflows/ci.yml) [](https://github.com/0xbuffdev/retention/blob/main/LICENSE)
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
Retention has no runtime dependencies. The first release candidate is `@0xbuff/retention@0.0.1`. Registry publication is subject to maintainer approval.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Use Node.js 24 or later and ESM. After publication, install from npm:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @0xbuff/retention@0.0.1
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Before publication, install the verified candidate tarball with `npm install /path/to/0xbuff-retention-0.0.1.tgz`.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {
|
|
27
|
+
rebuildReview,
|
|
28
|
+
scheduleDue,
|
|
29
|
+
type Policy,
|
|
30
|
+
type PracticeObservation,
|
|
31
|
+
} from "@0xbuff/retention";
|
|
32
|
+
|
|
33
|
+
const day = 86_400_000;
|
|
34
|
+
const policy: Policy = {
|
|
35
|
+
schemaVersion: 1,
|
|
36
|
+
algorithmVersion: "1",
|
|
37
|
+
policyId: "flashcards",
|
|
38
|
+
policyVersion: "v1",
|
|
39
|
+
scheduling: {
|
|
40
|
+
intervalsDays: [1, 3, 7],
|
|
41
|
+
retryDays: 1,
|
|
42
|
+
maintenanceDays: 30,
|
|
43
|
+
supportAfterMisses: 2,
|
|
44
|
+
longProbeAction: "restart",
|
|
45
|
+
dateArithmetic: "elapsed_milliseconds",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const event: PracticeObservation = {
|
|
50
|
+
schemaVersion: 1,
|
|
51
|
+
scopeId: "deck",
|
|
52
|
+
eventId: "review-1",
|
|
53
|
+
sequence: 0,
|
|
54
|
+
atMs: 0,
|
|
55
|
+
kind: "practice_observation",
|
|
56
|
+
conceptId: "binary-search",
|
|
57
|
+
sessionId: "session-1",
|
|
58
|
+
outcome: "pass",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const review = rebuildReview(policy, "deck", [event], day);
|
|
62
|
+
if (!review.ok) {
|
|
63
|
+
throw new Error("Review failed");
|
|
64
|
+
}
|
|
65
|
+
const due = scheduleDue(policy, "deck", review.value, day);
|
|
66
|
+
if (!due.ok || due.value[0]?.dueAtMs !== day) {
|
|
67
|
+
throw new Error("Expected a due review");
|
|
68
|
+
}
|
|
69
|
+
console.log(due.value);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
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.
|
|
73
|
+
|
|
74
|
+
## How it works
|
|
75
|
+
|
|
76
|
+
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.
|
|
77
|
+
|
|
78
|
+
For example, with intervals of 1, 3, 7, 16 and 35 elapsed days, a learner who passes each review when due follows this schedule:
|
|
79
|
+
|
|
80
|
+
| Retrieval succeeds on | Next review |
|
|
81
|
+
| --------------------- | ----------------------------------------- |
|
|
82
|
+
| Day 0 | Day 1 |
|
|
83
|
+
| Day 1 | Day 4 |
|
|
84
|
+
| Day 4 | Day 11 |
|
|
85
|
+
| Day 11 | Day 27 |
|
|
86
|
+
| Day 27 | Day 62 |
|
|
87
|
+
| Day 62 | After the configured maintenance interval |
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
## Capabilities
|
|
92
|
+
|
|
93
|
+
- Configurable spaced retrieval, retry intervals and maintenance reviews.
|
|
94
|
+
- Support recommendations and delayed retrieval probes.
|
|
95
|
+
- Due-review ranking across concepts, with optional priority weights and relationships.
|
|
96
|
+
- Elapsed-time or local-calendar scheduling using explicit timezone rules.
|
|
97
|
+
- Replay of duplicated, reordered, corrected, revoked or deleted observations.
|
|
98
|
+
- Optional advisory readiness based on independently admitted evidence.
|
|
99
|
+
|
|
100
|
+
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.
|
|
101
|
+
|
|
102
|
+
## Architecture
|
|
103
|
+
|
|
104
|
+
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.
|
|
105
|
+
|
|
106
|
+
```mermaid
|
|
107
|
+
flowchart LR
|
|
108
|
+
H["History, policy, clock"] --> R["Reconcile"]
|
|
109
|
+
R --> S["Schedule and rank"]
|
|
110
|
+
R --> C["Optional readiness"]
|
|
111
|
+
S --> A["Application"]
|
|
112
|
+
C --> A
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Replay
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
```mermaid
|
|
120
|
+
flowchart LR
|
|
121
|
+
H["Scoped history"] --> V["Validate and deduplicate"]
|
|
122
|
+
V --> C["Apply lifecycle controls"]
|
|
123
|
+
C --> R["Replay active observations"]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
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.
|
|
127
|
+
|
|
128
|
+
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.
|
|
129
|
+
|
|
130
|
+
### Readiness and evidence
|
|
131
|
+
|
|
132
|
+
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.
|
|
133
|
+
|
|
134
|
+
```mermaid
|
|
135
|
+
flowchart LR
|
|
136
|
+
P["Practice"] --> S["Review schedule"]
|
|
137
|
+
E["Admitted evidence"] --> S
|
|
138
|
+
E --> C["Eligible-only readiness"]
|
|
139
|
+
K["Eligibility policy"] --> C
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
Retention cannot establish whether evidence is authentic. The application admits evidence and makes any official assessment or credit decision independently.
|
|
145
|
+
|
|
146
|
+
## API
|
|
147
|
+
|
|
148
|
+
| Operation | Purpose |
|
|
149
|
+
| ------------------- | ------------------------------------------------------------------------- |
|
|
150
|
+
| `validatePolicy` | validate scheduling and optional eligibility policy. |
|
|
151
|
+
| `validateEvents` | validate scoped events and detect identity conflicts. |
|
|
152
|
+
| `rebuildReview` | Reconstruct review projections from complete history. |
|
|
153
|
+
| `advanceReview` | Verify the prior identity and event prefix, then rebuild with new events. |
|
|
154
|
+
| `evaluateReadiness` | Calculate advisory readiness from reconciled eligible evidence. |
|
|
155
|
+
| `scheduleDue` | Select and rank due concepts. |
|
|
156
|
+
| `explainReview` | Return structured reasons for a recommendation. |
|
|
157
|
+
|
|
158
|
+
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.
|
|
159
|
+
|
|
160
|
+
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.
|
|
161
|
+
|
|
162
|
+
## Documentation
|
|
163
|
+
|
|
164
|
+
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).
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
Install Node.js 24+ and pnpm 11.2.2, then run:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
corepack enable
|
|
172
|
+
pnpm install --frozen-lockfile
|
|
173
|
+
pnpm check
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
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).
|
|
177
|
+
|
|
178
|
+
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.
|
|
179
|
+
|
|
180
|
+
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.
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
type SchemaVersion = 1;
|
|
2
|
+
type AlgorithmVersion = "1";
|
|
3
|
+
type EventEnvelope = {
|
|
4
|
+
readonly schemaVersion: SchemaVersion;
|
|
5
|
+
readonly scopeId: string;
|
|
6
|
+
readonly eventId: string;
|
|
7
|
+
readonly sequence: number;
|
|
8
|
+
readonly atMs: number;
|
|
9
|
+
};
|
|
10
|
+
type ConceptEvent = EventEnvelope & {
|
|
11
|
+
readonly conceptId: string;
|
|
12
|
+
};
|
|
13
|
+
type PracticeOutcome = "pass" | "fail" | "not_observed";
|
|
14
|
+
type CreditedOutcome = "pass" | "fail";
|
|
15
|
+
type PracticeObservation = ConceptEvent & {
|
|
16
|
+
readonly kind: "practice_observation";
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
readonly outcome: PracticeOutcome;
|
|
19
|
+
readonly fresh?: boolean;
|
|
20
|
+
readonly hints?: number;
|
|
21
|
+
readonly ladder?: number;
|
|
22
|
+
};
|
|
23
|
+
type CreditedEvidence = {
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
readonly outcome: CreditedOutcome;
|
|
26
|
+
readonly fresh: boolean;
|
|
27
|
+
readonly hints: number;
|
|
28
|
+
readonly ladder: number;
|
|
29
|
+
readonly eligibilityPolicyVersion: string;
|
|
30
|
+
};
|
|
31
|
+
type EligibleCreditedRetrieval = ConceptEvent & CreditedEvidence & {
|
|
32
|
+
readonly kind: "eligible_credited_retrieval";
|
|
33
|
+
readonly creditDecisionId: string;
|
|
34
|
+
readonly decisionVersion: 1;
|
|
35
|
+
};
|
|
36
|
+
type CreditedDecisionCorrection = ConceptEvent & {
|
|
37
|
+
readonly kind: "credited_decision_correction";
|
|
38
|
+
readonly supersedesDecisionId: string;
|
|
39
|
+
readonly replacementDecisionId: string;
|
|
40
|
+
readonly decisionVersion: number;
|
|
41
|
+
readonly replacement: CreditedEvidence;
|
|
42
|
+
readonly reasonCode: string;
|
|
43
|
+
};
|
|
44
|
+
type CreditedDecisionRevocation = ConceptEvent & {
|
|
45
|
+
readonly kind: "credited_decision_revocation";
|
|
46
|
+
readonly supersedesDecisionId: string;
|
|
47
|
+
readonly reasonCode: string;
|
|
48
|
+
};
|
|
49
|
+
type ReviewEventDeletion = ConceptEvent & {
|
|
50
|
+
readonly kind: "review_event_deletion";
|
|
51
|
+
readonly targetEventId: string;
|
|
52
|
+
};
|
|
53
|
+
type ReviewScopeDeletion = EventEnvelope & {
|
|
54
|
+
readonly kind: "review_scope_deletion";
|
|
55
|
+
readonly throughSequence: number;
|
|
56
|
+
};
|
|
57
|
+
type ReviewObservation = PracticeObservation | EligibleCreditedRetrieval;
|
|
58
|
+
type CreditControl = CreditedDecisionCorrection | CreditedDecisionRevocation;
|
|
59
|
+
type DeletionControl = ReviewEventDeletion | ReviewScopeDeletion;
|
|
60
|
+
type ReviewControl = CreditControl | DeletionControl;
|
|
61
|
+
type ReviewEvent = ReviewObservation | ReviewControl;
|
|
62
|
+
type CalendarTransition = {
|
|
63
|
+
readonly atMs: number;
|
|
64
|
+
readonly offsetMinutes: number;
|
|
65
|
+
};
|
|
66
|
+
type CalendarProfile = {
|
|
67
|
+
readonly zoneId: string;
|
|
68
|
+
readonly rulesVersion: string;
|
|
69
|
+
readonly coverageStartMs: number;
|
|
70
|
+
readonly coverageEndMs: number;
|
|
71
|
+
readonly initialOffsetMinutes: number;
|
|
72
|
+
readonly transitions: readonly CalendarTransition[];
|
|
73
|
+
};
|
|
74
|
+
type SchedulingFields = {
|
|
75
|
+
readonly intervalsDays: readonly number[];
|
|
76
|
+
readonly retryDays: number;
|
|
77
|
+
readonly maintenanceDays: number;
|
|
78
|
+
readonly supportAfterMisses: number;
|
|
79
|
+
readonly longProbeAction: "restart" | "support" | "keep";
|
|
80
|
+
};
|
|
81
|
+
type SchedulingPolicy = SchedulingFields & ({
|
|
82
|
+
readonly dateArithmetic: "elapsed_milliseconds";
|
|
83
|
+
} | {
|
|
84
|
+
readonly dateArithmetic: "local_calendar_days";
|
|
85
|
+
readonly calendarProfile: CalendarProfile;
|
|
86
|
+
});
|
|
87
|
+
type EligibilityPolicy = {
|
|
88
|
+
readonly eligibilityPolicyVersion: string;
|
|
89
|
+
readonly minSuccesses: number;
|
|
90
|
+
readonly minSessions: number;
|
|
91
|
+
readonly minSpanMs: number;
|
|
92
|
+
readonly requireFresh: boolean;
|
|
93
|
+
readonly maxHints: number;
|
|
94
|
+
readonly minLadder: number;
|
|
95
|
+
readonly onFailure: "reset" | "ignore";
|
|
96
|
+
readonly onNonqualifying: "reset" | "ignore";
|
|
97
|
+
};
|
|
98
|
+
type PriorityWeights = {
|
|
99
|
+
readonly overdue: number;
|
|
100
|
+
readonly support: number;
|
|
101
|
+
readonly relation: number;
|
|
102
|
+
readonly stage: number;
|
|
103
|
+
};
|
|
104
|
+
type Policy = {
|
|
105
|
+
readonly schemaVersion: SchemaVersion;
|
|
106
|
+
readonly algorithmVersion: AlgorithmVersion;
|
|
107
|
+
readonly policyId: string;
|
|
108
|
+
readonly policyVersion: string;
|
|
109
|
+
readonly scheduling: SchedulingPolicy;
|
|
110
|
+
readonly eligibility?: EligibilityPolicy;
|
|
111
|
+
readonly priority?: PriorityWeights;
|
|
112
|
+
};
|
|
113
|
+
type ScheduleState = "unobserved" | "learning" | "reviewing" | "review_ready";
|
|
114
|
+
type PracticeReadiness = "unknown" | "developing" | "review_ready";
|
|
115
|
+
type CandidateReadiness = "unknown" | "developing" | "candidate_ready";
|
|
116
|
+
type RecommendationKind = "ordinary" | "delayed_retrieval" | "transfer" | "support";
|
|
117
|
+
type ReasonCode = "FIRST_PASS" | "EARLY_PASS" | "DUE_PASS" | "MISS" | "RESTART" | "SUPPORT_THRESHOLD" | "FORCED_SUPPORT" | "DELAYED_PROBE" | "MAINTENANCE" | "NO_OBSERVATION" | "CREDIT_CORRECTION" | "CREDIT_REVOCATION" | "EVENT_DELETION" | "SCOPE_DELETION" | "QUALIFYING_SUCCESS" | "CANDIDATE_RESET" | "CANDIDATE_IGNORE";
|
|
118
|
+
type ReviewReason = {
|
|
119
|
+
readonly code: ReasonCode;
|
|
120
|
+
readonly value?: number;
|
|
121
|
+
};
|
|
122
|
+
type ProjectionIdentity = {
|
|
123
|
+
readonly schemaVersion: SchemaVersion;
|
|
124
|
+
readonly algorithmVersion: AlgorithmVersion;
|
|
125
|
+
readonly scopeId: string;
|
|
126
|
+
readonly policyIdentity: string;
|
|
127
|
+
readonly evaluatedAtMs: number;
|
|
128
|
+
readonly watermark: string;
|
|
129
|
+
};
|
|
130
|
+
type PracticeProjection = {
|
|
131
|
+
readonly scheduleState: ScheduleState;
|
|
132
|
+
readonly stageIndex: number | null;
|
|
133
|
+
readonly dueAtMs: number | null;
|
|
134
|
+
readonly lastSeenAtMs: number | null;
|
|
135
|
+
readonly consecutiveMisses: number;
|
|
136
|
+
readonly advisorySuccesses: number;
|
|
137
|
+
readonly needsSupport: boolean;
|
|
138
|
+
readonly recommendationKind: RecommendationKind;
|
|
139
|
+
readonly readiness: PracticeReadiness;
|
|
140
|
+
readonly reasons: readonly ReviewReason[];
|
|
141
|
+
};
|
|
142
|
+
type CandidateProjection = {
|
|
143
|
+
readonly readiness: CandidateReadiness;
|
|
144
|
+
readonly qualifyingSuccesses: number;
|
|
145
|
+
readonly distinctSessions: number;
|
|
146
|
+
readonly firstQualifyingAtMs: number | null;
|
|
147
|
+
readonly lastQualifyingAtMs: number | null;
|
|
148
|
+
readonly qualifyingSpanMs: number;
|
|
149
|
+
readonly reasons: readonly ReviewReason[];
|
|
150
|
+
};
|
|
151
|
+
type ConceptProjection = PracticeProjection & {
|
|
152
|
+
readonly conceptId: string;
|
|
153
|
+
readonly candidate?: CandidateProjection;
|
|
154
|
+
};
|
|
155
|
+
type ReviewResult = {
|
|
156
|
+
readonly identity: ProjectionIdentity;
|
|
157
|
+
readonly concepts: readonly ConceptProjection[];
|
|
158
|
+
readonly appliedEventIds: readonly string[];
|
|
159
|
+
readonly controlEventIds: readonly string[];
|
|
160
|
+
readonly lifecycleReasons: readonly ReviewReason[];
|
|
161
|
+
};
|
|
162
|
+
type ConceptExplanation = {
|
|
163
|
+
readonly conceptId: string;
|
|
164
|
+
readonly practiceReasons: readonly ReviewReason[];
|
|
165
|
+
readonly candidateReasons?: readonly ReviewReason[];
|
|
166
|
+
};
|
|
167
|
+
type ReviewExplanation = {
|
|
168
|
+
readonly lifecycleReasons: readonly ReviewReason[];
|
|
169
|
+
readonly concepts: readonly ConceptExplanation[];
|
|
170
|
+
};
|
|
171
|
+
type ConceptRelation = {
|
|
172
|
+
readonly kind: "prerequisite" | "confusable";
|
|
173
|
+
readonly fromConceptId: string;
|
|
174
|
+
readonly toConceptId: string;
|
|
175
|
+
};
|
|
176
|
+
type PriorityFeatures = {
|
|
177
|
+
readonly overdue: number;
|
|
178
|
+
readonly support: number;
|
|
179
|
+
readonly relation: number;
|
|
180
|
+
readonly stage: number;
|
|
181
|
+
};
|
|
182
|
+
type PriorityReason = {
|
|
183
|
+
readonly code: "OVERDUE_DAYS" | "SUPPORT_NEEDED" | "RELATED_DUE" | "REVIEW_STAGE";
|
|
184
|
+
readonly value: number;
|
|
185
|
+
};
|
|
186
|
+
type DueRecommendation = {
|
|
187
|
+
readonly conceptId: string;
|
|
188
|
+
readonly dueAtMs: number;
|
|
189
|
+
readonly recommendationKind: RecommendationKind;
|
|
190
|
+
readonly score: number;
|
|
191
|
+
readonly features: PriorityFeatures;
|
|
192
|
+
readonly reasons: readonly PriorityReason[];
|
|
193
|
+
};
|
|
194
|
+
type ErrorCode = "INVALID_EVENT" | "SCOPE_MISMATCH" | "EVENT_ID_CONFLICT" | "SEQUENCE_CONFLICT" | "INVALID_CORRECTION" | "MISSING_CORRECTION_TARGET" | "INVALID_POLICY" | "POLICY_MISMATCH" | "INVALID_RELATION" | "INVALID_TIMESTAMP" | "UNSUPPORTED_VERSION" | "REBUILD_REQUIRED" | "CALENDAR_PROFILE_MISMATCH" | "RESOURCE_LIMIT_EXCEEDED";
|
|
195
|
+
type Diagnostic = {
|
|
196
|
+
readonly code: ErrorCode;
|
|
197
|
+
readonly field?: string;
|
|
198
|
+
readonly limit?: number;
|
|
199
|
+
};
|
|
200
|
+
type Result<T> = {
|
|
201
|
+
readonly ok: true;
|
|
202
|
+
readonly value: T;
|
|
203
|
+
} | {
|
|
204
|
+
readonly ok: false;
|
|
205
|
+
readonly errors: readonly Diagnostic[];
|
|
206
|
+
};
|
|
207
|
+
export declare function scheduleDue(inputPolicy: unknown, scopeId: unknown, inputReview: unknown, nowMs: unknown, relations?: unknown, limit?: unknown): Result<readonly DueRecommendation[]>;
|
|
208
|
+
export declare function advanceReview(inputPolicy: unknown, scopeId: unknown, previousIdentity: unknown, previousEvents: unknown, appendedEvents: unknown, nowMs: unknown): Result<ReviewResult>;
|
|
209
|
+
/** Explain a successful replay value; this does not revalidate evidence or run scheduling. */
|
|
210
|
+
export declare function explainReview(input: unknown): Result<ReviewExplanation>;
|
|
211
|
+
export declare function rebuildReview(inputPolicy: unknown, scopeId: unknown, events: unknown, nowMs: unknown): Result<ReviewResult>;
|
|
212
|
+
export declare function evaluateReadiness(inputPolicy: unknown, scopeId: unknown, conceptId: unknown, events: unknown, nowMs: unknown): Result<CandidateProjection | null>;
|
|
213
|
+
/**
|
|
214
|
+
* Validate inert JSON for a single caller-bound scope. Identical events collapse to their first
|
|
215
|
+
* occurrence; the result is not chronological and does not establish admission or lifecycle validity.
|
|
216
|
+
*/
|
|
217
|
+
export declare function validateEvents(scopeId: unknown, events: unknown): Result<readonly ReviewEvent[]>;
|
|
218
|
+
export declare function validatePolicy(input: unknown): Result<Policy>;
|
|
219
|
+
export type { AlgorithmVersion, CalendarProfile, CalendarTransition, CandidateProjection, CandidateReadiness, ConceptExplanation, ConceptProjection, ConceptRelation, CreditControl, CreditedDecisionCorrection, CreditedDecisionRevocation, CreditedEvidence, CreditedOutcome, DeletionControl, Diagnostic, DueRecommendation, EligibilityPolicy, EligibleCreditedRetrieval, ErrorCode, Policy, PracticeObservation, PracticeOutcome, PracticeProjection, PracticeReadiness, PriorityFeatures, PriorityReason, PriorityWeights, ProjectionIdentity, ReasonCode, RecommendationKind, Result, ReviewControl, ReviewEvent, ReviewEventDeletion, ReviewExplanation, ReviewObservation, ReviewReason, ReviewResult, ReviewScopeDeletion, ScheduleState, SchedulingPolicy, SchemaVersion };
|