@vue-skuilder/db 0.1.20 → 0.1.21
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/CLAUDE.md +2 -2
- package/dist/{classroomDB-CZdMBiTU.d.ts → contentSource-BP9hznNV.d.ts} +150 -196
- package/dist/{classroomDB-PxDZTky3.d.cts → contentSource-DsJadoBU.d.cts} +150 -196
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +615 -1758
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +579 -1727
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-D8o6ZnKW.d.ts → dataLayerProvider-CHYrQ5pB.d.cts} +1 -1
- package/dist/{dataLayerProvider-D0MoZMjH.d.cts → dataLayerProvider-MDTxXq2l.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +6 -22
- package/dist/impl/couch/index.d.ts +6 -22
- package/dist/impl/couch/index.js +598 -1769
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +579 -1755
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +22 -6
- package/dist/impl/static/index.d.ts +22 -6
- package/dist/impl/static/index.js +617 -1629
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +607 -1624
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/index.d.cts +64 -56
- package/dist/index.d.ts +64 -56
- package/dist/index.js +1000 -2161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +970 -2127
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -0
- package/dist/pouch/index.js.map +1 -1
- package/dist/pouch/index.mjs +3 -0
- package/dist/pouch/index.mjs.map +1 -1
- package/docs/navigators-architecture.md +2 -9
- package/package.json +3 -3
- package/src/core/interfaces/classroomDB.ts +5 -13
- package/src/core/interfaces/contentSource.ts +6 -66
- package/src/core/interfaces/courseDB.ts +2 -7
- package/src/core/navigators/Pipeline.ts +24 -53
- package/src/core/navigators/PipelineAssembler.ts +1 -1
- package/src/core/navigators/defaults.ts +84 -0
- package/src/core/navigators/{hierarchyDefinition.ts → filters/hierarchyDefinition.ts} +11 -25
- package/src/core/navigators/{interferenceMitigator.ts → filters/interferenceMitigator.ts} +10 -24
- package/src/core/navigators/{relativePriority.ts → filters/relativePriority.ts} +10 -24
- package/src/core/navigators/filters/userTagPreference.ts +1 -16
- package/src/core/navigators/{CompositeGenerator.ts → generators/CompositeGenerator.ts} +15 -64
- package/src/core/navigators/{elo.ts → generators/elo.ts} +13 -63
- package/src/core/navigators/{srs.ts → generators/srs.ts} +11 -40
- package/src/core/navigators/generators/types.ts +1 -1
- package/src/core/navigators/index.ts +36 -91
- package/src/impl/couch/classroomDB.ts +100 -103
- package/src/impl/couch/courseDB.ts +5 -81
- package/src/impl/couch/pouchdb-setup.ts +7 -0
- package/src/impl/static/StaticDataUnpacker.ts +50 -1
- package/src/impl/static/courseDB.ts +76 -37
- package/src/study/SessionController.ts +122 -202
- package/src/study/SourceMixer.ts +65 -0
- package/src/study/TagFilteredContentSource.ts +49 -92
- package/src/study/index.ts +1 -0
- package/src/study/services/CardHydrationService.ts +165 -81
- package/src/util/dataDirectory.ts +1 -1
- package/src/util/index.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +44 -168
- package/tests/core/navigators/Pipeline.test.ts +5 -72
- package/tests/core/navigators/PipelineAssembler.test.ts +8 -58
- package/tests/core/navigators/navigators.test.ts +118 -151
- package/src/core/navigators/hardcodedOrder.ts +0 -163
- package/src/util/tuiLogger.ts +0 -139
- /package/src/core/navigators/{inferredPreference.ts → filters/inferredPreferenceStub.ts} +0 -0
- /package/src/core/navigators/{userGoal.ts → filters/userGoalStub.ts} +0 -0
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
1
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __glob = (map) => (path2) => {
|
|
4
|
-
var fn = map[path2];
|
|
5
|
-
if (fn) return fn();
|
|
6
|
-
throw new Error("Module not found in bundle: " + path2);
|
|
7
|
-
};
|
|
8
2
|
var __esm = (fn, res) => function __init() {
|
|
9
3
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
4
|
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
5
|
|
|
16
6
|
// src/util/logger.ts
|
|
17
7
|
var isDevelopment, logger;
|
|
@@ -124,6 +114,9 @@ var init_pouchdb_setup = __esm({
|
|
|
124
114
|
"use strict";
|
|
125
115
|
PouchDB.plugin(PouchDBFind);
|
|
126
116
|
PouchDB.plugin(PouchDBAuth);
|
|
117
|
+
if (typeof PouchDB.debug !== "undefined") {
|
|
118
|
+
PouchDB.debug.disable();
|
|
119
|
+
}
|
|
127
120
|
PouchDB.defaults({
|
|
128
121
|
// ajax: {
|
|
129
122
|
// timeout: 60000,
|
|
@@ -133,14 +126,6 @@ var init_pouchdb_setup = __esm({
|
|
|
133
126
|
}
|
|
134
127
|
});
|
|
135
128
|
|
|
136
|
-
// src/util/tuiLogger.ts
|
|
137
|
-
var init_tuiLogger = __esm({
|
|
138
|
-
"src/util/tuiLogger.ts"() {
|
|
139
|
-
"use strict";
|
|
140
|
-
init_dataDirectory();
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
129
|
// src/util/dataDirectory.ts
|
|
145
130
|
import * as path from "path";
|
|
146
131
|
import * as os from "os";
|
|
@@ -157,7 +142,7 @@ function getDbPath(dbName) {
|
|
|
157
142
|
var init_dataDirectory = __esm({
|
|
158
143
|
"src/util/dataDirectory.ts"() {
|
|
159
144
|
"use strict";
|
|
160
|
-
|
|
145
|
+
init_logger();
|
|
161
146
|
init_factory();
|
|
162
147
|
}
|
|
163
148
|
});
|
|
@@ -476,195 +461,159 @@ var init_courseLookupDB = __esm({
|
|
|
476
461
|
}
|
|
477
462
|
});
|
|
478
463
|
|
|
479
|
-
// src/core/navigators/
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
var
|
|
487
|
-
|
|
464
|
+
// src/core/navigators/index.ts
|
|
465
|
+
function isGenerator(impl) {
|
|
466
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
467
|
+
}
|
|
468
|
+
function isFilter(impl) {
|
|
469
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
470
|
+
}
|
|
471
|
+
var NavigatorRoles, ContentNavigator;
|
|
472
|
+
var init_navigators = __esm({
|
|
473
|
+
"src/core/navigators/index.ts"() {
|
|
488
474
|
"use strict";
|
|
489
|
-
init_navigators();
|
|
490
475
|
init_logger();
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (generators.length === 0) {
|
|
509
|
-
throw new Error("CompositeGenerator requires at least one generator");
|
|
510
|
-
}
|
|
511
|
-
logger.debug(
|
|
512
|
-
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
513
|
-
);
|
|
514
|
-
}
|
|
476
|
+
NavigatorRoles = {
|
|
477
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
478
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
479
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
480
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
481
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
482
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
483
|
+
};
|
|
484
|
+
ContentNavigator = class {
|
|
485
|
+
/** User interface for this navigation session */
|
|
486
|
+
user;
|
|
487
|
+
/** Course interface for this navigation session */
|
|
488
|
+
course;
|
|
489
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
490
|
+
strategyName;
|
|
491
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
492
|
+
strategyId;
|
|
515
493
|
/**
|
|
516
|
-
*
|
|
494
|
+
* Constructor for standard navigators.
|
|
495
|
+
* Call this from subclass constructors to initialize common fields.
|
|
517
496
|
*
|
|
518
|
-
*
|
|
497
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
498
|
+
* user/course fields directly if needed.
|
|
519
499
|
*/
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
)
|
|
524
|
-
|
|
500
|
+
constructor(user, course, strategyData) {
|
|
501
|
+
this.user = user;
|
|
502
|
+
this.course = course;
|
|
503
|
+
if (strategyData) {
|
|
504
|
+
this.strategyName = strategyData.name;
|
|
505
|
+
this.strategyId = strategyData._id;
|
|
506
|
+
}
|
|
525
507
|
}
|
|
508
|
+
// ============================================================================
|
|
509
|
+
// STRATEGY STATE HELPERS
|
|
510
|
+
// ============================================================================
|
|
511
|
+
//
|
|
512
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
513
|
+
// learned patterns, temporal tracking) in the user database.
|
|
514
|
+
//
|
|
515
|
+
// ============================================================================
|
|
526
516
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* Cards appearing in multiple generators receive a score boost.
|
|
530
|
-
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
531
|
-
*
|
|
532
|
-
* This method supports both the legacy signature (limit only) and the
|
|
533
|
-
* CardGenerator interface signature (limit, context).
|
|
517
|
+
* Unique key identifying this strategy for state storage.
|
|
534
518
|
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
519
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
520
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
521
|
+
* need separate state storage.
|
|
537
522
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
541
|
-
);
|
|
542
|
-
const byCardId = /* @__PURE__ */ new Map();
|
|
543
|
-
for (const cards of results) {
|
|
544
|
-
for (const card of cards) {
|
|
545
|
-
const existing = byCardId.get(card.cardId) || [];
|
|
546
|
-
existing.push(card);
|
|
547
|
-
byCardId.set(card.cardId, existing);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
const merged = [];
|
|
551
|
-
for (const [, cards] of byCardId) {
|
|
552
|
-
const aggregatedScore = this.aggregateScores(cards);
|
|
553
|
-
const finalScore = Math.min(1, aggregatedScore);
|
|
554
|
-
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
555
|
-
const initialScore = cards[0].score;
|
|
556
|
-
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
557
|
-
const reason = this.buildAggregationReason(cards, finalScore);
|
|
558
|
-
merged.push({
|
|
559
|
-
...cards[0],
|
|
560
|
-
score: finalScore,
|
|
561
|
-
provenance: [
|
|
562
|
-
...mergedProvenance,
|
|
563
|
-
{
|
|
564
|
-
strategy: "composite",
|
|
565
|
-
strategyName: "Composite Generator",
|
|
566
|
-
strategyId: "COMPOSITE_GENERATOR",
|
|
567
|
-
action,
|
|
568
|
-
score: finalScore,
|
|
569
|
-
reason
|
|
570
|
-
}
|
|
571
|
-
]
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
523
|
+
get strategyKey() {
|
|
524
|
+
return this.constructor.name;
|
|
575
525
|
}
|
|
576
526
|
/**
|
|
577
|
-
*
|
|
527
|
+
* Get this strategy's persisted state for the current course.
|
|
528
|
+
*
|
|
529
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
530
|
+
* @throws Error if user or course is not initialized
|
|
578
531
|
*/
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
586
|
-
switch (this.aggregationMode) {
|
|
587
|
-
case "max" /* MAX */:
|
|
588
|
-
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
589
|
-
case "average" /* AVERAGE */:
|
|
590
|
-
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
591
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
592
|
-
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
593
|
-
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
594
|
-
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
595
|
-
}
|
|
596
|
-
default:
|
|
597
|
-
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
532
|
+
async getStrategyState() {
|
|
533
|
+
if (!this.user || !this.course) {
|
|
534
|
+
throw new Error(
|
|
535
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
536
|
+
);
|
|
598
537
|
}
|
|
538
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
599
539
|
}
|
|
600
540
|
/**
|
|
601
|
-
*
|
|
541
|
+
* Persist this strategy's state for the current course.
|
|
542
|
+
*
|
|
543
|
+
* @param data - The strategy's data payload to store
|
|
544
|
+
* @throws Error if user or course is not initialized
|
|
602
545
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
case "average" /* AVERAGE */:
|
|
609
|
-
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
610
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
611
|
-
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
612
|
-
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
613
|
-
return avg * frequencyBoost;
|
|
614
|
-
}
|
|
615
|
-
default:
|
|
616
|
-
return scores[0];
|
|
546
|
+
async putStrategyState(data) {
|
|
547
|
+
if (!this.user || !this.course) {
|
|
548
|
+
throw new Error(
|
|
549
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
550
|
+
);
|
|
617
551
|
}
|
|
552
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
618
553
|
}
|
|
619
554
|
/**
|
|
620
|
-
*
|
|
555
|
+
* Factory method to create navigator instances dynamically.
|
|
556
|
+
*
|
|
557
|
+
* @param user - User interface
|
|
558
|
+
* @param course - Course interface
|
|
559
|
+
* @param strategyData - Strategy configuration document
|
|
560
|
+
* @returns the runtime object used to steer a study session.
|
|
621
561
|
*/
|
|
622
|
-
async
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
562
|
+
static async create(user, course, strategyData) {
|
|
563
|
+
const implementingClass = strategyData.implementingClass;
|
|
564
|
+
let NavigatorImpl;
|
|
565
|
+
const variations = [".ts", ".js", ""];
|
|
566
|
+
const dirs = ["filters", "generators"];
|
|
567
|
+
for (const ext of variations) {
|
|
568
|
+
for (const dir of dirs) {
|
|
569
|
+
const loadFrom = `./${dir}/${implementingClass}${ext}`;
|
|
570
|
+
try {
|
|
571
|
+
const module = await import(loadFrom);
|
|
572
|
+
NavigatorImpl = module.default;
|
|
573
|
+
break;
|
|
574
|
+
} catch (e) {
|
|
575
|
+
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
634
576
|
}
|
|
635
577
|
}
|
|
636
578
|
}
|
|
637
|
-
|
|
579
|
+
if (!NavigatorImpl) {
|
|
580
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
581
|
+
}
|
|
582
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
638
583
|
}
|
|
639
584
|
/**
|
|
640
|
-
* Get
|
|
585
|
+
* Get cards with suitability scores and provenance trails.
|
|
586
|
+
*
|
|
587
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
588
|
+
*
|
|
589
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
590
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
591
|
+
* documenting how strategies contributed to the final score.
|
|
592
|
+
*
|
|
593
|
+
* ## Implementation Required
|
|
594
|
+
* All navigation strategies MUST override this method. The base class does
|
|
595
|
+
* not provide a default implementation.
|
|
596
|
+
*
|
|
597
|
+
* ## For Generators
|
|
598
|
+
* Override this method to generate candidates and compute scores based on
|
|
599
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
600
|
+
* initial provenance entry with action='generated'.
|
|
601
|
+
*
|
|
602
|
+
* ## For Filters
|
|
603
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
604
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
605
|
+
*
|
|
606
|
+
* @param limit - Maximum cards to return
|
|
607
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
641
608
|
*/
|
|
642
|
-
async
|
|
643
|
-
|
|
644
|
-
(g) => g instanceof ContentNavigator
|
|
645
|
-
);
|
|
646
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
647
|
-
const seen = /* @__PURE__ */ new Set();
|
|
648
|
-
const merged = [];
|
|
649
|
-
for (const reviews of results) {
|
|
650
|
-
for (const review of reviews) {
|
|
651
|
-
if (!seen.has(review.cardID)) {
|
|
652
|
-
seen.add(review.cardID);
|
|
653
|
-
merged.push(review);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
return merged;
|
|
609
|
+
async getWeightedCards(_limit) {
|
|
610
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
658
611
|
}
|
|
659
612
|
};
|
|
660
613
|
}
|
|
661
614
|
});
|
|
662
615
|
|
|
663
616
|
// src/core/navigators/Pipeline.ts
|
|
664
|
-
var Pipeline_exports = {};
|
|
665
|
-
__export(Pipeline_exports, {
|
|
666
|
-
Pipeline: () => Pipeline
|
|
667
|
-
});
|
|
668
617
|
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
669
618
|
function logPipelineConfig(generator, filters) {
|
|
670
619
|
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
@@ -724,6 +673,11 @@ var init_Pipeline = __esm({
|
|
|
724
673
|
this.filters = filters;
|
|
725
674
|
this.user = user;
|
|
726
675
|
this.course = course;
|
|
676
|
+
course.getCourseConfig().then((cfg) => {
|
|
677
|
+
logger.debug(`[pipeline] Crated pipeline for ${cfg.name}`);
|
|
678
|
+
}).catch((e) => {
|
|
679
|
+
logger.error(`[pipeline] Failed to lookup courseCfg: ${e}`);
|
|
680
|
+
});
|
|
727
681
|
logPipelineConfig(generator, filters);
|
|
728
682
|
}
|
|
729
683
|
/**
|
|
@@ -760,7 +714,13 @@ var init_Pipeline = __esm({
|
|
|
760
714
|
cards.sort((a, b) => b.score - a.score);
|
|
761
715
|
const result = cards.slice(0, limit);
|
|
762
716
|
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
763
|
-
logExecutionSummary(
|
|
717
|
+
logExecutionSummary(
|
|
718
|
+
this.generator.name,
|
|
719
|
+
generatedCount,
|
|
720
|
+
this.filters.length,
|
|
721
|
+
result.length,
|
|
722
|
+
topScores
|
|
723
|
+
);
|
|
764
724
|
logCardProvenance(result, 3);
|
|
765
725
|
return result;
|
|
766
726
|
}
|
|
@@ -809,33 +769,6 @@ var init_Pipeline = __esm({
|
|
|
809
769
|
userElo
|
|
810
770
|
};
|
|
811
771
|
}
|
|
812
|
-
// ===========================================================================
|
|
813
|
-
// Legacy StudyContentSource methods
|
|
814
|
-
// ===========================================================================
|
|
815
|
-
//
|
|
816
|
-
// These delegate to the generator for backward compatibility.
|
|
817
|
-
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
818
|
-
//
|
|
819
|
-
/**
|
|
820
|
-
* Get new cards via legacy API.
|
|
821
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
822
|
-
*/
|
|
823
|
-
async getNewCards(n) {
|
|
824
|
-
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
825
|
-
return this.generator.getNewCards(n);
|
|
826
|
-
}
|
|
827
|
-
return [];
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* Get pending reviews via legacy API.
|
|
831
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
832
|
-
*/
|
|
833
|
-
async getPendingReviews() {
|
|
834
|
-
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
835
|
-
return this.generator.getPendingReviews();
|
|
836
|
-
}
|
|
837
|
-
return [];
|
|
838
|
-
}
|
|
839
772
|
/**
|
|
840
773
|
* Get the course ID for this pipeline.
|
|
841
774
|
*/
|
|
@@ -846,20 +779,154 @@ var init_Pipeline = __esm({
|
|
|
846
779
|
}
|
|
847
780
|
});
|
|
848
781
|
|
|
849
|
-
// src/core/navigators/
|
|
850
|
-
var
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
});
|
|
854
|
-
var PipelineAssembler;
|
|
855
|
-
var init_PipelineAssembler = __esm({
|
|
856
|
-
"src/core/navigators/PipelineAssembler.ts"() {
|
|
782
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
783
|
+
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
784
|
+
var init_CompositeGenerator = __esm({
|
|
785
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
857
786
|
"use strict";
|
|
858
787
|
init_navigators();
|
|
859
|
-
init_Pipeline();
|
|
860
|
-
init_types_legacy();
|
|
861
788
|
init_logger();
|
|
862
|
-
|
|
789
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
790
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
791
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
792
|
+
/** Human-readable name for CardGenerator interface */
|
|
793
|
+
name = "Composite Generator";
|
|
794
|
+
generators;
|
|
795
|
+
aggregationMode;
|
|
796
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
797
|
+
super();
|
|
798
|
+
this.generators = generators;
|
|
799
|
+
this.aggregationMode = aggregationMode;
|
|
800
|
+
if (generators.length === 0) {
|
|
801
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
802
|
+
}
|
|
803
|
+
logger.debug(
|
|
804
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Creates a CompositeGenerator from strategy data.
|
|
809
|
+
*
|
|
810
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
811
|
+
*/
|
|
812
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
813
|
+
const generators = await Promise.all(
|
|
814
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
815
|
+
);
|
|
816
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
820
|
+
*
|
|
821
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
822
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
823
|
+
*
|
|
824
|
+
* This method supports both the legacy signature (limit only) and the
|
|
825
|
+
* CardGenerator interface signature (limit, context).
|
|
826
|
+
*
|
|
827
|
+
* @param limit - Maximum number of cards to return
|
|
828
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
829
|
+
*/
|
|
830
|
+
async getWeightedCards(limit, context) {
|
|
831
|
+
if (!context) {
|
|
832
|
+
throw new Error(
|
|
833
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
const results = await Promise.all(
|
|
837
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
838
|
+
);
|
|
839
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
840
|
+
for (const cards of results) {
|
|
841
|
+
for (const card of cards) {
|
|
842
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
843
|
+
existing.push(card);
|
|
844
|
+
byCardId.set(card.cardId, existing);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
const merged = [];
|
|
848
|
+
for (const [, cards] of byCardId) {
|
|
849
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
850
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
851
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
852
|
+
const initialScore = cards[0].score;
|
|
853
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
854
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
855
|
+
merged.push({
|
|
856
|
+
...cards[0],
|
|
857
|
+
score: finalScore,
|
|
858
|
+
provenance: [
|
|
859
|
+
...mergedProvenance,
|
|
860
|
+
{
|
|
861
|
+
strategy: "composite",
|
|
862
|
+
strategyName: "Composite Generator",
|
|
863
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
864
|
+
action,
|
|
865
|
+
score: finalScore,
|
|
866
|
+
reason
|
|
867
|
+
}
|
|
868
|
+
]
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Build human-readable reason for score aggregation.
|
|
875
|
+
*/
|
|
876
|
+
buildAggregationReason(cards, finalScore) {
|
|
877
|
+
const count = cards.length;
|
|
878
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
879
|
+
if (count === 1) {
|
|
880
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
881
|
+
}
|
|
882
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
883
|
+
switch (this.aggregationMode) {
|
|
884
|
+
case "max" /* MAX */:
|
|
885
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
886
|
+
case "average" /* AVERAGE */:
|
|
887
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
888
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
889
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
890
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
891
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
892
|
+
}
|
|
893
|
+
default:
|
|
894
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Aggregate scores from multiple generators for the same card.
|
|
899
|
+
*/
|
|
900
|
+
aggregateScores(cards) {
|
|
901
|
+
const scores = cards.map((c) => c.score);
|
|
902
|
+
switch (this.aggregationMode) {
|
|
903
|
+
case "max" /* MAX */:
|
|
904
|
+
return Math.max(...scores);
|
|
905
|
+
case "average" /* AVERAGE */:
|
|
906
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
907
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
908
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
909
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
910
|
+
return avg * frequencyBoost;
|
|
911
|
+
}
|
|
912
|
+
default:
|
|
913
|
+
return scores[0];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
921
|
+
var PipelineAssembler;
|
|
922
|
+
var init_PipelineAssembler = __esm({
|
|
923
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
924
|
+
"use strict";
|
|
925
|
+
init_navigators();
|
|
926
|
+
init_Pipeline();
|
|
927
|
+
init_types_legacy();
|
|
928
|
+
init_logger();
|
|
929
|
+
init_CompositeGenerator();
|
|
863
930
|
PipelineAssembler = class {
|
|
864
931
|
/**
|
|
865
932
|
* Assembles a navigation pipeline from strategy documents.
|
|
@@ -971,15 +1038,11 @@ var init_PipelineAssembler = __esm({
|
|
|
971
1038
|
}
|
|
972
1039
|
});
|
|
973
1040
|
|
|
974
|
-
// src/core/navigators/elo.ts
|
|
975
|
-
var elo_exports = {};
|
|
976
|
-
__export(elo_exports, {
|
|
977
|
-
default: () => ELONavigator
|
|
978
|
-
});
|
|
1041
|
+
// src/core/navigators/generators/elo.ts
|
|
979
1042
|
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
980
1043
|
var ELONavigator;
|
|
981
1044
|
var init_elo = __esm({
|
|
982
|
-
"src/core/navigators/elo.ts"() {
|
|
1045
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
983
1046
|
"use strict";
|
|
984
1047
|
init_navigators();
|
|
985
1048
|
ELONavigator = class extends ContentNavigator {
|
|
@@ -989,1403 +1052,257 @@ var init_elo = __esm({
|
|
|
989
1052
|
super(user, course, strategyData);
|
|
990
1053
|
this.name = strategyData?.name || "ELO";
|
|
991
1054
|
}
|
|
992
|
-
async getPendingReviews() {
|
|
993
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
994
|
-
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
995
|
-
const ratedReviews = reviews.map((r, i) => {
|
|
996
|
-
const ratedR = {
|
|
997
|
-
...r,
|
|
998
|
-
...elo[i]
|
|
999
|
-
};
|
|
1000
|
-
return ratedR;
|
|
1001
|
-
});
|
|
1002
|
-
ratedReviews.sort((a, b) => {
|
|
1003
|
-
return a.global.score - b.global.score;
|
|
1004
|
-
});
|
|
1005
|
-
return ratedReviews.map((r) => {
|
|
1006
|
-
return {
|
|
1007
|
-
...r,
|
|
1008
|
-
contentSourceType: "course",
|
|
1009
|
-
contentSourceID: this.course.getCourseID(),
|
|
1010
|
-
cardID: r.cardId,
|
|
1011
|
-
courseID: r.courseId,
|
|
1012
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1013
|
-
reviewID: r._id,
|
|
1014
|
-
status: "review"
|
|
1015
|
-
};
|
|
1016
|
-
});
|
|
1017
|
-
}
|
|
1018
|
-
async getNewCards(limit = 99) {
|
|
1019
|
-
const activeCards = await this.user.getActiveCards();
|
|
1020
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
1021
|
-
{ limit, elo: "user" },
|
|
1022
|
-
(c) => {
|
|
1023
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1024
|
-
return false;
|
|
1025
|
-
} else {
|
|
1026
|
-
return true;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
)).map((c) => {
|
|
1030
|
-
return {
|
|
1031
|
-
...c,
|
|
1032
|
-
status: "new"
|
|
1033
|
-
};
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
1055
|
/**
|
|
1037
1056
|
* Get new cards with suitability scores based on ELO distance.
|
|
1038
1057
|
*
|
|
1039
1058
|
* Cards closer to user's ELO get higher scores.
|
|
1040
1059
|
* Score formula: max(0, 1 - distance / 500)
|
|
1041
1060
|
*
|
|
1042
|
-
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1043
|
-
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1044
|
-
*
|
|
1045
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1046
|
-
* CardGenerator interface signature (limit, context).
|
|
1047
|
-
*
|
|
1048
|
-
* @param limit - Maximum number of cards to return
|
|
1049
|
-
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1050
|
-
*/
|
|
1051
|
-
async getWeightedCards(limit, context) {
|
|
1052
|
-
let userGlobalElo;
|
|
1053
|
-
if (context?.userElo !== void 0) {
|
|
1054
|
-
userGlobalElo = context.userElo;
|
|
1055
|
-
} else {
|
|
1056
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1057
|
-
const userElo = toCourseElo3(courseReg.elo);
|
|
1058
|
-
userGlobalElo = userElo.global.score;
|
|
1059
|
-
}
|
|
1060
|
-
const newCards = await this.getNewCards(limit);
|
|
1061
|
-
const cardIds = newCards.map((c) => c.cardID);
|
|
1062
|
-
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1063
|
-
const scored = newCards.map((c, i) => {
|
|
1064
|
-
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1065
|
-
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1066
|
-
const score = Math.max(0, 1 - distance / 500);
|
|
1067
|
-
return {
|
|
1068
|
-
cardId: c.cardID,
|
|
1069
|
-
courseId: c.courseID,
|
|
1070
|
-
score,
|
|
1071
|
-
provenance: [
|
|
1072
|
-
{
|
|
1073
|
-
strategy: "elo",
|
|
1074
|
-
strategyName: this.strategyName || this.name,
|
|
1075
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1076
|
-
action: "generated",
|
|
1077
|
-
score,
|
|
1078
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1079
|
-
}
|
|
1080
|
-
]
|
|
1081
|
-
};
|
|
1082
|
-
});
|
|
1083
|
-
scored.sort((a, b) => b.score - a.score);
|
|
1084
|
-
return scored.slice(0, limit);
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
// src/core/navigators/filters/eloDistance.ts
|
|
1091
|
-
var eloDistance_exports = {};
|
|
1092
|
-
__export(eloDistance_exports, {
|
|
1093
|
-
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1094
|
-
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1095
|
-
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1096
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1097
|
-
});
|
|
1098
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1099
|
-
const normalizedDistance = distance / halfLife;
|
|
1100
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1101
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1102
|
-
}
|
|
1103
|
-
function createEloDistanceFilter(config) {
|
|
1104
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1105
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1106
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1107
|
-
return {
|
|
1108
|
-
name: "ELO Distance Filter",
|
|
1109
|
-
async transform(cards, context) {
|
|
1110
|
-
const { course, userElo } = context;
|
|
1111
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1112
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1113
|
-
return cards.map((card, i) => {
|
|
1114
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1115
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1116
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1117
|
-
const newScore = card.score * multiplier;
|
|
1118
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1119
|
-
return {
|
|
1120
|
-
...card,
|
|
1121
|
-
score: newScore,
|
|
1122
|
-
provenance: [
|
|
1123
|
-
...card.provenance,
|
|
1124
|
-
{
|
|
1125
|
-
strategy: "eloDistance",
|
|
1126
|
-
strategyName: "ELO Distance Filter",
|
|
1127
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1128
|
-
action,
|
|
1129
|
-
score: newScore,
|
|
1130
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1131
|
-
}
|
|
1132
|
-
]
|
|
1133
|
-
};
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
}
|
|
1138
|
-
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1139
|
-
var init_eloDistance = __esm({
|
|
1140
|
-
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1141
|
-
"use strict";
|
|
1142
|
-
DEFAULT_HALF_LIFE = 200;
|
|
1143
|
-
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1144
|
-
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
// src/core/navigators/filters/userTagPreference.ts
|
|
1149
|
-
var userTagPreference_exports = {};
|
|
1150
|
-
__export(userTagPreference_exports, {
|
|
1151
|
-
default: () => UserTagPreferenceFilter
|
|
1152
|
-
});
|
|
1153
|
-
var UserTagPreferenceFilter;
|
|
1154
|
-
var init_userTagPreference = __esm({
|
|
1155
|
-
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1156
|
-
"use strict";
|
|
1157
|
-
init_navigators();
|
|
1158
|
-
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1159
|
-
_strategyData;
|
|
1160
|
-
/** Human-readable name for CardFilter interface */
|
|
1161
|
-
name;
|
|
1162
|
-
constructor(user, course, strategyData) {
|
|
1163
|
-
super(user, course, strategyData);
|
|
1164
|
-
this._strategyData = strategyData;
|
|
1165
|
-
this.name = strategyData.name || "User Tag Preferences";
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Compute multiplier for a card based on its tags and user preferences.
|
|
1169
|
-
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1170
|
-
*/
|
|
1171
|
-
computeMultiplier(cardTags, boostMap) {
|
|
1172
|
-
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1173
|
-
if (multipliers.length === 0) {
|
|
1174
|
-
return 1;
|
|
1175
|
-
}
|
|
1176
|
-
return Math.max(...multipliers);
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* Build human-readable reason for the filter's decision.
|
|
1180
|
-
*/
|
|
1181
|
-
buildReason(cardTags, boostMap, multiplier) {
|
|
1182
|
-
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1183
|
-
if (multiplier === 0) {
|
|
1184
|
-
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1185
|
-
}
|
|
1186
|
-
if (multiplier < 1) {
|
|
1187
|
-
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1188
|
-
}
|
|
1189
|
-
if (multiplier > 1) {
|
|
1190
|
-
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1191
|
-
}
|
|
1192
|
-
return "No matching user preferences";
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* CardFilter.transform implementation.
|
|
1196
|
-
*
|
|
1197
|
-
* Apply user tag preferences:
|
|
1198
|
-
* 1. Read preferences from strategy state
|
|
1199
|
-
* 2. If no preferences, pass through unchanged
|
|
1200
|
-
* 3. For each card:
|
|
1201
|
-
* - Look up tag in boost record
|
|
1202
|
-
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1203
|
-
* - If multiple tags match: use max multiplier
|
|
1204
|
-
* - Append provenance with clear reason
|
|
1205
|
-
*/
|
|
1206
|
-
async transform(cards, _context) {
|
|
1207
|
-
const prefs = await this.getStrategyState();
|
|
1208
|
-
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1209
|
-
return cards.map((card) => ({
|
|
1210
|
-
...card,
|
|
1211
|
-
provenance: [
|
|
1212
|
-
...card.provenance,
|
|
1213
|
-
{
|
|
1214
|
-
strategy: "userTagPreference",
|
|
1215
|
-
strategyName: this.strategyName || this.name,
|
|
1216
|
-
strategyId: this.strategyId || this._strategyData._id,
|
|
1217
|
-
action: "passed",
|
|
1218
|
-
score: card.score,
|
|
1219
|
-
reason: "No user tag preferences configured"
|
|
1220
|
-
}
|
|
1221
|
-
]
|
|
1222
|
-
}));
|
|
1223
|
-
}
|
|
1224
|
-
const adjusted = await Promise.all(
|
|
1225
|
-
cards.map(async (card) => {
|
|
1226
|
-
const cardTags = card.tags ?? [];
|
|
1227
|
-
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1228
|
-
const finalScore = Math.min(1, card.score * multiplier);
|
|
1229
|
-
let action;
|
|
1230
|
-
if (multiplier === 0 || multiplier < 1) {
|
|
1231
|
-
action = "penalized";
|
|
1232
|
-
} else if (multiplier > 1) {
|
|
1233
|
-
action = "boosted";
|
|
1234
|
-
} else {
|
|
1235
|
-
action = "passed";
|
|
1236
|
-
}
|
|
1237
|
-
return {
|
|
1238
|
-
...card,
|
|
1239
|
-
score: finalScore,
|
|
1240
|
-
provenance: [
|
|
1241
|
-
...card.provenance,
|
|
1242
|
-
{
|
|
1243
|
-
strategy: "userTagPreference",
|
|
1244
|
-
strategyName: this.strategyName || this.name,
|
|
1245
|
-
strategyId: this.strategyId || this._strategyData._id,
|
|
1246
|
-
action,
|
|
1247
|
-
score: finalScore,
|
|
1248
|
-
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1249
|
-
}
|
|
1250
|
-
]
|
|
1251
|
-
};
|
|
1252
|
-
})
|
|
1253
|
-
);
|
|
1254
|
-
return adjusted;
|
|
1255
|
-
}
|
|
1256
|
-
/**
|
|
1257
|
-
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1258
|
-
*/
|
|
1259
|
-
async getWeightedCards(_limit) {
|
|
1260
|
-
throw new Error(
|
|
1261
|
-
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1262
|
-
);
|
|
1263
|
-
}
|
|
1264
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1265
|
-
async getNewCards(_n) {
|
|
1266
|
-
return [];
|
|
1267
|
-
}
|
|
1268
|
-
async getPendingReviews() {
|
|
1269
|
-
return [];
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
});
|
|
1274
|
-
|
|
1275
|
-
// src/core/navigators/filters/index.ts
|
|
1276
|
-
var filters_exports = {};
|
|
1277
|
-
__export(filters_exports, {
|
|
1278
|
-
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1279
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1280
|
-
});
|
|
1281
|
-
var init_filters = __esm({
|
|
1282
|
-
"src/core/navigators/filters/index.ts"() {
|
|
1283
|
-
"use strict";
|
|
1284
|
-
init_eloDistance();
|
|
1285
|
-
init_userTagPreference();
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
// src/core/navigators/filters/types.ts
|
|
1290
|
-
var types_exports = {};
|
|
1291
|
-
var init_types = __esm({
|
|
1292
|
-
"src/core/navigators/filters/types.ts"() {
|
|
1293
|
-
"use strict";
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
// src/core/navigators/generators/index.ts
|
|
1298
|
-
var generators_exports = {};
|
|
1299
|
-
var init_generators = __esm({
|
|
1300
|
-
"src/core/navigators/generators/index.ts"() {
|
|
1301
|
-
"use strict";
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
1304
|
-
|
|
1305
|
-
// src/core/navigators/generators/types.ts
|
|
1306
|
-
var types_exports2 = {};
|
|
1307
|
-
var init_types2 = __esm({
|
|
1308
|
-
"src/core/navigators/generators/types.ts"() {
|
|
1309
|
-
"use strict";
|
|
1310
|
-
}
|
|
1311
|
-
});
|
|
1312
|
-
|
|
1313
|
-
// src/core/navigators/hardcodedOrder.ts
|
|
1314
|
-
var hardcodedOrder_exports = {};
|
|
1315
|
-
__export(hardcodedOrder_exports, {
|
|
1316
|
-
default: () => HardcodedOrderNavigator
|
|
1317
|
-
});
|
|
1318
|
-
var HardcodedOrderNavigator;
|
|
1319
|
-
var init_hardcodedOrder = __esm({
|
|
1320
|
-
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1321
|
-
"use strict";
|
|
1322
|
-
init_navigators();
|
|
1323
|
-
init_logger();
|
|
1324
|
-
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1325
|
-
/** Human-readable name for CardGenerator interface */
|
|
1326
|
-
name;
|
|
1327
|
-
orderedCardIds = [];
|
|
1328
|
-
constructor(user, course, strategyData) {
|
|
1329
|
-
super(user, course, strategyData);
|
|
1330
|
-
this.name = strategyData.name || "Hardcoded Order";
|
|
1331
|
-
if (strategyData.serializedData) {
|
|
1332
|
-
try {
|
|
1333
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1334
|
-
} catch (e) {
|
|
1335
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
async getPendingReviews() {
|
|
1340
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1341
|
-
return reviews.map((r) => {
|
|
1342
|
-
return {
|
|
1343
|
-
...r,
|
|
1344
|
-
contentSourceType: "course",
|
|
1345
|
-
contentSourceID: this.course.getCourseID(),
|
|
1346
|
-
cardID: r.cardId,
|
|
1347
|
-
courseID: r.courseId,
|
|
1348
|
-
reviewID: r._id,
|
|
1349
|
-
status: "review"
|
|
1350
|
-
};
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
|
-
async getNewCards(limit = 99) {
|
|
1354
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1355
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1356
|
-
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1357
|
-
return cardsToReturn.map((cardId) => {
|
|
1358
|
-
return {
|
|
1359
|
-
cardID: cardId,
|
|
1360
|
-
courseID: this.course.getCourseID(),
|
|
1361
|
-
contentSourceType: "course",
|
|
1362
|
-
contentSourceID: this.course.getCourseID(),
|
|
1363
|
-
status: "new"
|
|
1364
|
-
};
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
* Get cards in hardcoded order with scores based on position.
|
|
1369
|
-
*
|
|
1370
|
-
* Earlier cards in the sequence get higher scores.
|
|
1371
|
-
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1372
|
-
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1373
|
-
*
|
|
1374
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1375
|
-
* CardGenerator interface signature (limit, context).
|
|
1376
|
-
*
|
|
1377
|
-
* @param limit - Maximum number of cards to return
|
|
1378
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1379
|
-
*/
|
|
1380
|
-
async getWeightedCards(limit, _context) {
|
|
1381
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1382
|
-
const reviews = await this.getPendingReviews();
|
|
1383
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1384
|
-
const totalCards = newCardIds.length;
|
|
1385
|
-
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1386
|
-
const position = index + 1;
|
|
1387
|
-
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1388
|
-
return {
|
|
1389
|
-
cardId,
|
|
1390
|
-
courseId: this.course.getCourseID(),
|
|
1391
|
-
score,
|
|
1392
|
-
provenance: [
|
|
1393
|
-
{
|
|
1394
|
-
strategy: "hardcodedOrder",
|
|
1395
|
-
strategyName: this.strategyName || this.name,
|
|
1396
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1397
|
-
action: "generated",
|
|
1398
|
-
score,
|
|
1399
|
-
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1400
|
-
}
|
|
1401
|
-
]
|
|
1402
|
-
};
|
|
1403
|
-
});
|
|
1404
|
-
const scoredReviews = reviews.map((r) => ({
|
|
1405
|
-
cardId: r.cardID,
|
|
1406
|
-
courseId: r.courseID,
|
|
1407
|
-
score: 1,
|
|
1408
|
-
provenance: [
|
|
1409
|
-
{
|
|
1410
|
-
strategy: "hardcodedOrder",
|
|
1411
|
-
strategyName: this.strategyName || this.name,
|
|
1412
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1413
|
-
action: "generated",
|
|
1414
|
-
score: 1,
|
|
1415
|
-
reason: "Scheduled review, highest priority"
|
|
1416
|
-
}
|
|
1417
|
-
]
|
|
1418
|
-
}));
|
|
1419
|
-
const all = [...scoredReviews, ...scoredNew];
|
|
1420
|
-
all.sort((a, b) => b.score - a.score);
|
|
1421
|
-
return all.slice(0, limit);
|
|
1422
|
-
}
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
});
|
|
1426
|
-
|
|
1427
|
-
// src/core/navigators/hierarchyDefinition.ts
|
|
1428
|
-
var hierarchyDefinition_exports = {};
|
|
1429
|
-
__export(hierarchyDefinition_exports, {
|
|
1430
|
-
default: () => HierarchyDefinitionNavigator
|
|
1431
|
-
});
|
|
1432
|
-
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1433
|
-
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1434
|
-
var init_hierarchyDefinition = __esm({
|
|
1435
|
-
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1436
|
-
"use strict";
|
|
1437
|
-
init_navigators();
|
|
1438
|
-
DEFAULT_MIN_COUNT = 3;
|
|
1439
|
-
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1440
|
-
config;
|
|
1441
|
-
_strategyData;
|
|
1442
|
-
/** Human-readable name for CardFilter interface */
|
|
1443
|
-
name;
|
|
1444
|
-
constructor(user, course, _strategyData) {
|
|
1445
|
-
super(user, course, _strategyData);
|
|
1446
|
-
this._strategyData = _strategyData;
|
|
1447
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1448
|
-
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1449
|
-
}
|
|
1450
|
-
parseConfig(serializedData) {
|
|
1451
|
-
try {
|
|
1452
|
-
const parsed = JSON.parse(serializedData);
|
|
1453
|
-
return {
|
|
1454
|
-
prerequisites: parsed.prerequisites || {}
|
|
1455
|
-
};
|
|
1456
|
-
} catch {
|
|
1457
|
-
return {
|
|
1458
|
-
prerequisites: {}
|
|
1459
|
-
};
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Check if a specific prerequisite is satisfied
|
|
1464
|
-
*/
|
|
1465
|
-
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1466
|
-
if (!userTagElo) return false;
|
|
1467
|
-
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1468
|
-
if (userTagElo.count < minCount) return false;
|
|
1469
|
-
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1470
|
-
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1471
|
-
} else {
|
|
1472
|
-
return userTagElo.score >= userGlobalElo;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Get the set of tags the user has mastered.
|
|
1477
|
-
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1478
|
-
*/
|
|
1479
|
-
async getMasteredTags(context) {
|
|
1480
|
-
const mastered = /* @__PURE__ */ new Set();
|
|
1481
|
-
try {
|
|
1482
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1483
|
-
const userElo = toCourseElo4(courseReg.elo);
|
|
1484
|
-
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1485
|
-
for (const prereq of prereqs) {
|
|
1486
|
-
const tagElo = userElo.tags[prereq.tag];
|
|
1487
|
-
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1488
|
-
mastered.add(prereq.tag);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
} catch {
|
|
1493
|
-
}
|
|
1494
|
-
return mastered;
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* Get the set of tags that are unlocked (prerequisites met)
|
|
1498
|
-
*/
|
|
1499
|
-
getUnlockedTags(masteredTags) {
|
|
1500
|
-
const unlocked = /* @__PURE__ */ new Set();
|
|
1501
|
-
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1502
|
-
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1503
|
-
if (allPrereqsMet) {
|
|
1504
|
-
unlocked.add(tagId);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
return unlocked;
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Check if a tag has prerequisites defined in config
|
|
1511
|
-
*/
|
|
1512
|
-
hasPrerequisites(tagId) {
|
|
1513
|
-
return tagId in this.config.prerequisites;
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Check if a card is unlocked and generate reason.
|
|
1517
|
-
*/
|
|
1518
|
-
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1519
|
-
try {
|
|
1520
|
-
const cardTags = card.tags ?? [];
|
|
1521
|
-
const lockedTags = cardTags.filter(
|
|
1522
|
-
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1523
|
-
);
|
|
1524
|
-
if (lockedTags.length === 0) {
|
|
1525
|
-
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1526
|
-
return {
|
|
1527
|
-
isUnlocked: true,
|
|
1528
|
-
reason: `Prerequisites met, tags: ${tagList}`
|
|
1529
|
-
};
|
|
1530
|
-
}
|
|
1531
|
-
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1532
|
-
const prereqs = this.config.prerequisites[tag] || [];
|
|
1533
|
-
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1534
|
-
});
|
|
1535
|
-
return {
|
|
1536
|
-
isUnlocked: false,
|
|
1537
|
-
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1538
|
-
};
|
|
1539
|
-
} catch {
|
|
1540
|
-
return {
|
|
1541
|
-
isUnlocked: true,
|
|
1542
|
-
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1543
|
-
};
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* CardFilter.transform implementation.
|
|
1548
|
-
*
|
|
1549
|
-
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1550
|
-
*/
|
|
1551
|
-
async transform(cards, context) {
|
|
1552
|
-
const masteredTags = await this.getMasteredTags(context);
|
|
1553
|
-
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1554
|
-
const gated = [];
|
|
1555
|
-
for (const card of cards) {
|
|
1556
|
-
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1557
|
-
card,
|
|
1558
|
-
context.course,
|
|
1559
|
-
unlockedTags,
|
|
1560
|
-
masteredTags
|
|
1561
|
-
);
|
|
1562
|
-
const finalScore = isUnlocked ? card.score : 0;
|
|
1563
|
-
const action = isUnlocked ? "passed" : "penalized";
|
|
1564
|
-
gated.push({
|
|
1565
|
-
...card,
|
|
1566
|
-
score: finalScore,
|
|
1567
|
-
provenance: [
|
|
1568
|
-
...card.provenance,
|
|
1569
|
-
{
|
|
1570
|
-
strategy: "hierarchyDefinition",
|
|
1571
|
-
strategyName: this.strategyName || this.name,
|
|
1572
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1573
|
-
action,
|
|
1574
|
-
score: finalScore,
|
|
1575
|
-
reason
|
|
1576
|
-
}
|
|
1577
|
-
]
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
return gated;
|
|
1581
|
-
}
|
|
1582
|
-
/**
|
|
1583
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1584
|
-
*
|
|
1585
|
-
* Use transform() via Pipeline instead.
|
|
1586
|
-
*/
|
|
1587
|
-
async getWeightedCards(_limit) {
|
|
1588
|
-
throw new Error(
|
|
1589
|
-
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1590
|
-
);
|
|
1591
|
-
}
|
|
1592
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1593
|
-
async getNewCards(_n) {
|
|
1594
|
-
return [];
|
|
1595
|
-
}
|
|
1596
|
-
async getPendingReviews() {
|
|
1597
|
-
return [];
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
}
|
|
1601
|
-
});
|
|
1602
|
-
|
|
1603
|
-
// src/core/navigators/inferredPreference.ts
|
|
1604
|
-
var inferredPreference_exports = {};
|
|
1605
|
-
__export(inferredPreference_exports, {
|
|
1606
|
-
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1607
|
-
});
|
|
1608
|
-
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1609
|
-
var init_inferredPreference = __esm({
|
|
1610
|
-
"src/core/navigators/inferredPreference.ts"() {
|
|
1611
|
-
"use strict";
|
|
1612
|
-
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
// src/core/navigators/interferenceMitigator.ts
|
|
1617
|
-
var interferenceMitigator_exports = {};
|
|
1618
|
-
__export(interferenceMitigator_exports, {
|
|
1619
|
-
default: () => InterferenceMitigatorNavigator
|
|
1620
|
-
});
|
|
1621
|
-
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1622
|
-
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1623
|
-
var init_interferenceMitigator = __esm({
|
|
1624
|
-
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1625
|
-
"use strict";
|
|
1626
|
-
init_navigators();
|
|
1627
|
-
DEFAULT_MIN_COUNT2 = 10;
|
|
1628
|
-
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1629
|
-
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1630
|
-
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1631
|
-
config;
|
|
1632
|
-
_strategyData;
|
|
1633
|
-
/** Human-readable name for CardFilter interface */
|
|
1634
|
-
name;
|
|
1635
|
-
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1636
|
-
interferenceMap;
|
|
1637
|
-
constructor(user, course, _strategyData) {
|
|
1638
|
-
super(user, course, _strategyData);
|
|
1639
|
-
this._strategyData = _strategyData;
|
|
1640
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1641
|
-
this.interferenceMap = this.buildInterferenceMap();
|
|
1642
|
-
this.name = _strategyData.name || "Interference Mitigator";
|
|
1643
|
-
}
|
|
1644
|
-
parseConfig(serializedData) {
|
|
1645
|
-
try {
|
|
1646
|
-
const parsed = JSON.parse(serializedData);
|
|
1647
|
-
let sets = parsed.interferenceSets || [];
|
|
1648
|
-
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1649
|
-
sets = sets.map((tags) => ({ tags }));
|
|
1650
|
-
}
|
|
1651
|
-
return {
|
|
1652
|
-
interferenceSets: sets,
|
|
1653
|
-
maturityThreshold: {
|
|
1654
|
-
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1655
|
-
minElo: parsed.maturityThreshold?.minElo,
|
|
1656
|
-
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1657
|
-
},
|
|
1658
|
-
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1659
|
-
};
|
|
1660
|
-
} catch {
|
|
1661
|
-
return {
|
|
1662
|
-
interferenceSets: [],
|
|
1663
|
-
maturityThreshold: {
|
|
1664
|
-
minCount: DEFAULT_MIN_COUNT2,
|
|
1665
|
-
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1666
|
-
},
|
|
1667
|
-
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1668
|
-
};
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
/**
|
|
1672
|
-
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1673
|
-
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1674
|
-
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1675
|
-
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1676
|
-
* - etc.
|
|
1677
|
-
*/
|
|
1678
|
-
buildInterferenceMap() {
|
|
1679
|
-
const map = /* @__PURE__ */ new Map();
|
|
1680
|
-
for (const group of this.config.interferenceSets) {
|
|
1681
|
-
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1682
|
-
for (const tag of group.tags) {
|
|
1683
|
-
if (!map.has(tag)) {
|
|
1684
|
-
map.set(tag, []);
|
|
1685
|
-
}
|
|
1686
|
-
const partners = map.get(tag);
|
|
1687
|
-
for (const other of group.tags) {
|
|
1688
|
-
if (other !== tag) {
|
|
1689
|
-
const existing = partners.find((p) => p.partner === other);
|
|
1690
|
-
if (existing) {
|
|
1691
|
-
existing.decay = Math.max(existing.decay, decay);
|
|
1692
|
-
} else {
|
|
1693
|
-
partners.push({ partner: other, decay });
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
return map;
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* Get the set of tags that are currently immature for this user.
|
|
1703
|
-
* A tag is immature if the user has interacted with it but hasn't
|
|
1704
|
-
* reached the maturity threshold.
|
|
1705
|
-
*/
|
|
1706
|
-
async getImmatureTags(context) {
|
|
1707
|
-
const immature = /* @__PURE__ */ new Set();
|
|
1708
|
-
try {
|
|
1709
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1710
|
-
const userElo = toCourseElo5(courseReg.elo);
|
|
1711
|
-
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1712
|
-
const minElo = this.config.maturityThreshold?.minElo;
|
|
1713
|
-
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1714
|
-
const minCountForElapsed = minElapsedDays * 2;
|
|
1715
|
-
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1716
|
-
if (tagElo.count === 0) continue;
|
|
1717
|
-
const belowCount = tagElo.count < minCount;
|
|
1718
|
-
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1719
|
-
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1720
|
-
if (belowCount || belowElo || belowElapsed) {
|
|
1721
|
-
immature.add(tagId);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
} catch {
|
|
1725
|
-
}
|
|
1726
|
-
return immature;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1730
|
-
* These are the tags we want to avoid introducing.
|
|
1731
|
-
*/
|
|
1732
|
-
getTagsToAvoid(immatureTags) {
|
|
1733
|
-
const avoid = /* @__PURE__ */ new Map();
|
|
1734
|
-
for (const immatureTag of immatureTags) {
|
|
1735
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1736
|
-
if (partners) {
|
|
1737
|
-
for (const { partner, decay } of partners) {
|
|
1738
|
-
if (!immatureTags.has(partner)) {
|
|
1739
|
-
const existing = avoid.get(partner) ?? 0;
|
|
1740
|
-
avoid.set(partner, Math.max(existing, decay));
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
return avoid;
|
|
1746
|
-
}
|
|
1747
|
-
/**
|
|
1748
|
-
* Compute interference score reduction for a card.
|
|
1749
|
-
* Returns: { multiplier, interfering tags, reason }
|
|
1750
|
-
*/
|
|
1751
|
-
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1752
|
-
if (tagsToAvoid.size === 0) {
|
|
1753
|
-
return {
|
|
1754
|
-
multiplier: 1,
|
|
1755
|
-
interferingTags: [],
|
|
1756
|
-
reason: "No interference detected"
|
|
1757
|
-
};
|
|
1758
|
-
}
|
|
1759
|
-
let multiplier = 1;
|
|
1760
|
-
const interferingTags = [];
|
|
1761
|
-
for (const tag of cardTags) {
|
|
1762
|
-
const decay = tagsToAvoid.get(tag);
|
|
1763
|
-
if (decay !== void 0) {
|
|
1764
|
-
interferingTags.push(tag);
|
|
1765
|
-
multiplier *= 1 - decay;
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
if (interferingTags.length === 0) {
|
|
1769
|
-
return {
|
|
1770
|
-
multiplier: 1,
|
|
1771
|
-
interferingTags: [],
|
|
1772
|
-
reason: "No interference detected"
|
|
1773
|
-
};
|
|
1774
|
-
}
|
|
1775
|
-
const causingTags = /* @__PURE__ */ new Set();
|
|
1776
|
-
for (const tag of interferingTags) {
|
|
1777
|
-
for (const immatureTag of immatureTags) {
|
|
1778
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1779
|
-
if (partners?.some((p) => p.partner === tag)) {
|
|
1780
|
-
causingTags.add(immatureTag);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1785
|
-
return { multiplier, interferingTags, reason };
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* CardFilter.transform implementation.
|
|
1789
|
-
*
|
|
1790
|
-
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1791
|
-
* immature learnings get reduced scores.
|
|
1792
|
-
*/
|
|
1793
|
-
async transform(cards, context) {
|
|
1794
|
-
const immatureTags = await this.getImmatureTags(context);
|
|
1795
|
-
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1796
|
-
const adjusted = [];
|
|
1797
|
-
for (const card of cards) {
|
|
1798
|
-
const cardTags = card.tags ?? [];
|
|
1799
|
-
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1800
|
-
cardTags,
|
|
1801
|
-
tagsToAvoid,
|
|
1802
|
-
immatureTags
|
|
1803
|
-
);
|
|
1804
|
-
const finalScore = card.score * multiplier;
|
|
1805
|
-
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1806
|
-
adjusted.push({
|
|
1807
|
-
...card,
|
|
1808
|
-
score: finalScore,
|
|
1809
|
-
provenance: [
|
|
1810
|
-
...card.provenance,
|
|
1811
|
-
{
|
|
1812
|
-
strategy: "interferenceMitigator",
|
|
1813
|
-
strategyName: this.strategyName || this.name,
|
|
1814
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1815
|
-
action,
|
|
1816
|
-
score: finalScore,
|
|
1817
|
-
reason
|
|
1818
|
-
}
|
|
1819
|
-
]
|
|
1820
|
-
});
|
|
1821
|
-
}
|
|
1822
|
-
return adjusted;
|
|
1823
|
-
}
|
|
1824
|
-
/**
|
|
1825
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1826
|
-
*
|
|
1827
|
-
* Use transform() via Pipeline instead.
|
|
1828
|
-
*/
|
|
1829
|
-
async getWeightedCards(_limit) {
|
|
1830
|
-
throw new Error(
|
|
1831
|
-
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1835
|
-
async getNewCards(_n) {
|
|
1836
|
-
return [];
|
|
1837
|
-
}
|
|
1838
|
-
async getPendingReviews() {
|
|
1839
|
-
return [];
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
}
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
// src/core/navigators/relativePriority.ts
|
|
1846
|
-
var relativePriority_exports = {};
|
|
1847
|
-
__export(relativePriority_exports, {
|
|
1848
|
-
default: () => RelativePriorityNavigator
|
|
1849
|
-
});
|
|
1850
|
-
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1851
|
-
var init_relativePriority = __esm({
|
|
1852
|
-
"src/core/navigators/relativePriority.ts"() {
|
|
1853
|
-
"use strict";
|
|
1854
|
-
init_navigators();
|
|
1855
|
-
DEFAULT_PRIORITY = 0.5;
|
|
1856
|
-
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1857
|
-
DEFAULT_COMBINE_MODE = "max";
|
|
1858
|
-
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1859
|
-
config;
|
|
1860
|
-
_strategyData;
|
|
1861
|
-
/** Human-readable name for CardFilter interface */
|
|
1862
|
-
name;
|
|
1863
|
-
constructor(user, course, _strategyData) {
|
|
1864
|
-
super(user, course, _strategyData);
|
|
1865
|
-
this._strategyData = _strategyData;
|
|
1866
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1867
|
-
this.name = _strategyData.name || "Relative Priority";
|
|
1868
|
-
}
|
|
1869
|
-
parseConfig(serializedData) {
|
|
1870
|
-
try {
|
|
1871
|
-
const parsed = JSON.parse(serializedData);
|
|
1872
|
-
return {
|
|
1873
|
-
tagPriorities: parsed.tagPriorities || {},
|
|
1874
|
-
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1875
|
-
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1876
|
-
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1877
|
-
};
|
|
1878
|
-
} catch {
|
|
1879
|
-
return {
|
|
1880
|
-
tagPriorities: {},
|
|
1881
|
-
defaultPriority: DEFAULT_PRIORITY,
|
|
1882
|
-
combineMode: DEFAULT_COMBINE_MODE,
|
|
1883
|
-
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Look up the priority for a tag.
|
|
1889
|
-
*/
|
|
1890
|
-
getTagPriority(tagId) {
|
|
1891
|
-
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1892
|
-
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Compute combined priority for a card based on its tags.
|
|
1895
|
-
*/
|
|
1896
|
-
computeCardPriority(cardTags) {
|
|
1897
|
-
if (cardTags.length === 0) {
|
|
1898
|
-
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1899
|
-
}
|
|
1900
|
-
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1901
|
-
switch (this.config.combineMode) {
|
|
1902
|
-
case "max":
|
|
1903
|
-
return Math.max(...priorities);
|
|
1904
|
-
case "min":
|
|
1905
|
-
return Math.min(...priorities);
|
|
1906
|
-
case "average":
|
|
1907
|
-
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1908
|
-
default:
|
|
1909
|
-
return Math.max(...priorities);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* Compute boost factor based on priority.
|
|
1914
|
-
*
|
|
1915
|
-
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1916
|
-
*
|
|
1917
|
-
* This creates a multiplier centered around 1.0:
|
|
1918
|
-
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1919
|
-
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1920
|
-
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1921
|
-
*/
|
|
1922
|
-
computeBoostFactor(priority) {
|
|
1923
|
-
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1924
|
-
return 1 + (priority - 0.5) * influence;
|
|
1925
|
-
}
|
|
1926
|
-
/**
|
|
1927
|
-
* Build human-readable reason for priority adjustment.
|
|
1928
|
-
*/
|
|
1929
|
-
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1930
|
-
if (cardTags.length === 0) {
|
|
1931
|
-
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1932
|
-
}
|
|
1933
|
-
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1934
|
-
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1935
|
-
if (boostFactor === 1) {
|
|
1936
|
-
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1937
|
-
} else if (boostFactor > 1) {
|
|
1938
|
-
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1939
|
-
} else {
|
|
1940
|
-
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
/**
|
|
1944
|
-
* CardFilter.transform implementation.
|
|
1945
|
-
*
|
|
1946
|
-
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1947
|
-
* cards with low-priority tags get reduced scores.
|
|
1948
|
-
*/
|
|
1949
|
-
async transform(cards, _context) {
|
|
1950
|
-
const adjusted = await Promise.all(
|
|
1951
|
-
cards.map(async (card) => {
|
|
1952
|
-
const cardTags = card.tags ?? [];
|
|
1953
|
-
const priority = this.computeCardPriority(cardTags);
|
|
1954
|
-
const boostFactor = this.computeBoostFactor(priority);
|
|
1955
|
-
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1956
|
-
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1957
|
-
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1958
|
-
return {
|
|
1959
|
-
...card,
|
|
1960
|
-
score: finalScore,
|
|
1961
|
-
provenance: [
|
|
1962
|
-
...card.provenance,
|
|
1963
|
-
{
|
|
1964
|
-
strategy: "relativePriority",
|
|
1965
|
-
strategyName: this.strategyName || this.name,
|
|
1966
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1967
|
-
action,
|
|
1968
|
-
score: finalScore,
|
|
1969
|
-
reason
|
|
1970
|
-
}
|
|
1971
|
-
]
|
|
1972
|
-
};
|
|
1973
|
-
})
|
|
1974
|
-
);
|
|
1975
|
-
return adjusted;
|
|
1976
|
-
}
|
|
1977
|
-
/**
|
|
1978
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1979
|
-
*
|
|
1980
|
-
* Use transform() via Pipeline instead.
|
|
1981
|
-
*/
|
|
1982
|
-
async getWeightedCards(_limit) {
|
|
1983
|
-
throw new Error(
|
|
1984
|
-
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1985
|
-
);
|
|
1986
|
-
}
|
|
1987
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1988
|
-
async getNewCards(_n) {
|
|
1989
|
-
return [];
|
|
1990
|
-
}
|
|
1991
|
-
async getPendingReviews() {
|
|
1992
|
-
return [];
|
|
1993
|
-
}
|
|
1994
|
-
};
|
|
1995
|
-
}
|
|
1996
|
-
});
|
|
1997
|
-
|
|
1998
|
-
// src/core/navigators/srs.ts
|
|
1999
|
-
var srs_exports = {};
|
|
2000
|
-
__export(srs_exports, {
|
|
2001
|
-
default: () => SRSNavigator
|
|
2002
|
-
});
|
|
2003
|
-
import moment3 from "moment";
|
|
2004
|
-
var SRSNavigator;
|
|
2005
|
-
var init_srs = __esm({
|
|
2006
|
-
"src/core/navigators/srs.ts"() {
|
|
2007
|
-
"use strict";
|
|
2008
|
-
init_navigators();
|
|
2009
|
-
SRSNavigator = class extends ContentNavigator {
|
|
2010
|
-
/** Human-readable name for CardGenerator interface */
|
|
2011
|
-
name;
|
|
2012
|
-
constructor(user, course, strategyData) {
|
|
2013
|
-
super(user, course, strategyData);
|
|
2014
|
-
this.name = strategyData?.name || "SRS";
|
|
2015
|
-
}
|
|
2016
|
-
/**
|
|
2017
|
-
* Get review cards scored by urgency.
|
|
2018
|
-
*
|
|
2019
|
-
* Score formula combines:
|
|
2020
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2021
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
2022
|
-
*
|
|
2023
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
2024
|
-
*
|
|
2025
|
-
* This method supports both the legacy signature (limit only) and the
|
|
2026
|
-
* CardGenerator interface signature (limit, context).
|
|
2027
|
-
*
|
|
2028
|
-
* @param limit - Maximum number of cards to return
|
|
2029
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2030
|
-
*/
|
|
2031
|
-
async getWeightedCards(limit, _context) {
|
|
2032
|
-
if (!this.user || !this.course) {
|
|
2033
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2034
|
-
}
|
|
2035
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2036
|
-
const now = moment3.utc();
|
|
2037
|
-
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
2038
|
-
const scored = dueReviews.map((review) => {
|
|
2039
|
-
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
2040
|
-
return {
|
|
2041
|
-
cardId: review.cardId,
|
|
2042
|
-
courseId: review.courseId,
|
|
2043
|
-
score,
|
|
2044
|
-
provenance: [
|
|
2045
|
-
{
|
|
2046
|
-
strategy: "srs",
|
|
2047
|
-
strategyName: this.strategyName || this.name,
|
|
2048
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2049
|
-
action: "generated",
|
|
2050
|
-
score,
|
|
2051
|
-
reason
|
|
2052
|
-
}
|
|
2053
|
-
]
|
|
2054
|
-
};
|
|
2055
|
-
});
|
|
2056
|
-
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Compute urgency score for a review card.
|
|
2060
|
-
*
|
|
2061
|
-
* Two factors:
|
|
2062
|
-
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2063
|
-
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2064
|
-
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2065
|
-
*
|
|
2066
|
-
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2067
|
-
* - 24h interval → ~1.0 (very recent learning)
|
|
2068
|
-
* - 30 days (720h) → ~0.56
|
|
2069
|
-
* - 180 days → ~0.30
|
|
2070
|
-
*
|
|
2071
|
-
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2072
|
-
* Result range: approximately 0.5 to 0.95
|
|
2073
|
-
*/
|
|
2074
|
-
computeUrgencyScore(review, now) {
|
|
2075
|
-
const scheduledAt = moment3.utc(review.scheduledAt);
|
|
2076
|
-
const due = moment3.utc(review.reviewTime);
|
|
2077
|
-
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2078
|
-
const hoursOverdue = now.diff(due, "hours");
|
|
2079
|
-
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2080
|
-
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2081
|
-
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2082
|
-
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2083
|
-
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2084
|
-
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2085
|
-
return { score, reason };
|
|
2086
|
-
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Get pending reviews in legacy format.
|
|
2089
|
-
*
|
|
2090
|
-
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2091
|
-
*/
|
|
2092
|
-
async getPendingReviews() {
|
|
2093
|
-
if (!this.user || !this.course) {
|
|
2094
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2095
|
-
}
|
|
2096
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2097
|
-
return reviews.map((r) => ({
|
|
2098
|
-
...r,
|
|
2099
|
-
contentSourceType: "course",
|
|
2100
|
-
contentSourceID: this.course.getCourseID(),
|
|
2101
|
-
cardID: r.cardId,
|
|
2102
|
-
courseID: r.courseId,
|
|
2103
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2104
|
-
reviewID: r._id,
|
|
2105
|
-
status: "review"
|
|
2106
|
-
}));
|
|
2107
|
-
}
|
|
2108
|
-
/**
|
|
2109
|
-
* SRS does not generate new cards.
|
|
2110
|
-
* Use ELONavigator or another generator for new cards.
|
|
2111
|
-
*/
|
|
2112
|
-
async getNewCards(_n) {
|
|
2113
|
-
return [];
|
|
2114
|
-
}
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
});
|
|
2118
|
-
|
|
2119
|
-
// src/core/navigators/userGoal.ts
|
|
2120
|
-
var userGoal_exports = {};
|
|
2121
|
-
__export(userGoal_exports, {
|
|
2122
|
-
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2123
|
-
});
|
|
2124
|
-
var USER_GOAL_NAVIGATOR_STUB;
|
|
2125
|
-
var init_userGoal = __esm({
|
|
2126
|
-
"src/core/navigators/userGoal.ts"() {
|
|
2127
|
-
"use strict";
|
|
2128
|
-
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2129
|
-
}
|
|
2130
|
-
});
|
|
2131
|
-
|
|
2132
|
-
// import("./**/*") in src/core/navigators/index.ts
|
|
2133
|
-
var globImport;
|
|
2134
|
-
var init_ = __esm({
|
|
2135
|
-
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
2136
|
-
globImport = __glob({
|
|
2137
|
-
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2138
|
-
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2139
|
-
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
2140
|
-
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2141
|
-
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2142
|
-
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2143
|
-
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2144
|
-
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2145
|
-
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2146
|
-
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
2147
|
-
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
2148
|
-
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2149
|
-
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2150
|
-
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2151
|
-
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2152
|
-
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2153
|
-
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2154
|
-
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
});
|
|
2158
|
-
|
|
2159
|
-
// src/core/navigators/index.ts
|
|
2160
|
-
var navigators_exports = {};
|
|
2161
|
-
__export(navigators_exports, {
|
|
2162
|
-
ContentNavigator: () => ContentNavigator,
|
|
2163
|
-
NavigatorRole: () => NavigatorRole,
|
|
2164
|
-
NavigatorRoles: () => NavigatorRoles,
|
|
2165
|
-
Navigators: () => Navigators,
|
|
2166
|
-
getCardOrigin: () => getCardOrigin,
|
|
2167
|
-
isFilter: () => isFilter,
|
|
2168
|
-
isGenerator: () => isGenerator
|
|
2169
|
-
});
|
|
2170
|
-
function getCardOrigin(card) {
|
|
2171
|
-
if (card.provenance.length === 0) {
|
|
2172
|
-
throw new Error("Card has no provenance - cannot determine origin");
|
|
2173
|
-
}
|
|
2174
|
-
const firstEntry = card.provenance[0];
|
|
2175
|
-
const reason = firstEntry.reason.toLowerCase();
|
|
2176
|
-
if (reason.includes("failed")) {
|
|
2177
|
-
return "failed";
|
|
2178
|
-
}
|
|
2179
|
-
if (reason.includes("review")) {
|
|
2180
|
-
return "review";
|
|
2181
|
-
}
|
|
2182
|
-
return "new";
|
|
2183
|
-
}
|
|
2184
|
-
function isGenerator(impl) {
|
|
2185
|
-
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2186
|
-
}
|
|
2187
|
-
function isFilter(impl) {
|
|
2188
|
-
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2189
|
-
}
|
|
2190
|
-
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
2191
|
-
var init_navigators = __esm({
|
|
2192
|
-
"src/core/navigators/index.ts"() {
|
|
2193
|
-
"use strict";
|
|
2194
|
-
init_logger();
|
|
2195
|
-
init_();
|
|
2196
|
-
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
2197
|
-
Navigators2["ELO"] = "elo";
|
|
2198
|
-
Navigators2["SRS"] = "srs";
|
|
2199
|
-
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2200
|
-
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2201
|
-
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2202
|
-
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2203
|
-
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
2204
|
-
return Navigators2;
|
|
2205
|
-
})(Navigators || {});
|
|
2206
|
-
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2207
|
-
NavigatorRole2["GENERATOR"] = "generator";
|
|
2208
|
-
NavigatorRole2["FILTER"] = "filter";
|
|
2209
|
-
return NavigatorRole2;
|
|
2210
|
-
})(NavigatorRole || {});
|
|
2211
|
-
NavigatorRoles = {
|
|
2212
|
-
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2213
|
-
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2214
|
-
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2215
|
-
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2216
|
-
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2217
|
-
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2218
|
-
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2219
|
-
};
|
|
2220
|
-
ContentNavigator = class {
|
|
2221
|
-
/** User interface for this navigation session */
|
|
2222
|
-
user;
|
|
2223
|
-
/** Course interface for this navigation session */
|
|
2224
|
-
course;
|
|
2225
|
-
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2226
|
-
strategyName;
|
|
2227
|
-
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2228
|
-
strategyId;
|
|
2229
|
-
/**
|
|
2230
|
-
* Constructor for standard navigators.
|
|
2231
|
-
* Call this from subclass constructors to initialize common fields.
|
|
2232
|
-
*
|
|
2233
|
-
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2234
|
-
*/
|
|
2235
|
-
constructor(user, course, strategyData) {
|
|
2236
|
-
if (user && course && strategyData) {
|
|
2237
|
-
this.user = user;
|
|
2238
|
-
this.course = course;
|
|
2239
|
-
this.strategyName = strategyData.name;
|
|
2240
|
-
this.strategyId = strategyData._id;
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
// ============================================================================
|
|
2244
|
-
// STRATEGY STATE HELPERS
|
|
2245
|
-
// ============================================================================
|
|
2246
|
-
//
|
|
2247
|
-
// These methods allow strategies to persist their own state (user preferences,
|
|
2248
|
-
// learned patterns, temporal tracking) in the user database.
|
|
2249
|
-
//
|
|
2250
|
-
// ============================================================================
|
|
2251
|
-
/**
|
|
2252
|
-
* Unique key identifying this strategy for state storage.
|
|
2253
|
-
*
|
|
2254
|
-
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2255
|
-
* Override in subclasses if multiple instances of the same strategy type
|
|
2256
|
-
* need separate state storage.
|
|
2257
|
-
*/
|
|
2258
|
-
get strategyKey() {
|
|
2259
|
-
return this.constructor.name;
|
|
2260
|
-
}
|
|
2261
|
-
/**
|
|
2262
|
-
* Get this strategy's persisted state for the current course.
|
|
2263
|
-
*
|
|
2264
|
-
* @returns The strategy's data payload, or null if no state exists
|
|
2265
|
-
* @throws Error if user or course is not initialized
|
|
2266
|
-
*/
|
|
2267
|
-
async getStrategyState() {
|
|
2268
|
-
if (!this.user || !this.course) {
|
|
2269
|
-
throw new Error(
|
|
2270
|
-
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2271
|
-
);
|
|
2272
|
-
}
|
|
2273
|
-
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* Persist this strategy's state for the current course.
|
|
2277
|
-
*
|
|
2278
|
-
* @param data - The strategy's data payload to store
|
|
2279
|
-
* @throws Error if user or course is not initialized
|
|
2280
|
-
*/
|
|
2281
|
-
async putStrategyState(data) {
|
|
2282
|
-
if (!this.user || !this.course) {
|
|
2283
|
-
throw new Error(
|
|
2284
|
-
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2285
|
-
);
|
|
2286
|
-
}
|
|
2287
|
-
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2288
|
-
}
|
|
2289
|
-
/**
|
|
2290
|
-
* Factory method to create navigator instances dynamically.
|
|
2291
|
-
*
|
|
2292
|
-
* @param user - User interface
|
|
2293
|
-
* @param course - Course interface
|
|
2294
|
-
* @param strategyData - Strategy configuration document
|
|
2295
|
-
* @returns the runtime object used to steer a study session.
|
|
2296
|
-
*/
|
|
2297
|
-
static async create(user, course, strategyData) {
|
|
2298
|
-
const implementingClass = strategyData.implementingClass;
|
|
2299
|
-
let NavigatorImpl;
|
|
2300
|
-
const variations = [".ts", ".js", ""];
|
|
2301
|
-
for (const ext of variations) {
|
|
2302
|
-
try {
|
|
2303
|
-
const module = await globImport(`./${implementingClass}${ext}`);
|
|
2304
|
-
NavigatorImpl = module.default;
|
|
2305
|
-
break;
|
|
2306
|
-
} catch (e) {
|
|
2307
|
-
logger.debug(`Failed to load with extension ${ext}:`, e);
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
if (!NavigatorImpl) {
|
|
2311
|
-
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
2312
|
-
}
|
|
2313
|
-
return new NavigatorImpl(user, course, strategyData);
|
|
2314
|
-
}
|
|
2315
|
-
/**
|
|
2316
|
-
* Get cards with suitability scores and provenance trails.
|
|
2317
|
-
*
|
|
2318
|
-
* **This is the PRIMARY API for navigation strategies.**
|
|
2319
|
-
*
|
|
2320
|
-
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2321
|
-
* better candidates for presentation. Each card includes a provenance trail
|
|
2322
|
-
* documenting how strategies contributed to the final score.
|
|
2323
|
-
*
|
|
2324
|
-
* ## For Generators
|
|
2325
|
-
* Override this method to generate candidates and compute scores based on
|
|
2326
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2327
|
-
* initial provenance entry with action='generated'.
|
|
2328
|
-
*
|
|
2329
|
-
* ## Default Implementation
|
|
2330
|
-
* The base class provides a backward-compatible default that:
|
|
2331
|
-
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2332
|
-
* 2. Assigns score=1.0 to all cards
|
|
2333
|
-
* 3. Creates minimal provenance from legacy methods
|
|
2334
|
-
* 4. Returns combined results up to limit
|
|
1061
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1062
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
2335
1063
|
*
|
|
2336
|
-
* This
|
|
2337
|
-
*
|
|
1064
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1065
|
+
* CardGenerator interface signature (limit, context).
|
|
2338
1066
|
*
|
|
2339
|
-
* @param limit - Maximum cards to return
|
|
2340
|
-
* @
|
|
1067
|
+
* @param limit - Maximum number of cards to return
|
|
1068
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
2341
1069
|
*/
|
|
2342
|
-
async getWeightedCards(limit) {
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
1070
|
+
async getWeightedCards(limit, context) {
|
|
1071
|
+
let userGlobalElo;
|
|
1072
|
+
if (context?.userElo !== void 0) {
|
|
1073
|
+
userGlobalElo = context.userElo;
|
|
1074
|
+
} else {
|
|
1075
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1076
|
+
const userElo = toCourseElo3(courseReg.elo);
|
|
1077
|
+
userGlobalElo = userElo.global.score;
|
|
1078
|
+
}
|
|
1079
|
+
const activeCards = await this.user.getActiveCards();
|
|
1080
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1081
|
+
{ limit, elo: "user" },
|
|
1082
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1083
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
1084
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1085
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1086
|
+
const scored = newCards.map((c, i) => {
|
|
1087
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1088
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1089
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1090
|
+
return {
|
|
2347
1091
|
cardId: c.cardID,
|
|
2348
1092
|
courseId: c.courseID,
|
|
2349
|
-
score
|
|
1093
|
+
score,
|
|
2350
1094
|
provenance: [
|
|
2351
1095
|
{
|
|
2352
|
-
strategy: "
|
|
2353
|
-
strategyName: this.strategyName ||
|
|
2354
|
-
strategyId: this.strategyId || "
|
|
1096
|
+
strategy: "elo",
|
|
1097
|
+
strategyName: this.strategyName || this.name,
|
|
1098
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
2355
1099
|
action: "generated",
|
|
2356
|
-
score
|
|
2357
|
-
reason:
|
|
1100
|
+
score,
|
|
1101
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
2358
1102
|
}
|
|
2359
1103
|
]
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
1104
|
+
};
|
|
1105
|
+
});
|
|
1106
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1107
|
+
return scored.slice(0, limit);
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
// src/core/navigators/generators/srs.ts
|
|
1114
|
+
import moment3 from "moment";
|
|
1115
|
+
var SRSNavigator;
|
|
1116
|
+
var init_srs = __esm({
|
|
1117
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
1118
|
+
"use strict";
|
|
1119
|
+
init_navigators();
|
|
1120
|
+
init_logger();
|
|
1121
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1122
|
+
/** Human-readable name for CardGenerator interface */
|
|
1123
|
+
name;
|
|
1124
|
+
constructor(user, course, strategyData) {
|
|
1125
|
+
super(user, course, strategyData);
|
|
1126
|
+
this.name = strategyData?.name || "SRS";
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Get review cards scored by urgency.
|
|
1130
|
+
*
|
|
1131
|
+
* Score formula combines:
|
|
1132
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1133
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1134
|
+
*
|
|
1135
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1136
|
+
*
|
|
1137
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1138
|
+
* CardGenerator interface signature (limit, context).
|
|
1139
|
+
*
|
|
1140
|
+
* @param limit - Maximum number of cards to return
|
|
1141
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1142
|
+
*/
|
|
1143
|
+
async getWeightedCards(limit, _context) {
|
|
1144
|
+
if (!this.user || !this.course) {
|
|
1145
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
1146
|
+
}
|
|
1147
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1148
|
+
const now = moment3.utc();
|
|
1149
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
1150
|
+
const scored = dueReviews.map((review) => {
|
|
1151
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1152
|
+
return {
|
|
1153
|
+
cardId: review.cardId,
|
|
1154
|
+
courseId: review.courseId,
|
|
1155
|
+
score,
|
|
1156
|
+
reviewID: review._id,
|
|
2365
1157
|
provenance: [
|
|
2366
1158
|
{
|
|
2367
|
-
strategy: "
|
|
2368
|
-
strategyName: this.strategyName ||
|
|
2369
|
-
strategyId: this.strategyId || "
|
|
1159
|
+
strategy: "srs",
|
|
1160
|
+
strategyName: this.strategyName || this.name,
|
|
1161
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2370
1162
|
action: "generated",
|
|
2371
|
-
score
|
|
2372
|
-
reason
|
|
1163
|
+
score,
|
|
1164
|
+
reason
|
|
2373
1165
|
}
|
|
2374
1166
|
]
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
|
|
1167
|
+
};
|
|
1168
|
+
});
|
|
1169
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
1170
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Compute urgency score for a review card.
|
|
1174
|
+
*
|
|
1175
|
+
* Two factors:
|
|
1176
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
1177
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
1178
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
1179
|
+
*
|
|
1180
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
1181
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
1182
|
+
* - 30 days (720h) → ~0.56
|
|
1183
|
+
* - 180 days → ~0.30
|
|
1184
|
+
*
|
|
1185
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
1186
|
+
* Result range: approximately 0.5 to 0.95
|
|
1187
|
+
*/
|
|
1188
|
+
computeUrgencyScore(review, now) {
|
|
1189
|
+
const scheduledAt = moment3.utc(review.scheduledAt);
|
|
1190
|
+
const due = moment3.utc(review.reviewTime);
|
|
1191
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
1192
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
1193
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
1194
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
1195
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
1196
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
1197
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
1198
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
1199
|
+
return { score, reason };
|
|
2378
1200
|
}
|
|
2379
1201
|
};
|
|
2380
1202
|
}
|
|
2381
1203
|
});
|
|
2382
1204
|
|
|
1205
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1206
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1207
|
+
const normalizedDistance = distance / halfLife;
|
|
1208
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1209
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1210
|
+
}
|
|
1211
|
+
function createEloDistanceFilter(config) {
|
|
1212
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1213
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1214
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1215
|
+
return {
|
|
1216
|
+
name: "ELO Distance Filter",
|
|
1217
|
+
async transform(cards, context) {
|
|
1218
|
+
const { course, userElo } = context;
|
|
1219
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1220
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1221
|
+
return cards.map((card, i) => {
|
|
1222
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1223
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1224
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1225
|
+
const newScore = card.score * multiplier;
|
|
1226
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1227
|
+
return {
|
|
1228
|
+
...card,
|
|
1229
|
+
score: newScore,
|
|
1230
|
+
provenance: [
|
|
1231
|
+
...card.provenance,
|
|
1232
|
+
{
|
|
1233
|
+
strategy: "eloDistance",
|
|
1234
|
+
strategyName: "ELO Distance Filter",
|
|
1235
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1236
|
+
action,
|
|
1237
|
+
score: newScore,
|
|
1238
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1239
|
+
}
|
|
1240
|
+
]
|
|
1241
|
+
};
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1247
|
+
var init_eloDistance = __esm({
|
|
1248
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1249
|
+
"use strict";
|
|
1250
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1251
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1252
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
// src/core/navigators/defaults.ts
|
|
1257
|
+
function createDefaultEloStrategy(courseId) {
|
|
1258
|
+
return {
|
|
1259
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1260
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1261
|
+
name: "ELO (default)",
|
|
1262
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1263
|
+
implementingClass: "elo" /* ELO */,
|
|
1264
|
+
course: courseId,
|
|
1265
|
+
serializedData: ""
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
function createDefaultSrsStrategy(courseId) {
|
|
1269
|
+
return {
|
|
1270
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
1271
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1272
|
+
name: "SRS (default)",
|
|
1273
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
1274
|
+
implementingClass: "srs" /* SRS */,
|
|
1275
|
+
course: courseId,
|
|
1276
|
+
serializedData: ""
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
function createDefaultPipeline(user, course) {
|
|
1280
|
+
const courseId = course.getCourseID();
|
|
1281
|
+
const eloNavigator = new ELONavigator(user, course, createDefaultEloStrategy(courseId));
|
|
1282
|
+
const srsNavigator = new SRSNavigator(user, course, createDefaultSrsStrategy(courseId));
|
|
1283
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
1284
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
1285
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, course);
|
|
1286
|
+
}
|
|
1287
|
+
var init_defaults = __esm({
|
|
1288
|
+
"src/core/navigators/defaults.ts"() {
|
|
1289
|
+
"use strict";
|
|
1290
|
+
init_navigators();
|
|
1291
|
+
init_Pipeline();
|
|
1292
|
+
init_CompositeGenerator();
|
|
1293
|
+
init_elo();
|
|
1294
|
+
init_srs();
|
|
1295
|
+
init_eloDistance();
|
|
1296
|
+
init_types_legacy();
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
|
|
2383
1300
|
// src/impl/couch/courseDB.ts
|
|
2384
1301
|
import {
|
|
2385
1302
|
EloToNumber,
|
|
2386
1303
|
Status,
|
|
2387
1304
|
blankCourseElo as blankCourseElo2,
|
|
2388
|
-
toCourseElo as
|
|
1305
|
+
toCourseElo as toCourseElo4
|
|
2389
1306
|
} from "@vue-skuilder/common";
|
|
2390
1307
|
var init_courseDB = __esm({
|
|
2391
1308
|
"src/impl/couch/courseDB.ts"() {
|
|
@@ -2398,12 +1315,8 @@ var init_courseDB = __esm({
|
|
|
2398
1315
|
init_courseAPI();
|
|
2399
1316
|
init_courseLookupDB();
|
|
2400
1317
|
init_navigators();
|
|
2401
|
-
init_Pipeline();
|
|
2402
1318
|
init_PipelineAssembler();
|
|
2403
|
-
|
|
2404
|
-
init_elo();
|
|
2405
|
-
init_srs();
|
|
2406
|
-
init_eloDistance();
|
|
1319
|
+
init_defaults();
|
|
2407
1320
|
}
|
|
2408
1321
|
});
|
|
2409
1322
|
|
|
@@ -3659,7 +2572,7 @@ var init_cardProcessor = __esm({
|
|
|
3659
2572
|
});
|
|
3660
2573
|
|
|
3661
2574
|
// src/core/bulkImport/types.ts
|
|
3662
|
-
var
|
|
2575
|
+
var init_types = __esm({
|
|
3663
2576
|
"src/core/bulkImport/types.ts"() {
|
|
3664
2577
|
"use strict";
|
|
3665
2578
|
}
|
|
@@ -3670,7 +2583,7 @@ var init_bulkImport = __esm({
|
|
|
3670
2583
|
"src/core/bulkImport/index.ts"() {
|
|
3671
2584
|
"use strict";
|
|
3672
2585
|
init_cardProcessor();
|
|
3673
|
-
|
|
2586
|
+
init_types();
|
|
3674
2587
|
}
|
|
3675
2588
|
});
|
|
3676
2589
|
|
|
@@ -3748,6 +2661,36 @@ var init_StaticDataUnpacker = __esm({
|
|
|
3748
2661
|
logger.error(`Document ${id} not found in chunk ${chunk.id}`);
|
|
3749
2662
|
throw new Error(`Document ${id} not found in chunk ${chunk.id}`);
|
|
3750
2663
|
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Get all documents with IDs starting with a specific prefix.
|
|
2666
|
+
*
|
|
2667
|
+
* This method loads the relevant chunk(s) and returns all matching documents.
|
|
2668
|
+
* Useful for querying documents by type (e.g., all NAVIGATION_STRATEGY documents).
|
|
2669
|
+
*
|
|
2670
|
+
* @param prefix - Document ID prefix to match (e.g., "NAVIGATION_STRATEGY")
|
|
2671
|
+
* @returns Array of all documents with IDs starting with the prefix
|
|
2672
|
+
*/
|
|
2673
|
+
async getAllDocumentsByPrefix(prefix) {
|
|
2674
|
+
const relevantChunks = this.manifest.chunks.filter((chunk) => {
|
|
2675
|
+
const prefixEnd = prefix + "\uFFF0";
|
|
2676
|
+
return chunk.startKey <= prefixEnd && chunk.endKey >= prefix;
|
|
2677
|
+
});
|
|
2678
|
+
if (relevantChunks.length === 0) {
|
|
2679
|
+
logger.debug(`[StaticDataUnpacker] No chunks found for prefix: ${prefix}`);
|
|
2680
|
+
return [];
|
|
2681
|
+
}
|
|
2682
|
+
await Promise.all(relevantChunks.map((chunk) => this.loadChunk(chunk.id)));
|
|
2683
|
+
const matchingDocs = [];
|
|
2684
|
+
for (const [docId, doc] of this.documentCache.entries()) {
|
|
2685
|
+
if (docId.startsWith(prefix)) {
|
|
2686
|
+
matchingDocs.push(await this.hydrateAttachments(doc));
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
logger.debug(
|
|
2690
|
+
`[StaticDataUnpacker] Found ${matchingDocs.length} documents with prefix: ${prefix}`
|
|
2691
|
+
);
|
|
2692
|
+
return matchingDocs;
|
|
2693
|
+
}
|
|
3751
2694
|
/**
|
|
3752
2695
|
* Query cards by ELO score, returning card IDs sorted by ELO
|
|
3753
2696
|
*/
|
|
@@ -3784,7 +2727,14 @@ var init_StaticDataUnpacker = __esm({
|
|
|
3784
2727
|
* Get all tag names mapped to their card arrays
|
|
3785
2728
|
*/
|
|
3786
2729
|
async getTagsIndex() {
|
|
3787
|
-
|
|
2730
|
+
try {
|
|
2731
|
+
return await this.loadIndex("tags");
|
|
2732
|
+
} catch {
|
|
2733
|
+
return {
|
|
2734
|
+
byCard: {},
|
|
2735
|
+
byTag: {}
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
3788
2738
|
}
|
|
3789
2739
|
getDocTypeFromId(id) {
|
|
3790
2740
|
for (const docTypeKey in DocTypePrefixes) {
|
|
@@ -4075,8 +3025,9 @@ var init_courseDB3 = __esm({
|
|
|
4075
3025
|
"src/impl/static/courseDB.ts"() {
|
|
4076
3026
|
"use strict";
|
|
4077
3027
|
init_types_legacy();
|
|
4078
|
-
init_navigators();
|
|
4079
3028
|
init_logger();
|
|
3029
|
+
init_defaults();
|
|
3030
|
+
init_PipelineAssembler();
|
|
4080
3031
|
StaticCourseDB = class {
|
|
4081
3032
|
constructor(courseId, unpacker, userDB, manifest) {
|
|
4082
3033
|
this.courseId = courseId;
|
|
@@ -4155,21 +3106,6 @@ var init_courseDB3 = __esm({
|
|
|
4155
3106
|
async updateCardElo(cardId, _elo) {
|
|
4156
3107
|
return { ok: true, id: cardId, rev: "1-static" };
|
|
4157
3108
|
}
|
|
4158
|
-
async getNewCards(limit = 99) {
|
|
4159
|
-
const activeCards = await this.userDB.getActiveCards();
|
|
4160
|
-
return (await this.getCardsCenteredAtELO({ limit, elo: "user" }, (c) => {
|
|
4161
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
4162
|
-
return false;
|
|
4163
|
-
} else {
|
|
4164
|
-
return true;
|
|
4165
|
-
}
|
|
4166
|
-
})).map((c) => {
|
|
4167
|
-
return {
|
|
4168
|
-
...c,
|
|
4169
|
-
status: "new"
|
|
4170
|
-
};
|
|
4171
|
-
});
|
|
4172
|
-
}
|
|
4173
3109
|
async getCardsCenteredAtELO(options, filter) {
|
|
4174
3110
|
let targetElo = typeof options.elo === "number" ? options.elo : 1e3;
|
|
4175
3111
|
if (options.elo === "user") {
|
|
@@ -4355,19 +3291,23 @@ var init_courseDB3 = __esm({
|
|
|
4355
3291
|
return [];
|
|
4356
3292
|
}
|
|
4357
3293
|
// Navigation Strategy Manager implementation
|
|
4358
|
-
async getNavigationStrategy(
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
course: this.courseId,
|
|
4366
|
-
serializedData: ""
|
|
4367
|
-
};
|
|
3294
|
+
async getNavigationStrategy(id) {
|
|
3295
|
+
try {
|
|
3296
|
+
return await this.unpacker.getDocument(id);
|
|
3297
|
+
} catch (error) {
|
|
3298
|
+
logger.error(`[static/courseDB] Strategy ${id} not found: ${error}`);
|
|
3299
|
+
throw error;
|
|
3300
|
+
}
|
|
4368
3301
|
}
|
|
4369
3302
|
async getAllNavigationStrategies() {
|
|
4370
|
-
|
|
3303
|
+
const prefix = DocTypePrefixes["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */];
|
|
3304
|
+
try {
|
|
3305
|
+
const docs = await this.unpacker.getAllDocumentsByPrefix(prefix);
|
|
3306
|
+
return docs;
|
|
3307
|
+
} catch (error) {
|
|
3308
|
+
logger.warn(`[static/courseDB] Error loading navigation strategies: ${error}`);
|
|
3309
|
+
return [];
|
|
3310
|
+
}
|
|
4371
3311
|
}
|
|
4372
3312
|
async addNavigationStrategy(_data) {
|
|
4373
3313
|
throw new Error("Cannot add navigation strategies in static mode");
|
|
@@ -4375,9 +3315,52 @@ var init_courseDB3 = __esm({
|
|
|
4375
3315
|
async updateNavigationStrategy(_id, _data) {
|
|
4376
3316
|
throw new Error("Cannot update navigation strategies in static mode");
|
|
4377
3317
|
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Create a ContentNavigator for this course.
|
|
3320
|
+
*
|
|
3321
|
+
* Loads navigation strategy documents from static data and uses PipelineAssembler
|
|
3322
|
+
* to build a Pipeline. Falls back to default pipeline if no strategies found.
|
|
3323
|
+
*/
|
|
3324
|
+
async createNavigator(user) {
|
|
3325
|
+
try {
|
|
3326
|
+
const allStrategies = await this.getAllNavigationStrategies();
|
|
3327
|
+
if (allStrategies.length === 0) {
|
|
3328
|
+
logger.debug(
|
|
3329
|
+
"[static/courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
3330
|
+
);
|
|
3331
|
+
return createDefaultPipeline(user, this);
|
|
3332
|
+
}
|
|
3333
|
+
const assembler = new PipelineAssembler();
|
|
3334
|
+
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
3335
|
+
strategies: allStrategies,
|
|
3336
|
+
user,
|
|
3337
|
+
course: this
|
|
3338
|
+
});
|
|
3339
|
+
for (const warning of warnings) {
|
|
3340
|
+
logger.warn(`[PipelineAssembler] ${warning}`);
|
|
3341
|
+
}
|
|
3342
|
+
if (!pipeline) {
|
|
3343
|
+
logger.debug("[static/courseDB] Pipeline assembly failed, using default pipeline");
|
|
3344
|
+
return createDefaultPipeline(user, this);
|
|
3345
|
+
}
|
|
3346
|
+
logger.debug(
|
|
3347
|
+
`[static/courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
3348
|
+
);
|
|
3349
|
+
return pipeline;
|
|
3350
|
+
} catch (e) {
|
|
3351
|
+
logger.error(`[static/courseDB] Error creating navigator: ${e}`);
|
|
3352
|
+
throw e;
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
4378
3355
|
// Study Content Source implementation
|
|
4379
|
-
async
|
|
4380
|
-
|
|
3356
|
+
async getWeightedCards(limit) {
|
|
3357
|
+
try {
|
|
3358
|
+
const navigator = await this.createNavigator(this.userDB);
|
|
3359
|
+
return navigator.getWeightedCards(limit);
|
|
3360
|
+
} catch (e) {
|
|
3361
|
+
logger.error(`[static/courseDB] Error getting weighted cards: ${e}`);
|
|
3362
|
+
throw e;
|
|
3363
|
+
}
|
|
4381
3364
|
}
|
|
4382
3365
|
// Attachment helper methods (internal use, not part of interface)
|
|
4383
3366
|
/**
|