learngraph 0.4.0 → 0.5.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.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Spaced Repetition Scheduler (SM-2 Algorithm)
3
+ *
4
+ * Implements the SuperMemo SM-2 algorithm for optimal review scheduling.
5
+ * Schedules reviews at increasing intervals based on performance.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { SkillId } from '../types/skill.js';
10
+ import type { MasteryState } from '../types/mastery.js';
11
+ import type { GraphStorage } from '../types/storage.js';
12
+ import type { ReviewSchedule, ReviewOptions } from '../types/query.js';
13
+ /**
14
+ * Default options for review scheduling
15
+ */
16
+ export declare const REVIEW_DEFAULTS: Required<ReviewOptions>;
17
+ /**
18
+ * SM-2 algorithm constants
19
+ */
20
+ export declare const SM2_CONSTANTS: {
21
+ /** Minimum easiness factor */
22
+ readonly MIN_EASINESS: 1.3;
23
+ /** Default easiness factor */
24
+ readonly DEFAULT_EASINESS: 2.5;
25
+ /** Maximum easiness factor */
26
+ readonly MAX_EASINESS: 3.5;
27
+ /** Initial interval (days) after first review */
28
+ readonly INITIAL_INTERVAL: 1;
29
+ /** Second interval (days) after second review */
30
+ readonly SECOND_INTERVAL: 6;
31
+ };
32
+ /**
33
+ * Review quality rating (0-5 scale)
34
+ */
35
+ export type ReviewQuality = 0 | 1 | 2 | 3 | 4 | 5;
36
+ /**
37
+ * Learner review state
38
+ */
39
+ export interface ReviewState {
40
+ /** Mastery states for skills (keyed by skill ID) */
41
+ masteryStates: Map<SkillId, MasteryState>;
42
+ }
43
+ /**
44
+ * SM-2 update result
45
+ */
46
+ export interface SM2Result {
47
+ /** New easiness factor */
48
+ easinessFactor: number;
49
+ /** New interval in days */
50
+ intervalDays: number;
51
+ /** Next review date */
52
+ nextReview: Date;
53
+ /** Number of successful repetitions */
54
+ repetitions: number;
55
+ }
56
+ /**
57
+ * Spaced Repetition Scheduler
58
+ *
59
+ * Uses the SM-2 algorithm to schedule optimal review times.
60
+ * The algorithm adjusts intervals based on recall quality:
61
+ * - Quality 5: Perfect response
62
+ * - Quality 4: Correct with hesitation
63
+ * - Quality 3: Correct with difficulty
64
+ * - Quality 2: Incorrect but easily recalled
65
+ * - Quality 1: Incorrect, remembered when shown
66
+ * - Quality 0: Complete blackout
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const scheduler = new SpacedRepetitionScheduler(storage);
71
+ *
72
+ * // Get review schedule
73
+ * const schedule = await scheduler.getSchedule(learnerState);
74
+ * console.log(`${schedule.dueNow.length} reviews due now`);
75
+ *
76
+ * // Update after a review
77
+ * const result = scheduler.calculateNextReview(masteryState, 4); // quality 4
78
+ * console.log(`Next review in ${result.intervalDays} days`);
79
+ * ```
80
+ */
81
+ export declare class SpacedRepetitionScheduler {
82
+ private readonly storage;
83
+ constructor(storage: GraphStorage);
84
+ /**
85
+ * Get the review schedule for a learner
86
+ *
87
+ * @param learner - Current learner state
88
+ * @param options - Schedule options
89
+ * @returns Review schedule with due and upcoming items
90
+ */
91
+ getSchedule(learner: ReviewState, options?: ReviewOptions): Promise<ReviewSchedule>;
92
+ /**
93
+ * Calculate the next review interval using SM-2 algorithm
94
+ *
95
+ * @param currentState - Current mastery state
96
+ * @param quality - Review quality (0-5)
97
+ * @returns Updated SM-2 parameters
98
+ */
99
+ calculateNextReview(currentState: MasteryState, quality: ReviewQuality): SM2Result;
100
+ /**
101
+ * Convert review quality to mastery update
102
+ *
103
+ * @param quality - Review quality (0-5)
104
+ * @returns Mastery level adjustment
105
+ */
106
+ qualityToMasteryAdjustment(quality: ReviewQuality): number;
107
+ /**
108
+ * Calculate next review date based on current mastery state
109
+ */
110
+ private calculateNextReviewDate;
111
+ /**
112
+ * Estimate previous interval from mastery state
113
+ */
114
+ private estimatePreviousInterval;
115
+ /**
116
+ * Calculate review priority
117
+ * Higher priority = more urgent to review
118
+ */
119
+ private calculatePriority;
120
+ }
121
+ /**
122
+ * Create a spaced repetition scheduler
123
+ */
124
+ export declare function createSpacedRepetitionScheduler(storage: GraphStorage): SpacedRepetitionScheduler;
125
+ /**
126
+ * Standalone SM-2 calculation (for use without storage)
127
+ *
128
+ * @param quality - Review quality (0-5)
129
+ * @param previousEasiness - Previous easiness factor
130
+ * @param previousInterval - Previous interval in days
131
+ * @param repetitions - Number of previous successful repetitions
132
+ * @returns Updated SM-2 parameters
133
+ */
134
+ export declare function calculateSM2(quality: ReviewQuality, previousEasiness?: number, previousInterval?: number, repetitions?: number): SM2Result;
135
+ //# sourceMappingURL=spaced-repetition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaced-repetition.d.ts","sourceRoot":"","sources":["../../../src/query/spaced-repetition.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAc,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEnF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,aAAa,CAInD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa;IACxB,8BAA8B;;IAE9B,8BAA8B;;IAE9B,8BAA8B;;IAE9B,iDAAiD;;IAEjD,iDAAiD;;CAEzC,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,aAAa,EAAE,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,0BAA0B;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,UAAU,EAAE,IAAI,CAAC;IACjB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,yBAAyB;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAElD;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC;IAsE1B;;;;;;OAMG;IACH,mBAAmB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,GAAG,SAAS;IAiDlF;;;;;OAKG;IACH,0BAA0B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM;IAY1D;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA6B/B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAehC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAe1B;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,GACpB,yBAAyB,CAE3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,gBAAgB,GAAE,MAAiD,EACnE,gBAAgB,SAAI,EACpB,WAAW,SAAI,GACd,SAAS,CAmCX"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Zone of Proximal Development (ZPD) Calculator
3
+ *
4
+ * Implements Vygotsky's Zone of Proximal Development theory to identify
5
+ * skills that are "just right" for a learner - challenging but achievable.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { SkillNode, SkillId } from '../types/skill.js';
10
+ import type { MasteryState } from '../types/mastery.js';
11
+ import type { GraphStorage } from '../types/storage.js';
12
+ import type { ZPDResult, ZPDOptions } from '../types/query.js';
13
+ /**
14
+ * Default options for ZPD calculation
15
+ */
16
+ export declare const ZPD_DEFAULTS: Required<Omit<ZPDOptions, 'filterTags' | 'filterDomain'>>;
17
+ /**
18
+ * Learner profile for ZPD calculation
19
+ */
20
+ export interface LearnerProfile {
21
+ /** Mastery states for skills (keyed by skill ID) */
22
+ masteryStates: Map<SkillId, MasteryState>;
23
+ /** Estimated learner ability level (0-1, derived from average mastery) */
24
+ abilityLevel?: number;
25
+ }
26
+ /**
27
+ * ZPD Calculator
28
+ *
29
+ * Calculates the Zone of Proximal Development for a learner based on:
30
+ * 1. Current mastery states
31
+ * 2. Prerequisite graph structure
32
+ * 3. Skill difficulty levels
33
+ *
34
+ * A skill is in the ZPD if:
35
+ * - All prerequisites are mastered
36
+ * - The skill is not yet mastered
37
+ * - The skill difficulty is within tolerance of learner ability
38
+ */
39
+ export declare class ZPDCalculator {
40
+ private readonly storage;
41
+ constructor(storage: GraphStorage);
42
+ /**
43
+ * Calculate ZPD for a learner
44
+ *
45
+ * @param learner - Learner profile with mastery states
46
+ * @param options - Calculation options
47
+ * @returns ZPD result with ready skills and blocked skills
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const calculator = new ZPDCalculator(storage);
52
+ *
53
+ * const learner = {
54
+ * masteryStates: new Map([
55
+ * ['skill-1', { skillId: 'skill-1', mastery: 0.9, ... }],
56
+ * ['skill-2', { skillId: 'skill-2', mastery: 0.3, ... }],
57
+ * ])
58
+ * };
59
+ *
60
+ * const zpd = await calculator.calculate(learner);
61
+ * console.log('Ready to learn:', zpd.ready.map(s => s.name));
62
+ * ```
63
+ */
64
+ calculate(learner: LearnerProfile, options?: ZPDOptions): Promise<ZPDResult>;
65
+ /**
66
+ * Get the next recommended skill to learn
67
+ *
68
+ * @param learner - Learner profile
69
+ * @param options - ZPD options
70
+ * @returns The highest priority skill to learn next, or null if none available
71
+ */
72
+ getNextSkill(learner: LearnerProfile, options?: ZPDOptions): Promise<SkillNode | null>;
73
+ /**
74
+ * Check if a specific skill is in the learner's ZPD
75
+ *
76
+ * @param skillId - Skill to check
77
+ * @param learner - Learner profile
78
+ * @returns Object with inZPD status and blocking prerequisites if any
79
+ */
80
+ isInZPD(skillId: SkillId, learner: LearnerProfile): Promise<{
81
+ inZPD: boolean;
82
+ blocking: string[];
83
+ }>;
84
+ /**
85
+ * Calculate learner ability level from mastery states
86
+ */
87
+ private calculateAbilityLevel;
88
+ /**
89
+ * Sort skills by learning priority
90
+ */
91
+ private sortByPriority;
92
+ }
93
+ /**
94
+ * Create a ZPD calculator
95
+ */
96
+ export declare function createZPDCalculator(storage: GraphStorage): ZPDCalculator;
97
+ //# sourceMappingURL=zpd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zpd.d.ts","sourceRoot":"","sources":["../../../src/query/zpd.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,GAAG,cAAc,CAAC,CAIlF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,aAAa,EAAE,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAE1C,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAElD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAsFtF;;;;;;OAMG;IACG,YAAY,CAChB,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAK5B;;;;;;OAMG;IACG,OAAO,CACX,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IA+BlD;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAkB7B;;OAEG;IACH,OAAO,CAAC,cAAc;CAiBvB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAExE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learngraph",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "The world's first AI-powered learning path generator. Transform syllabi into personalized mastery paths with Zone of Proximal Development (ZPD), Bloom's Taxonomy, spaced repetition, and Bayesian Knowledge Tracing built in. Every student's path to mastery.",
5
5
  "author": "Dr. Ernesto Lee <dr.ernesto.lee@gmail.com>",
6
6
  "license": "Apache-2.0",