@mmon-co/ncept-default-theory 2.0.0 → 3.0.0

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/LICENSE CHANGED
@@ -1,21 +1,105 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 mmon-co
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 mmon Co.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Default Theory
2
2
 
3
- `@mmon-co/ncept-default-theory` implements Core's `Theory` interface. It depends on `@mmon-co/ncept-core` through public exports, just as a third-party Theory does; Core does not depend on it. The web Application selects it explicitly. FSRS retention, acquisition, Mission futures, tutor Programs and pedagogical Skills live here. Hosts supply persistence, model calls and their own mechanics.
3
+ `@mmon-co/ncept-default-theory` implements Core's `Theory` interface. It depends on `@mmon-co/ncept-core` through public exports, just as a third-party Theory does; Core does not depend on it. The web Application selects it explicitly. Node retention schedules, acquisition, Mission futures, tutor Programs and pedagogical Skills live here. Hosts supply persistence, model calls and their own mechanics.
4
4
 
5
5
  ## Use
6
6
 
7
- Import `defaultTheory` and `DEFAULT_THEORY_REQUIREMENT` from `@mmon-co/ncept-default-theory`. The executable keeps its identity `default`, version `1.0.0+<commit>` (`dev` outside a deploy) and new-Profile range `~1.0`. This package move changes neither stored observations nor Profile requirements and needs no data migration.
7
+ Import `defaultTheory` and `DEFAULT_THEORY_REQUIREMENT` from `@mmon-co/ncept-default-theory`. The executable has identity `default`, a semver version with build metadata, and a new-Profile range pinned to its current minor. Version 1.4 migrates boolean `pedagogy:review` metadata to tagged schedules on live Patch heads. `fsrs` schedules memory checks, `interval` checks a maintained state or capability after its named number of days, and `never` skips Review. An unset milestone uses `never`; other unset Nodes use `fsrs`.
8
8
 
9
9
  The root exports the implementation's public operations and types. Focused exports are `@mmon-co/ncept-default-theory/path`, `/state`, `/messages` and `/outcomes`.
10
10
 
@@ -22,13 +22,13 @@ The Skills' Markdown is the source. `build-skills.ts` embeds it in Git-ignored `
22
22
 
23
23
  `npm pack --dry-run` from this directory runs `prepack`, rebuilding Core and this package. The archive contains only `dist/`, this README, `LICENSE` and its manifest. Its Core dependency is a registry semver range, not a workspace-only reference.
24
24
 
25
- MIT licensed; see [LICENSE](LICENSE).
25
+ Licensed under the Functional Source License 1.1 with Apache-2.0 as its future licence; see [LICENSE](LICENSE). You may use, change and redistribute this package for anything except offering others a commercial product or service that substitutes for it or does substantially the same thing; that includes selling a Theory derived from it. A learner may run it on their own machine, with or without a paid teacher, and a teacher may use it in their own work; hosting it for paying students is such a service. Each version becomes Apache-2.0 two years after it is made available. Versions up to 2.0.0 were published under MIT and remain so. A Theory written against Core's `Theory` interface without this package's code is not a derived work and takes whatever licence its author chooses. For other terms, write to yz@mmon.co.
26
26
 
27
27
  ## Stored-output version guard
28
28
 
29
29
  `bun test packages/default-theory/test/stored-output.test.ts` compares a fixed graph and observation log with `test/snapshots/stored-output.<major>.<minor>.json`. The ordinary test suite and pre-integration gate run it too. It records tag membership on Nodes, Edges and the learner at several evidence prefixes and clocks, the `pedagogy:` keys those operations read, and observation payloads emitted by recording tools and outcome/day events. It does not record captions, rankings, readings, paths, prompts or build metadata. Like any fixture, it detects changes exercised by that graph and log, not every possible policy change.
30
30
 
31
- A mismatch requires a minor (mechanical migration) or major (non-mechanical migration) bump to `DEFAULT_THEORY_REF` and the corresponding forward data migration. Changed criteria for applying the same tags count as stored-data changes, not patches. Generate the new version's snapshot after making that change. If the diff changes no stored data, refresh the existing snapshot instead:
31
+ A mismatch requires a minor (mechanical migration) or major (non-mechanical migration) bump to `DEFAULT_THEORY_REF` and the corresponding forward data migration. Changed criteria for applying the same tags count as stored-data changes, not patches; when nothing stored changes shape, the step declares no rewrite (`{ from, to }`), and hosts move each Profile's pin and discard its derived state without reading it. Generate the new version's snapshot after making that change. If the diff changes no stored data, refresh the existing snapshot instead:
32
32
 
33
33
  ```sh
34
34
  UPDATE_DEFAULT_THEORY_STORED_OUTPUT=1 bun test packages/default-theory/test/stored-output.test.ts
package/dist/chat.d.ts CHANGED
@@ -70,7 +70,7 @@ export declare const modes: {
70
70
  }[];
71
71
  entry: {
72
72
  required: false;
73
- kinds: ("mission" | "checkpoint" | "goal" | "target")[];
73
+ kinds: ("mission" | "checkpoint" | "target" | "goal")[];
74
74
  };
75
75
  capabilities: readonly HostCapability[];
76
76
  switches: {
package/dist/chat.js CHANGED
@@ -7,9 +7,10 @@ import { skillBody, skillResources, skillsForMode, tutorSystemPrompt } from "./s
7
7
  import { catalogToolsForMode } from "./catalog.js";
8
8
  import { evaluationContext, evaluateWatchedReply } from "./evaluation.js";
9
9
  import { lessonOpening, openingLanguage } from "./opening.js";
10
+ import { nodeReviewSchedule } from "./path.js";
10
11
  const COMMON_CONCEPT_PATCH_PROPERTY = "app:common-concept";
11
12
  const RAISE_WHEN_PROPERTY = "pedagogy:raise-when";
12
- const COMMON_CONCEPT_DOCUMENT_URL = "/ncept/playgrounds/document?material=";
13
+ const DOCS_URL_PROPERTY = "app:docs-url";
13
14
  function metadataValue(ctx, node, property) {
14
15
  const candidates = metadataSetsForEntity(ctx.graph, { kind: "node", id: node }).flatMap((set) => {
15
16
  if (!(property in set.properties))
@@ -46,10 +47,17 @@ function officialDocuments(ctx) {
46
47
  ];
47
48
  });
48
49
  }
49
- function linkedDocuments(documents, messages) {
50
- // A linked official title still counts as offered when the tutor mistypes its destination.
51
- return documents.filter(({ documentId, label }) => messages.some((text) => text.includes(`${COMMON_CONCEPT_DOCUMENT_URL}${encodeURIComponent(documentId)}`) ||
52
- text.replace(/\]\(\s+/g, "](").includes(`[${label}](${COMMON_CONCEPT_DOCUMENT_URL}`)));
50
+ function docsUrl(ctx, node) {
51
+ const url = metadataValue(ctx, node, DOCS_URL_PROPERTY);
52
+ return typeof url === "string" && url.trim() !== "" ? url : undefined;
53
+ }
54
+ function linkedDocuments(ctx, documents, messages) {
55
+ // The label also recognizes links kept in memory from before the public docs.
56
+ const labels = new Set(messages.flatMap((text) => [...text.matchAll(/(?<!!)\[([^\]]+)\]\(\s*[^\s)]+[^)]*\)/g)].map((match) => match[1])));
57
+ return documents.filter(({ node, label }) => {
58
+ const url = docsUrl(ctx, node);
59
+ return labels.has(label) || (url !== undefined && messages.some((text) => text.includes(url)));
60
+ });
53
61
  }
54
62
  /** Exclude Document links already carried by tutor text, in this conversation or a closed Session. */
55
63
  function recommendableAffordances(ctx, documents) {
@@ -59,12 +67,13 @@ function recommendableAffordances(ctx, documents) {
59
67
  ? observation.payload.entries.filter(({ speaker }) => speaker.kind === "tutor").map(({ text }) => text)
60
68
  : []),
61
69
  ];
62
- const offered = new Set(linkedDocuments(documents, told).map(({ node }) => node));
70
+ const offered = new Set(linkedDocuments(ctx, documents, told).map(({ node }) => node));
63
71
  return documents.flatMap((document) => {
64
72
  const state = ctx.state.nodes[document.node];
65
73
  const raiseWhen = metadataValue(ctx, document.node, RAISE_WHEN_PROPERTY);
66
- const documentUrl = `${COMMON_CONCEPT_DOCUMENT_URL}${encodeURIComponent(document.documentId)}`;
67
- if (state === undefined ||
74
+ const documentUrl = docsUrl(ctx, document.node);
75
+ if (documentUrl === undefined ||
76
+ state === undefined ||
68
77
  state.featureUses.length !== 0 ||
69
78
  typeof raiseWhen !== "string" ||
70
79
  raiseWhen.trim() === "" ||
@@ -134,7 +143,11 @@ function* setup(ctx, mode) {
134
143
  if (!ctx.graph.nodes.some(({ id }) => id === node))
135
144
  throw new Error(`Missing Node ${node}`);
136
145
  const prompt = tutorSystemPrompt(mode);
137
- const offered = linkedDocuments(officialDocuments(ctx), ctx.tutorMessages ?? []);
146
+ const offered = linkedDocuments(ctx, officialDocuments(ctx), ctx.tutorMessages ?? []);
147
+ const entry = ctx.entry;
148
+ const intervalNodes = entry?.kind === "review"
149
+ ? entry.nodes.filter((node) => nodeReviewSchedule(ctx.graph, node).kind === "interval")
150
+ : [];
138
151
  return {
139
152
  prompt,
140
153
  context: [
@@ -150,8 +163,13 @@ function* setup(ctx, mode) {
150
163
  : "This Session is attached to no Nodes; name Nodes explicitly where a tool needs them.",
151
164
  ...(ctx.entry === undefined ? [] : [`Session opening (host-resolved facts):\n${JSON.stringify(ctx.entry)}`]),
152
165
  ...(ctx.missions?.length ? [`Current Missions (context data):\n${JSON.stringify(ctx.missions)}`] : []),
153
- ...(ctx.entry?.kind === "review"
154
- ? [`Current Review (frozen batch; check retention, not teach):\n${JSON.stringify(ctx.entry)}`]
166
+ ...(entry?.kind === "review"
167
+ ? [
168
+ `Current Review (frozen batch; check retention, not teach):\n${JSON.stringify({
169
+ ...entry,
170
+ ...(intervalNodes.length > 0 ? { intervalNodes } : {}),
171
+ })}`,
172
+ ]
155
173
  : []),
156
174
  ...(ctx.lesson === undefined
157
175
  ? []
@@ -8,12 +8,15 @@ import { progressDefault, estimateDefault, prepareEstimateDefault } from "./read
8
8
  /** The single default implementation assembly. */
9
9
  export declare const implementation: {
10
10
  id: "default";
11
- version: "1.1.0";
11
+ version: "1.4.0";
12
12
  migrations: readonly Readonly<{
13
13
  from: import("@mmon-co/ncept-core/theory").TheoryDataVersion;
14
14
  to: import("@mmon-co/ncept-core/theory").TheoryDataVersion;
15
- migratePatch(content: import("@mmon-co/ncept-core").PatchContent): import("@mmon-co/ncept-core").PatchContent;
16
- migrate(profile: import("@mmon-co/ncept-core").Profile): import("@mmon-co/ncept-core").Profile;
15
+ migratePatch?(content: import("@mmon-co/ncept-core").PatchContent, graphs?: {
16
+ basesChanged: boolean;
17
+ resolve: (candidate?: import("@mmon-co/ncept-core").PatchContent) => import("@mmon-co/ncept-core").ResolvedGraph;
18
+ }): import("@mmon-co/ncept-core").PatchContent;
19
+ migrate?(profile: import("@mmon-co/ncept-core").Profile): import("@mmon-co/ncept-core").Profile;
17
20
  migrateOutcome?(payload: unknown, profile: import("@mmon-co/ncept-core").Profile): unknown;
18
21
  }>[];
19
22
  initState: typeof initDefaultState;
@@ -74,7 +77,7 @@ export declare const implementation: {
74
77
  }[];
75
78
  entry: {
76
79
  required: false;
77
- kinds: ("mission" | "checkpoint" | "goal" | "target")[];
80
+ kinds: ("mission" | "checkpoint" | "target" | "goal")[];
78
81
  };
79
82
  capabilities: readonly import("@mmon-co/ncept-core/theory").HostCapability[];
80
83
  switches: {
package/dist/index.d.ts CHANGED
@@ -5,8 +5,11 @@ export declare const defaultTheory: {
5
5
  migrations: readonly Readonly<{
6
6
  from: import("@mmon-co/ncept-core").TheoryDataVersion;
7
7
  to: import("@mmon-co/ncept-core").TheoryDataVersion;
8
- migratePatch(content: import("@mmon-co/ncept-core").PatchContent): import("@mmon-co/ncept-core").PatchContent;
9
- migrate(profile: import("@mmon-co/ncept-core").Profile): import("@mmon-co/ncept-core").Profile;
8
+ migratePatch?(content: import("@mmon-co/ncept-core").PatchContent, graphs?: {
9
+ basesChanged: boolean;
10
+ resolve: (candidate?: import("@mmon-co/ncept-core").PatchContent) => import("@mmon-co/ncept-core").ResolvedGraph;
11
+ }): import("@mmon-co/ncept-core").PatchContent;
12
+ migrate?(profile: import("@mmon-co/ncept-core").Profile): import("@mmon-co/ncept-core").Profile;
10
13
  migrateOutcome?(payload: unknown, profile: import("@mmon-co/ncept-core").Profile): unknown;
11
14
  }>[];
12
15
  initState: typeof import("./state.js").initDefaultState;
@@ -67,7 +70,7 @@ export declare const defaultTheory: {
67
70
  }[];
68
71
  entry: {
69
72
  required: false;
70
- kinds: ("mission" | "checkpoint" | "goal" | "target")[];
73
+ kinds: ("mission" | "checkpoint" | "target" | "goal")[];
71
74
  };
72
75
  capabilities: readonly import("@mmon-co/ncept-core").HostCapability[];
73
76
  switches: {
@@ -184,7 +187,7 @@ export declare const defaultTheory: {
184
187
  /** The range a new Profile accepts: the default Theory's current minor, which a patch deploy keeps. */
185
188
  export declare const DEFAULT_THEORY_REQUIREMENT: {
186
189
  readonly theory: "default";
187
- readonly range: "~1.1";
190
+ readonly range: "~1.4";
188
191
  };
189
192
  export * from "./path.js";
190
193
  export * from "./reading.js";
@@ -196,7 +199,7 @@ export * from "./state.js";
196
199
  export * from "./completion.js";
197
200
  export * from "./tags.js";
198
201
  export * from "./outcomes.js";
199
- export { recallToAttemptMigration } from "./migrations.js";
202
+ export { recallToAttemptMigration, reviewScheduleMigration } from "./migrations.js";
200
203
  export * from "./roleplay.js";
201
204
  export * from "./chat.js";
202
205
  export * from "./opening.js";
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ export const defaultTheory = {
6
6
  version: `${implementation.version}+${theoryContent}`,
7
7
  };
8
8
  /** The range a new Profile accepts: the default Theory's current minor, which a patch deploy keeps. */
9
- export const DEFAULT_THEORY_REQUIREMENT = { theory: defaultTheory.id, range: "~1.1" };
9
+ export const DEFAULT_THEORY_REQUIREMENT = { theory: defaultTheory.id, range: "~1.4" };
10
10
  export * from "./path.js";
11
11
  export * from "./reading.js";
12
12
  export * from "./timing.js";
@@ -17,7 +17,7 @@ export * from "./state.js";
17
17
  export * from "./completion.js";
18
18
  export * from "./tags.js";
19
19
  export * from "./outcomes.js";
20
- export { recallToAttemptMigration } from "./migrations.js";
20
+ export { recallToAttemptMigration, reviewScheduleMigration } from "./migrations.js";
21
21
  export * from "./roleplay.js";
22
22
  export * from "./chat.js";
23
23
  export * from "./opening.js";
@@ -1,15 +1,23 @@
1
1
  import { type Profile } from "@mmon-co/ncept-core";
2
- import { type ExactPatchRef } from "@mmon-co/ncept-core/patch";
3
- import type { TheoryMigration } from "@mmon-co/ncept-core/theory";
2
+ import { type PatchContent, type ExactPatchRef } from "@mmon-co/ncept-core/patch";
3
+ import { type TheoryMigration } from "@mmon-co/ncept-core/theory";
4
4
  declare function migratePayload(payload: unknown, revision: ExactPatchRef): unknown;
5
5
  declare function migrate(profile: Profile): Profile;
6
6
  export declare const recallToAttemptMigration: {
7
7
  from: "1.0";
8
8
  to: "1.1";
9
- migratePatch: (content: import("@mmon-co/ncept-core").PatchContent) => import("@mmon-co/ncept-core").PatchContent;
10
9
  migrate: typeof migrate;
11
10
  migrateOutcome: (payload: unknown, profile: Profile) => unknown;
12
11
  migratePayload: typeof migratePayload;
13
12
  };
13
+ export declare const reviewScheduleMigration: {
14
+ from: "1.3";
15
+ to: "1.4";
16
+ migratePatch(content: PatchContent, graphs: {
17
+ basesChanged: boolean;
18
+ resolve: (candidate?: PatchContent) => import("@mmon-co/ncept-core").ResolvedGraph;
19
+ } | undefined): PatchContent;
20
+ migrate(profile: Profile): Profile;
21
+ };
14
22
  export declare const migrations: readonly TheoryMigration[];
15
23
  export {};
@@ -1,5 +1,8 @@
1
- import { attachmentDigest, isObservation } from "@mmon-co/ncept-core";
2
- import { isNodeId } from "@mmon-co/ncept-core/patch";
1
+ import { canonicalJson, attachmentDigest, isObservation } from "@mmon-co/ncept-core";
2
+ import { isNodeId, candidateRevision, nodeCascadedProperty, isMetadataValue, resolvePatchBundle, sameExactPatchRef, } from "@mmon-co/ncept-core/patch";
3
+ import { migrateTheoryPatchClosure } from "@mmon-co/ncept-core/theory";
4
+ import { pathProperty } from "./path.js";
5
+ import { REVIEW_PROPERTY } from "./schedules.js";
3
6
  import { isAttemptOutcome } from "./outcomes.js";
4
7
  function object(value) {
5
8
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -59,9 +62,91 @@ function migrate(profile) {
59
62
  export const recallToAttemptMigration = {
60
63
  from: "1.0",
61
64
  to: "1.1",
62
- migratePatch: (content) => content,
63
65
  migrate,
64
66
  migrateOutcome: (payload, profile) => migratePayload(payload, profile.patches.terminal),
65
67
  migratePayload,
66
68
  };
67
- export const migrations = [recallToAttemptMigration];
69
+ export const reviewScheduleMigration = {
70
+ from: "1.3",
71
+ to: "1.4",
72
+ migratePatch(content, graphs) {
73
+ const sets = content.delta.operations.flatMap((op) => (op.kind === "add-metadata-set" ? [op.metadataSet] : []));
74
+ if (!graphs?.basesChanged &&
75
+ !sets.some(({ properties }) => typeof properties[REVIEW_PROPERTY] === "boolean") &&
76
+ typeof content.metadata.properties[REVIEW_PROPERTY] !== "boolean")
77
+ return content;
78
+ const resolve = graphs?.resolve ??
79
+ ((candidate = content) => {
80
+ const revision = candidateRevision("patch-migrating", candidate);
81
+ return resolvePatchBundle({ terminal: revision.ref, revisions: [revision] });
82
+ });
83
+ const before = resolve();
84
+ const milestone = (id) => pathProperty(before, id, "pedagogy:milestone") === true;
85
+ function rewrite(properties, subjects) {
86
+ const review = properties[REVIEW_PROPERTY];
87
+ return typeof review === "boolean"
88
+ ? {
89
+ ...properties,
90
+ [REVIEW_PROPERTY]: {
91
+ kind: review && !subjects?.every((s) => s.kind === "node" && milestone(s.id)) ? "fsrs" : "never",
92
+ },
93
+ }
94
+ : properties;
95
+ }
96
+ const rewritten = {
97
+ ...content,
98
+ metadata: { ...content.metadata, properties: rewrite(content.metadata.properties) },
99
+ delta: {
100
+ operations: content.delta.operations.map((op) => {
101
+ if (op.kind !== "add-metadata-set")
102
+ return op;
103
+ return {
104
+ ...op,
105
+ metadataSet: { ...op.metadataSet, properties: rewrite(op.metadataSet.properties, op.metadataSet.subjects) },
106
+ };
107
+ }),
108
+ },
109
+ };
110
+ // A single contribution may cover both ordinary Nodes and milestones, including
111
+ // through a tag or across Patch bases. Preserve each effective reading separately.
112
+ const after = resolve(rewritten);
113
+ const additions = [];
114
+ const ids = new Set(after.metadataSets.map((set) => set.id));
115
+ for (const { id } of before.nodes) {
116
+ const old = nodeCascadedProperty(before, id, REVIEW_PROPERTY);
117
+ const fallback = { kind: milestone(id) ? "never" : "fsrs" };
118
+ const wanted = old === false ? { kind: "never" } : old === true || old == null ? fallback : old;
119
+ const actual = nodeCascadedProperty(after, id, REVIEW_PROPERTY) ?? fallback;
120
+ if (canonicalJson(actual) === canonicalJson(wanted))
121
+ continue;
122
+ let key = `metadata-review-${id}`;
123
+ while (ids.has(key))
124
+ key = `${key}-review`;
125
+ ids.add(key);
126
+ if (!isMetadataValue(wanted))
127
+ throw new Error("Invalid inherited Review schedule");
128
+ additions.push({
129
+ kind: "add-metadata-set",
130
+ metadataSet: { id: key, subjects: [{ kind: "node", id }], properties: { [REVIEW_PROPERTY]: wanted } },
131
+ });
132
+ }
133
+ return additions.length
134
+ ? { ...rewritten, delta: { operations: [...rewritten.delta.operations, ...additions] } }
135
+ : rewritten;
136
+ },
137
+ migrate(profile) {
138
+ const { terminal, revisions } = migrateTheoryPatchClosure({ id: "default", version: "1.4.0", migrations: [reviewScheduleMigration] }, profile.patches, { theory: "default", range: "~1.3" });
139
+ return sameExactPatchRef(profile.patches.terminal, terminal.ref)
140
+ ? profile
141
+ : { ...profile, patches: { terminal: terminal.ref, revisions } };
142
+ },
143
+ };
144
+ export const migrations = [
145
+ recallToAttemptMigration,
146
+ // FSRS-6 (ts-fsrs 5) replaces FSRS-5's curve: review tags and path ranks read retrievability,
147
+ // which every Profile recomputes from its unchanged evidence.
148
+ { from: "1.1", to: "1.2" },
149
+ // FSRS-7 (ts-fsrs 6) replaces FSRS-6's single trace with slow and fast traces; likewise derived only.
150
+ { from: "1.2", to: "1.3" },
151
+ reviewScheduleMigration,
152
+ ];
package/dist/path.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { type NodeId, type ResolvedGraph } from "@mmon-co/ncept-core/patch";
2
2
  import { type MissionPath, type MissionFuture, type PathContext } from "@mmon-co/ncept-core/theory";
3
+ import { type ReviewSchedule } from "./schedules.js";
4
+ export { REVIEW_PROPERTY, validateReviewSchedule, type ReviewSchedule } from "./schedules.js";
3
5
  /** Default-theory authoring metadata, not Core graph vocabulary. */
4
6
  export declare function pathProperty(graph: ResolvedGraph, node: NodeId, key: string): unknown;
5
- /** Milestones and one-off steps keep their evidence without entering Review. */
7
+ export declare function nodeReviewSchedule(graph: ResolvedGraph, node: NodeId): ReviewSchedule;
6
8
  export declare function nodeAllowsReview(graph: ResolvedGraph, node: NodeId): boolean;
7
9
  /** Default-theory hint: an absolute integer, higher first, inherited from tags. */
8
10
  export declare function nodePriority(graph: ResolvedGraph, node: NodeId): number;
package/dist/path.js CHANGED
@@ -3,7 +3,8 @@ import { dependentCones } from "./dependent-cone.js";
3
3
  import { LESSON_TAG_PREFIX, tagIndex, } from "@mmon-co/ncept-core/theory";
4
4
  import { prepareEstimateDefault, progressDefault } from "./reading.js";
5
5
  import { DEFAULT_PARAMETERS, stateDefault } from "./state.js";
6
- import { forgetting_curve } from "ts-fsrs";
6
+ import { REVIEW_PROPERTY, retrievabilityAt, sameReviewCurve } from "./schedules.js";
7
+ export { REVIEW_PROPERTY, validateReviewSchedule } from "./schedules.js";
7
8
  /** Default-theory authoring metadata, not Core graph vocabulary. */
8
9
  export function pathProperty(graph, node, key) {
9
10
  return lastMetadataContribution(graph, metadataSetsForEntity(graph, { kind: "node", id: node }).flatMap((set) => {
@@ -11,9 +12,14 @@ export function pathProperty(graph, node, key) {
11
12
  return source === undefined ? [] : [{ value: set.properties[key], source }];
12
13
  }))?.value;
13
14
  }
14
- /** Milestones and one-off steps keep their evidence without entering Review. */
15
+ export function nodeReviewSchedule(graph, node) {
16
+ // Explicit values were validated when their revision was minted.
17
+ // eslint-disable-next-line typescript/consistent-type-assertions
18
+ const review = nodeCascadedProperty(graph, node, REVIEW_PROPERTY);
19
+ return review ?? { kind: pathProperty(graph, node, "pedagogy:milestone") === true ? "never" : "fsrs" };
20
+ }
15
21
  export function nodeAllowsReview(graph, node) {
16
- return (pathProperty(graph, node, "pedagogy:milestone") !== true && pathProperty(graph, node, "pedagogy:review") !== false);
22
+ return nodeReviewSchedule(graph, node).kind !== "never";
17
23
  }
18
24
  /** Default-theory hint: an absolute integer, higher first, inherited from tags. */
19
25
  export function nodePriority(graph, node) {
@@ -208,16 +214,14 @@ function pathValidity(context, scope) {
208
214
  });
209
215
  // Integer priority dominates decay. Identical curves keep even their stable ties forever.
210
216
  const competing = new Set(candidates
211
- .filter((a) => candidates.some((b) => a.priority === b.priority &&
212
- (a.schedule.lastReview !== b.schedule.lastReview || a.schedule.stability !== b.schedule.stability)))
217
+ .filter((a) => candidates.some((b) => a.priority === b.priority && !sameReviewCurve(a.schedule, b.schedule)))
213
218
  .map(({ id }) => id));
214
219
  for (const { id } of context.graph.nodes) {
215
220
  const node = state.nodes[id];
216
221
  const schedule = node?.schedule;
217
- if (!scope.has(id) || !schedule || node.reviewCleared || !nodeAllowsReview(context.graph, id))
222
+ if (!scope.has(id) || !schedule || node.reviewCleared)
218
223
  continue;
219
- const last = Date.parse(schedule.lastReview);
220
- const at = (time) => forgetting_curve((time - last) / 86_400_000, schedule.stability);
224
+ const at = (time) => retrievabilityAt(schedule, time);
221
225
  const nextBelow = (threshold) => {
222
226
  if (threshold <= 0 || at(now) < threshold)
223
227
  return;
package/dist/release.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const theoryContent = "0e02007470e1d43f5b572872ba466de874d22d728e90d06280cde6bc2c4395c9";
1
+ export declare const theoryContent = "6c049d0fff88f3c7c07156c23de1d5e18802ce8ecd58532a36e4be28dc76477c";
package/dist/release.js CHANGED
@@ -1 +1 @@
1
- export const theoryContent = "0e02007470e1d43f5b572872ba466de874d22d728e90d06280cde6bc2c4395c9";
1
+ export const theoryContent = "6c049d0fff88f3c7c07156c23de1d5e18802ce8ecd58532a36e4be28dc76477c";
@@ -0,0 +1,51 @@
1
+ import { type Observation, type ObservationId } from "@mmon-co/ncept-core/observations";
2
+ import type { Demonstration, Grade, HomedRecord, Lapse } from "./state.js";
3
+ export declare const REVIEW_PROPERTY = "pedagogy:review";
4
+ export type ReviewSchedule = {
5
+ kind: "fsrs";
6
+ } | {
7
+ kind: "never";
8
+ } | {
9
+ kind: "interval";
10
+ days: number;
11
+ };
12
+ export type DefaultParameters = Readonly<{
13
+ retention: Readonly<{
14
+ due: number;
15
+ fading: number;
16
+ claimStabilityDays: number;
17
+ }>;
18
+ }>;
19
+ export declare const DEFAULT_PARAMETERS: DefaultParameters;
20
+ interface ScheduleEvidence {
21
+ readonly lastReview: string;
22
+ /** Observed forgetting stays due independently of the decay curve. */
23
+ readonly lapsed: boolean;
24
+ readonly citations: readonly ObservationId[];
25
+ }
26
+ export type ReplayedSchedule = ScheduleEvidence & ({
27
+ readonly kind: "fsrs";
28
+ readonly stability: number;
29
+ readonly stabilityFast: number;
30
+ readonly difficulty: number;
31
+ readonly reps: number;
32
+ readonly lapses: number;
33
+ } | {
34
+ readonly kind: "interval";
35
+ readonly days: number;
36
+ });
37
+ export type NodeSchedule = ReplayedSchedule & {
38
+ readonly retrievability: number;
39
+ };
40
+ type RetentionEvidence = {
41
+ readonly records: readonly HomedRecord[];
42
+ readonly direct: readonly Observation<Demonstration | Lapse>[];
43
+ readonly implicit: readonly HomedRecord[];
44
+ readonly grades: readonly Observation<Grade>[];
45
+ };
46
+ type Replay = (evidence: RetentionEvidence) => ReplayedSchedule | undefined;
47
+ export declare function validateReviewSchedule(value: unknown): void;
48
+ export declare function prepareReviewReplay(schedule: ReviewSchedule): Replay;
49
+ export declare function sameReviewCurve(a: NodeSchedule, b: NodeSchedule): boolean;
50
+ export declare function retrievabilityAt(schedule: ReplayedSchedule, time: number): number;
51
+ export {};