@mmon-co/ncept-default-theory 1.1.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/dist/state.js CHANGED
@@ -1,11 +1,13 @@
1
- import { createEmptyCard, forgetting_curve, fsrs, generatorParameters, Rating } from "ts-fsrs";
2
1
  import { readTheoryState } from "@mmon-co/ncept-core/theory";
3
2
  import { dependentCones } from "./dependent-cone.js";
3
+ import { nodeReviewSchedule } from "./path.js";
4
+ import { prepareReviewReplay, retrievabilityAt } from "./schedules.js";
5
+ export { DEFAULT_PARAMETERS } from "./schedules.js";
4
6
  import { COMPLETION_PROPERTY, compileCompletion, completionBoundary, prepareCompletionHistory, } from "./completion.js";
5
- import { exactPatchRefKey, lastMetadataContribution, metadataSetsForEntity, NODE_CRITERION_PROPERTY, sameExactPatchRef, } from "@mmon-co/ncept-core/patch";
7
+ import { provenanceOf, exactPatchRefKey, lastMetadataContribution, metadataSetsForEntity, NODE_CRITERION_PROPERTY, sameExactPatchRef, } from "@mmon-co/ncept-core/patch";
6
8
  import { compareObservations, isObservationId, isObservationTimestamp, } from "@mmon-co/ncept-core/observations";
7
9
  export const DEFAULT_THEORY_ID = "default";
8
- export const DEFAULT_THEORY_REF = { theory: DEFAULT_THEORY_ID, version: "1.0.0" };
10
+ export const DEFAULT_THEORY_REF = { theory: DEFAULT_THEORY_ID, version: "1.4.0" };
9
11
  function object(value) {
10
12
  return typeof value === "object" && value !== null && !Array.isArray(value);
11
13
  }
@@ -308,7 +310,7 @@ export function homingCandidates(graph) {
308
310
  const value = set.properties[NODE_CRITERION_PROPERTY];
309
311
  if (value === undefined)
310
312
  return [];
311
- const source = graph.provenance.metadataProperties[set.id]?.[NODE_CRITERION_PROPERTY]?.at(-1);
313
+ const source = provenanceOf(graph.provenance.metadataProperties, set.id)?.[NODE_CRITERION_PROPERTY]?.at(-1);
312
314
  if (typeof value !== "string" || source === undefined)
313
315
  throw new Error(`Invalid capability statement for ${id}`);
314
316
  return [{ value, source }];
@@ -360,12 +362,6 @@ export function projectGraphChange(state, graph, next, successors = {}) {
360
362
  ];
361
363
  });
362
364
  }
363
- export const DEFAULT_PARAMETERS = {
364
- retention: { due: 0.9, fading: 0.7, claimStabilityDays: 1 },
365
- };
366
- const DAY_MS = 86_400_000;
367
- /** Daily reviews have no learning steps; disabling fuzz keeps replay deterministic. */
368
- const SCHEDULER = fsrs(generatorParameters({ enable_fuzz: false, enable_short_term: false }));
369
365
  /** The latest tentative competence report, newer than any actual failure. */
370
366
  function knowsClaim(records) {
371
367
  const latest = records.findLast((record) => record.payload.kind === "claim");
@@ -393,64 +389,6 @@ export function labelDefaultNode(input) {
393
389
  records,
394
390
  };
395
391
  }
396
- /** Accepted whole-day grades are the only direct FSRS reviews. Ungraded direct days also
397
- * suppress implicit credit. Core uses host boundaries, never a clock-zone or UTC-day fallback. */
398
- function scheduleDefaultNode(records, implicit, lapses, grades, parameters) {
399
- const direct = [
400
- ...records.flatMap((record) => record.payload.kind === "demonstration" && record.payload.unaided ? [{ ...record, payload: record.payload }] : []),
401
- ...lapses,
402
- ];
403
- const accepted = activeNodeGrades(grades, direct);
404
- const directDays = new Set(direct.flatMap(({ learnerDay }) => (learnerDay === undefined ? [] : [learnerDay.id])));
405
- const credit = implicit.filter(({ learnerDay }) => learnerDay !== undefined && !directDays.has(learnerDay.id));
406
- const claims = records.filter((record) => record.payload.kind === "claim");
407
- let card;
408
- let reviewDay;
409
- let initializingClaim;
410
- let lapsed = false;
411
- const citations = [];
412
- for (const record of [...claims, ...credit, ...accepted].sort(compareObservations)) {
413
- const { payload, at, id } = record;
414
- if (payload.kind === "claim") {
415
- if (payload.stance !== "knows" || card !== undefined)
416
- continue;
417
- card = {
418
- ...SCHEDULER.next(createEmptyCard(at), at, Rating.Good).card,
419
- stability: parameters.retention.claimStabilityDays,
420
- reps: 0,
421
- };
422
- initializingClaim = at;
423
- }
424
- else if (payload.kind === "grade") {
425
- const earlierSuccess = (initializingClaim !== undefined && Date.parse(initializingClaim) < Date.parse(payload.day.start)) ||
426
- direct.some(({ at, payload: evidence }) => evidence.kind === "demonstration" &&
427
- evidence.outcome === "success" &&
428
- Date.parse(at) < Date.parse(payload.day.start));
429
- card = SCHEDULER.next(card ?? createEmptyCard(payload.day.end), payload.day.end, Rating[payload.rating]).card;
430
- lapsed = payload.rating === "Again" && earlierSuccess;
431
- citations.push(...(record.cites ?? []));
432
- }
433
- else {
434
- const day = record.learnerDay;
435
- if (day === undefined || day.id === reviewDay)
436
- continue;
437
- card = SCHEDULER.next(card ?? createEmptyCard(at), at, Rating.Good).card;
438
- reviewDay = day.id;
439
- }
440
- citations.push(id);
441
- }
442
- if (card?.last_review === undefined)
443
- return undefined;
444
- return {
445
- stability: card.stability,
446
- difficulty: card.difficulty,
447
- reps: card.reps,
448
- lapses: card.lapses,
449
- lastReview: card.last_review.toISOString(),
450
- lapsed,
451
- citations: [...new Set(citations)],
452
- };
453
- }
454
392
  /** Resolved Node and tag metadata share the ordinary Patch precedence. */
455
393
  export function defaultNodeCompletion(graph, node, index) {
456
394
  const value = lastMetadataContribution(graph, (index === undefined
@@ -458,7 +396,7 @@ export function defaultNodeCompletion(graph, node, index) {
458
396
  : (index.metadata.get(node) ?? [])).flatMap((set) => {
459
397
  if (!(COMPLETION_PROPERTY in set.properties))
460
398
  return [];
461
- const source = graph.provenance.metadataProperties[set.id]?.[COMPLETION_PROPERTY]?.at(-1);
399
+ const source = provenanceOf(graph.provenance.metadataProperties, set.id)?.[COMPLETION_PROPERTY]?.at(-1);
462
400
  if (source === undefined)
463
401
  throw new Error(`Missing completion provenance for ${node}`);
464
402
  return [{ value: set.properties[COMPLETION_PROPERTY], source }];
@@ -469,7 +407,7 @@ export function defaultNodeCompletion(graph, node, index) {
469
407
  }
470
408
  /** Stable authoring provenance, rather than the terminal of an unrelated graph edit. */
471
409
  export function completionNodeRef(graph, node, nodeIds) {
472
- const provenance = graph.provenance.nodes[node]?.at(-1)?.patch;
410
+ const provenance = provenanceOf(graph.provenance.nodes, node)?.at(-1)?.patch;
473
411
  if (!provenance || !(nodeIds?.has(node) ?? graph.nodes.some(({ id }) => id === node)))
474
412
  throw new Error(`Unknown completion Node ${node}`);
475
413
  return { node, provenance };
@@ -1204,6 +1142,10 @@ export function initDefaultState(graph) {
1204
1142
  const query = defaultNodeCompletion(graph, id, graphIndex);
1205
1143
  return query === undefined ? [] : [[id, { query, evaluate: compileCompletion(query, id) }]];
1206
1144
  }));
1145
+ const reviewPlans = new Map(graph.nodes.flatMap(({ id }) => {
1146
+ const schedule = nodeReviewSchedule(graph, id);
1147
+ return schedule.kind === "never" ? [] : [[id, prepareReviewReplay(schedule)]];
1148
+ }));
1207
1149
  const own = new Map();
1208
1150
  const successes = new Map();
1209
1151
  const schedules = new Map();
@@ -1215,6 +1157,7 @@ export function initDefaultState(graph) {
1215
1157
  let homeless;
1216
1158
  function read(now) {
1217
1159
  const prepared = evidence.read(now);
1160
+ const at = Date.parse(now);
1218
1161
  const { index, homed } = prepared;
1219
1162
  const changedOwn = new Set();
1220
1163
  for (const id of prepared.dirtyNodes) {
@@ -1253,13 +1196,15 @@ export function initDefaultState(graph) {
1253
1196
  }
1254
1197
  const facts = indexed(acquisition.get(id));
1255
1198
  const featureUses = index.featureUses.get(id) ?? [];
1256
- if (!initialized || dirtySchedules.has(id)) {
1199
+ const replay = reviewPlans.get(id);
1200
+ if (replay !== undefined && (!initialized || dirtySchedules.has(id))) {
1257
1201
  const implicit = (graphIndex.dependents.get(id) ?? []).flatMap((node) => successes.get(node) ?? []);
1258
1202
  const records = own.get(id) ?? [];
1259
- const grades = activeNodeGrades(index.grades.get(id) ?? [], [
1203
+ const direct = [
1260
1204
  ...records.flatMap((record) => isDemonstration(record.payload) && record.payload.unaided ? [{ ...record, payload: record.payload }] : []),
1261
1205
  ...(index.lapses.get(id) ?? []),
1262
- ]);
1206
+ ];
1207
+ const grades = activeNodeGrades(index.grades.get(id) ?? [], direct);
1263
1208
  const supportedSuccesses = new Set(records
1264
1209
  .filter(({ payload }) => isDemonstration(payload) && payload.unaided && payload.outcome === "success")
1265
1210
  .map(({ id }) => id));
@@ -1268,15 +1213,10 @@ export function initDefaultState(graph) {
1268
1213
  !grades.some(({ payload }) => Date.parse(payload.day.end) > Date.parse(pass.at))));
1269
1214
  // Grade/support changes and late direct evidence replace the affected day's review;
1270
1215
  // replay only this Node's chronology rather than retaining a second retention state.
1271
- schedules.set(id, scheduleDefaultNode(own.get(id) ?? [], implicit, index.lapses.get(id) ?? [], index.grades.get(id) ?? [], DEFAULT_PARAMETERS));
1216
+ schedules.set(id, replay({ records, direct, implicit, grades }));
1272
1217
  }
1273
1218
  const card = schedules.get(id);
1274
- const schedule = card === undefined
1275
- ? undefined
1276
- : {
1277
- ...card,
1278
- retrievability: forgetting_curve((Date.parse(now) - Date.parse(card.lastReview)) / DAY_MS, card.stability),
1279
- };
1219
+ const schedule = card && { ...card, retrievability: retrievabilityAt(card, at) };
1280
1220
  nodes[id] = {
1281
1221
  ...facts,
1282
1222
  featureUses,
package/dist/tags.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare function defaultNodeState(state: DefaultState, node: NodeId): Nod
6
6
  export declare function isDefaultKnown(node: NodeState): boolean;
7
7
  /** Acquisition withdrawal does not discard a completion-bound Node’s recall schedule. */
8
8
  export declare function isDefaultReviewable(node: NodeState): boolean;
9
+ export declare function isDefaultReviewDue(node: NodeState): boolean;
9
10
  /** A shared reachability answer travels in, so a projection walks the graph for it once. */
10
11
  type QueryToken = (state: DefaultState, graph: ResolvedGraph, reached?: ReadonlySet<NodeId>) => ReadonlySet<NodeId>;
11
12
  export declare const defaultQueryTokens: {
package/dist/tags.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { dependentCones } from "./dependent-cone.js";
2
- import { nodePriority, teachingPath, pathProperty, nodeAllowsReview } from "./path.js";
2
+ import { nodePriority, teachingPath, pathProperty } from "./path.js";
3
3
  import { NODE_ELABORATE_PROPERTY } from "@mmon-co/ncept-core/patch";
4
4
  import { completionCaption } from "./completion.js";
5
5
  import { defaultProjectionBasis, DEFAULT_PARAMETERS, } from "./state.js";
@@ -16,8 +16,11 @@ export function isDefaultKnown(node) {
16
16
  export function isDefaultReviewable(node) {
17
17
  return isDefaultKnown(node) || (node.completion.query !== undefined && node.schedule !== undefined);
18
18
  }
19
+ export function isDefaultReviewDue(node) {
20
+ return node.schedule?.lapsed === true || (node.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.due;
21
+ }
19
22
  function select(predicate) {
20
- return (state, graph) => new Set(graph.nodes.filter(({ id }) => predicate(defaultNodeState(state, id), graph, id)).map(({ id }) => id));
23
+ return (state, graph) => new Set(graph.nodes.filter(({ id }) => predicate(defaultNodeState(state, id))).map(({ id }) => id));
21
24
  }
22
25
  function reachableNodes(state, graph) {
23
26
  return new Set(graph.nodes
@@ -39,12 +42,8 @@ export const defaultQueryTokens = {
39
42
  }),
40
43
  reachable: (state, graph, reached = reachableNodes(state, graph)) => reached,
41
44
  frontier: (state, graph, reached = reachableNodes(state, graph)) => new Set([...reached].filter((id) => !isDefaultKnown(defaultNodeState(state, id)))),
42
- "review:due": select((node, graph, id) => nodeAllowsReview(graph, id) &&
43
- !node.reviewCleared &&
44
- isDefaultReviewable(node) &&
45
- (node.schedule?.lapsed === true || (node.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.due)),
46
- "review:fading": select((node, graph, id) => nodeAllowsReview(graph, id) &&
47
- !node.reviewCleared &&
45
+ "review:due": select((node) => !node.reviewCleared && isDefaultReviewable(node) && isDefaultReviewDue(node)),
46
+ "review:fading": select((node) => !node.reviewCleared &&
48
47
  isDefaultReviewable(node) &&
49
48
  (node.schedule?.lapsed === true || (node.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.fading)),
50
49
  };
package/dist/tools.js CHANGED
@@ -4,13 +4,13 @@ import { projectDefault } from "./tags.js";
4
4
  import { contentDigest } from "@mmon-co/ncept-core/digest";
5
5
  import { CATALOG_MAX_PAGE_SIZE, CATALOG_PAGE_SIZE } from "./catalog-contract.js";
6
6
  import { effectiveObservations, isObservationId, read, write, } from "@mmon-co/ncept-core/observations";
7
- import { materialKey, projectVisualGraph, route } from "@mmon-co/ncept-core/patch";
7
+ import { provenanceOf, materialKey, projectVisualGraph, route } from "@mmon-co/ncept-core/patch";
8
8
  import { readMissionPath } from "@mmon-co/ncept-core/theory/path";
9
9
  import { pathDefault } from "./path.js";
10
10
  import { event, refinePendingHomes } from "./event.js";
11
11
  import { isAttemptOutcome } from "./outcomes.js";
12
- import { activeDefaultRecords, completionNodeRef, electedObservations, assertDefaultRetraction, emptyNodeMemory, interpretationsDefault, isClaim, isDefaultObservation, isDemonstration, isRetrievalOpenerDemonstration, isTeaching, memoryDefault, stateDefault, DEFAULT_THEORY_REF, DEFAULT_PARAMETERS, } from "./state.js";
13
- import { defaultNodeState, defaultQueryTokens, indicatorsDefault, isDefaultKnown, isDefaultReviewable, } from "./tags.js";
12
+ import { activeDefaultRecords, completionNodeRef, electedObservations, assertDefaultRetraction, emptyNodeMemory, interpretationsDefault, isClaim, isDefaultObservation, isDemonstration, isRetrievalOpenerDemonstration, isTeaching, memoryDefault, stateDefault, DEFAULT_THEORY_REF, } from "./state.js";
13
+ import { defaultNodeState, defaultQueryTokens, indicatorsDefault, isDefaultKnown, isDefaultReviewable, isDefaultReviewDue, } from "./tags.js";
14
14
  const nodeProperty = { type: "string", pattern: "^node-.+" };
15
15
  const scopeProperties = { scope: { type: "array", items: nodeProperty } };
16
16
  const surfaceProperty = { type: "string", pattern: "^surface-.+" };
@@ -236,17 +236,11 @@ function lessonCompletion(ctx) {
236
236
  const complete = nodes.every(({ complete }) => complete);
237
237
  return {
238
238
  complete,
239
- status: complete
240
- ? "This Lesson's completion queries hold; the host owns closure and the next Lesson."
241
- : "This Lesson stays open; the next Lesson is not cleared for starting.",
239
+ status: complete ? "This Lesson's completion queries hold." : "This Lesson's completion queries do not yet hold.",
242
240
  nodes,
243
241
  };
244
242
  }
245
243
  function closeRecount(ctx, rawPractising) {
246
- const lesson = lessonCompletion(ctx);
247
- if (lesson !== undefined)
248
- throw new Error("close_recount is for Review. The host closes Lessons when every focus Node's pedagogy:completion query holds.\n" +
249
- JSON.stringify(lesson));
250
244
  const practising = rawPractising === undefined ? [] : rawPractising;
251
245
  if (!Array.isArray(practising))
252
246
  throw new Error("Expected practice directions");
@@ -416,7 +410,7 @@ export const defaultInstrumentTools = [
416
410
  "1. demonstrated: the Node query holds. A Node with no completion is never demonstrated. Aided attempts count only as practice unless the query selects them.",
417
411
  "2. probably-known: an attached knows claim is newer than any failure on this Node.",
418
412
  "3. unknown: otherwise. Only demonstrated and probably-known count as known for routing.",
419
- "Retention is separate: the schedule replays the first unaided attempt per Node per UTC day as Good or Again. Unaided success also gives Good to direct prerequisites, at most once per day; failure never flows down. A diagnosed component regression supplies Again unless its slip is already recorded. An unresolved failure stays due for Review until an unaided success, independently of the forgetting curve. Claims start a short schedule without covering prerequisites. Review tags select ordinary acquired Nodes and scheduled completion-bound Nodes below the retention thresholds, excluding milestones and Nodes with pedagogy:review: false. Scheduled completion-bound Nodes remain eligible despite acquisition withdrawal; incomplete or expired reports do not supply Again.",
413
+ "Retention is separate: the schedule replays each Node's grade for the learner day. Unaided success also gives Good to direct prerequisites, at most once per day; failure never flows down. A diagnosed component regression supplies Again unless its slip is already recorded. An unresolved failure stays due for Review until an unaided success, independently of the forgetting curve. Claims start a short schedule without covering prerequisites. The pedagogy:review schedule is {kind: fsrs} for memory, {kind: never} for no Review, or {kind: interval, days: N} for a check N days after the last one. Unset means never for milestones and fsrs otherwise. Review tags select ordinary acquired Nodes and scheduled completion-bound Nodes below the retention thresholds. Scheduled completion-bound Nodes remain eligible despite acquisition withdrawal; incomplete or expired reports do not supply Again.",
420
414
  "A newer knows claim can follow failure; a later failure defeats that claim unless completion still holds.",
421
415
  ].join("\n"),
422
416
  *run(raw, ctx) {
@@ -433,9 +427,7 @@ export const defaultInstrumentTools = [
433
427
  .map((id) => candidate(ctx, id))),
434
428
  scopedTool("probes", "Claimed or due Nodes with acquisition and retention facts.", (ctx, scope) => readingNodes(ctx, scope).flatMap((id) => {
435
429
  const state = defaultNodeState(ctx.state, id);
436
- return state.label === "probably-known" ||
437
- (isDefaultReviewable(state) &&
438
- (state.schedule?.lapsed === true || (state.schedule?.retrievability ?? 1) < DEFAULT_PARAMETERS.retention.due))
430
+ return state.label === "probably-known" || (isDefaultReviewable(state) && isDefaultReviewDue(state))
439
431
  ? [{ ...candidate(ctx, id), schedule: state.schedule, rule: trail(ctx, id).rule }]
440
432
  : [];
441
433
  })),
@@ -447,7 +439,7 @@ export const defaultInstrumentTools = [
447
439
  .filter((material) => material.about.includes(node))
448
440
  .map((material) => ({
449
441
  material,
450
- provenance: ctx.graph.provenance.materials[materialKey(material)] ?? [],
442
+ provenance: provenanceOf(ctx.graph.provenance.materials, materialKey(material)) ?? [],
451
443
  }))),
452
444
  nodeTool("memory", "Opaque Node memory tail or summary with original Record citations.", (ctx, node) => {
453
445
  const memory = ctx.state.memories[node] ?? emptyNodeMemory(node);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mmon-co/ncept-default-theory",
3
- "version": "1.1.0",
4
- "license": "MIT",
3
+ "version": "3.0.0",
4
+ "license": "FSL-1.1-ALv2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/mmon-co/ncept.git",
@@ -13,6 +13,16 @@
13
13
  "LICENSE"
14
14
  ],
15
15
  "type": "module",
16
+ "imports": {
17
+ "#fsrs-scheduler": {
18
+ "types": "ts-fsrs",
19
+ "default": "@open-spaced-repetition/srs-kit"
20
+ },
21
+ "#fsrs-date": {
22
+ "types": "ts-fsrs",
23
+ "default": "@open-spaced-repetition/srs-kit/chrono/date"
24
+ }
25
+ },
16
26
  "exports": {
17
27
  ".": {
18
28
  "types": "./dist/index.d.ts",
@@ -40,8 +50,9 @@
40
50
  "prepack": "bun run build"
41
51
  },
42
52
  "dependencies": {
43
- "@mmon-co/ncept-core": "^0.2.0",
44
- "ts-fsrs": "^4.0.0",
53
+ "@mmon-co/ncept-core": "^0.4.0",
54
+ "@open-spaced-repetition/srs-kit": "1.0.0",
55
+ "ts-fsrs": "^6.0.0",
45
56
  "yaml": "^2.5.0"
46
57
  },
47
58
  "devDependencies": {