@vue-skuilder/db 0.2.27 → 0.2.29

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.
Files changed (82) hide show
  1. package/dist/classroomDB-DLTtLZct.d.cts +86 -0
  2. package/dist/classroomDB-DLTtLZct.d.ts +86 -0
  3. package/dist/{contentSource-LPf044hY.d.ts → contentSource-B6FrSihy.d.cts} +282 -99
  4. package/dist/{contentSource-D3c1fMAk.d.cts → contentSource-CqJmbOZN.d.ts} +282 -99
  5. package/dist/core/index.d.cts +16 -92
  6. package/dist/core/index.d.ts +16 -92
  7. package/dist/core/index.js +607 -179
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/core/index.mjs +606 -179
  10. package/dist/core/index.mjs.map +1 -1
  11. package/dist/{dataLayerProvider-DaAootVV.d.ts → dataLayerProvider-B9_UCvkR.d.ts} +2 -8
  12. package/dist/{dataLayerProvider-CeLiFbHv.d.cts → dataLayerProvider-DUxDqMtZ.d.cts} +2 -8
  13. package/dist/diagnostics/index.d.cts +443 -0
  14. package/dist/diagnostics/index.d.ts +443 -0
  15. package/dist/diagnostics/index.js +932 -0
  16. package/dist/diagnostics/index.js.map +1 -0
  17. package/dist/diagnostics/index.mjs +881 -0
  18. package/dist/diagnostics/index.mjs.map +1 -0
  19. package/dist/impl/couch/index.d.cts +13 -3
  20. package/dist/impl/couch/index.d.ts +13 -3
  21. package/dist/impl/couch/index.js +605 -179
  22. package/dist/impl/couch/index.js.map +1 -1
  23. package/dist/impl/couch/index.mjs +605 -179
  24. package/dist/impl/couch/index.mjs.map +1 -1
  25. package/dist/impl/static/index.d.cts +11 -5
  26. package/dist/impl/static/index.d.ts +11 -5
  27. package/dist/impl/static/index.js +602 -185
  28. package/dist/impl/static/index.js.map +1 -1
  29. package/dist/impl/static/index.mjs +602 -185
  30. package/dist/impl/static/index.mjs.map +1 -1
  31. package/dist/{index-BkBJlGDX.d.ts → index-CVGehe_t.d.ts} +1 -1
  32. package/dist/{index-D7WdMDAs.d.cts → index-Ktg72jKb.d.cts} +1 -1
  33. package/dist/index.d.cts +73 -11
  34. package/dist/index.d.ts +73 -11
  35. package/dist/index.js +696 -200
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +683 -200
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/{types-DjiFOZxJ.d.cts → types-D0oQeJAi.d.cts} +1 -1
  40. package/dist/{types-uJ2Xn3_X.d.ts → types-dXWfyz9B.d.ts} +1 -1
  41. package/dist/{types-legacy-CrwyZIvI.d.cts → types-legacy-BkOYOR6U.d.cts} +1 -1
  42. package/dist/{types-legacy-CrwyZIvI.d.ts → types-legacy-BkOYOR6U.d.ts} +1 -1
  43. package/dist/util/packer/index.d.cts +3 -3
  44. package/dist/util/packer/index.d.ts +3 -3
  45. package/package.json +15 -3
  46. package/src/core/interfaces/contentSource.ts +7 -0
  47. package/src/core/interfaces/dataLayerProvider.ts +3 -8
  48. package/src/core/navigators/Pipeline.ts +149 -14
  49. package/src/core/navigators/PipelineAssembler.ts +19 -40
  50. package/src/core/navigators/PipelineDebugger.ts +74 -17
  51. package/src/core/navigators/SrsDebugger.ts +37 -12
  52. package/src/core/navigators/defaults.ts +29 -5
  53. package/src/core/navigators/filters/WeightedFilter.ts +5 -1
  54. package/src/core/navigators/filters/eloDistance.ts +261 -76
  55. package/src/core/navigators/filters/hierarchyDefinition.ts +5 -1
  56. package/src/core/navigators/filters/index.ts +2 -2
  57. package/src/core/navigators/filters/interferenceMitigator.ts +5 -1
  58. package/src/core/navigators/filters/relativePriority.ts +5 -1
  59. package/src/core/navigators/filters/types.ts +24 -1
  60. package/src/core/navigators/filters/userTagPreference.ts +5 -1
  61. package/src/core/navigators/generators/elo.ts +23 -53
  62. package/src/core/navigators/generators/srs.ts +27 -124
  63. package/src/core/navigators/index.ts +32 -5
  64. package/src/core/navigators/pipelinePlan.ts +245 -0
  65. package/src/core/navigators/regulators.ts +230 -0
  66. package/src/core/types/studySession.ts +40 -0
  67. package/src/diagnostics/dataset.ts +242 -0
  68. package/src/diagnostics/derive.ts +555 -0
  69. package/src/diagnostics/index.ts +27 -0
  70. package/src/diagnostics/loader.ts +194 -0
  71. package/src/diagnostics/pipeline.ts +236 -0
  72. package/src/diagnostics/text.ts +265 -0
  73. package/src/impl/couch/PouchDataLayerProvider.ts +0 -23
  74. package/src/impl/couch/courseDB.ts +13 -0
  75. package/src/impl/static/StaticDataLayerProvider.ts +0 -11
  76. package/src/impl/static/courseDB.ts +9 -0
  77. package/src/index.ts +4 -0
  78. package/src/study/SessionController.ts +76 -2
  79. package/src/study/SessionOverlay.ts +7 -4
  80. package/tests/core/navigators/PipelineAssembler.test.ts +20 -5
  81. package/tests/core/navigators/eloDistanceFilter.test.ts +9 -9
  82. package/tsup.config.ts +1 -0
@@ -509,7 +509,7 @@ function parseCardElo(provenance) {
509
509
  const match = eloEntry.reason.match(/card:\s*(\d+)/);
510
510
  return match ? parseInt(match[1], 10) : void 0;
511
511
  }
512
- function buildRunReport(courseId, courseName, generatorName, generators, generatedCount, filters, allCards, selectedCards, userElo, hints) {
512
+ function buildRunReport(courseId, courseName, generatorName, generators, generatedCount, filters, allCards, selectedCards, userElo, hints, scoredCards, regulators) {
513
513
  const selectedIds = new Set(selectedCards.map((c) => c.cardId));
514
514
  const toReport = (card) => ({
515
515
  cardId: card.cardId,
@@ -517,7 +517,7 @@ function buildRunReport(courseId, courseName, generatorName, generators, generat
517
517
  origin: getOrigin(card),
518
518
  generator: card.provenance[0]?.strategyName || card.provenance[0]?.strategy,
519
519
  finalScore: card.score,
520
- cardElo: parseCardElo(card.provenance),
520
+ cardElo: card.cardElo ?? parseCardElo(card.provenance),
521
521
  provenance: card.provenance,
522
522
  tags: card.tags,
523
523
  selected: selectedIds.has(card.cardId)
@@ -562,6 +562,23 @@ function buildRunReport(courseId, courseName, generatorName, generators, generat
562
562
  note: `${discardedTailCards.length} additional candidate(s) scored below the top ${DISCARDED_KEEP_TOP} near-misses and were not retained (score ${scoreMin.toExponential(2)}\u2013${scoreMax.toExponential(2)}${eloFragment}). Likely ELO-window pull remnants filtered out by hierarchy/lesson/priority gates.`
563
563
  };
564
564
  }
565
+ const isUnselectedNew = (c) => !c.reviewID && !selectedIds.has(c.cardId);
566
+ const generatorScore = (c) => c.provenance[0]?.score ?? 0;
567
+ const keptIds = new Set(allCards.map((c) => c.cardId));
568
+ const hintExcluded = (c) => c.score > 0 && !keptIds.has(c.cardId);
569
+ let nextInLine;
570
+ for (const c of allCards) {
571
+ if (isUnselectedNew(c) && (!nextInLine || c.score > nextInLine.score)) nextInLine = c;
572
+ }
573
+ let topGenerated;
574
+ for (const c of scoredCards ?? allCards) {
575
+ if (!isUnselectedNew(c) || hintExcluded(c)) continue;
576
+ if (!topGenerated || generatorScore(c) > generatorScore(topGenerated)) topGenerated = c;
577
+ }
578
+ const unselectedNew = nextInLine || topGenerated ? {
579
+ ...nextInLine ? { nextInLine: toReport(nextInLine) } : {},
580
+ ...topGenerated && topGenerated.cardId !== nextInLine?.cardId ? { topGenerated: toReport(topGenerated) } : {}
581
+ } : void 0;
565
582
  const reviewsSelected = selectedCards.filter((c) => getOrigin(c) === "review").length;
566
583
  const newSelected = selectedCards.filter((c) => getOrigin(c) === "new").length;
567
584
  return {
@@ -577,7 +594,9 @@ function buildRunReport(courseId, courseName, generatorName, generators, generat
577
594
  reviewsSelected,
578
595
  newSelected,
579
596
  cards,
580
- discardedTail
597
+ unselectedNew,
598
+ discardedTail,
599
+ ...regulators ? { regulators } : {}
581
600
  };
582
601
  }
583
602
  function formatProvenance(provenance) {
@@ -1301,11 +1320,23 @@ var SrsDebugger_exports = {};
1301
1320
  __export(SrsDebugger_exports, {
1302
1321
  captureSrsBacklog: () => captureSrsBacklog,
1303
1322
  clearSrsBacklogDebug: () => clearSrsBacklogDebug,
1304
- getSrsBacklogDebug: () => getSrsBacklogDebug
1323
+ getSrsBacklogDebug: () => getSrsBacklogDebug,
1324
+ noteReviewPressure: () => noteReviewPressure
1305
1325
  });
1306
1326
  function captureSrsBacklog(snapshot) {
1307
1327
  snapshots.set(snapshot.courseId, snapshot);
1308
1328
  }
1329
+ function noteReviewPressure(courseId, pressure) {
1330
+ const snapshot = snapshots.get(courseId);
1331
+ if (!snapshot) return;
1332
+ snapshots.set(courseId, {
1333
+ ...snapshot,
1334
+ reviewMass: pressure.mass,
1335
+ healthyBacklog: pressure.healthyMass,
1336
+ backlogGrowthRate: pressure.rate,
1337
+ backlogMultiplier: pressure.multiplier
1338
+ });
1339
+ }
1309
1340
  function getSrsBacklogDebug() {
1310
1341
  return [...snapshots.values()].sort((a, b) => b.timestamp - a.timestamp);
1311
1342
  }
@@ -1584,13 +1615,12 @@ __export(elo_exports, {
1584
1615
  default: () => ELONavigator
1585
1616
  });
1586
1617
  import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
1587
- var ELO_RELEVANCE_SIGMA, ELONavigator;
1618
+ var ELONavigator;
1588
1619
  var init_elo = __esm({
1589
1620
  "src/core/navigators/generators/elo.ts"() {
1590
1621
  "use strict";
1591
1622
  init_navigators();
1592
1623
  init_logger();
1593
- ELO_RELEVANCE_SIGMA = 300;
1594
1624
  ELONavigator = class extends ContentNavigator {
1595
1625
  /** Human-readable name for CardGenerator interface */
1596
1626
  name;
@@ -1599,10 +1629,8 @@ var init_elo = __esm({
1599
1629
  this.name = strategyData?.name || "ELO";
1600
1630
  }
1601
1631
  /**
1602
- * Get new cards with suitability scores based on ELO distance.
1603
- *
1604
- * Cards closer to user's ELO get higher scores.
1605
- * Score formula: max(0, 1 - distance / 500)
1632
+ * Get the new cards nearest the learner's ELO, each scored with a flat
1633
+ * jitter in [0.5, 1]. Carries each card's ELO for the ELO distance filter.
1606
1634
  *
1607
1635
  * NOTE: This generator only handles NEW cards. Reviews are handled by
1608
1636
  * SRSNavigator. Use CompositeGenerator to combine both.
@@ -1630,20 +1658,20 @@ var init_elo = __esm({
1630
1658
  const scored = newCards.map((c) => {
1631
1659
  const cardElo = c.elo ?? 1e3;
1632
1660
  const distance = Math.abs(cardElo - userGlobalElo);
1633
- const relevance = Math.exp(-((distance / ELO_RELEVANCE_SIGMA) ** 2));
1634
- const samplingKey = relevance * (0.5 + 0.5 * Math.random());
1661
+ const jitter = 0.5 + 0.5 * Math.random();
1635
1662
  return {
1636
1663
  cardId: c.cardID,
1637
1664
  courseId: c.courseID,
1638
- score: samplingKey,
1665
+ score: jitter,
1666
+ cardElo,
1639
1667
  provenance: [
1640
1668
  {
1641
1669
  strategy: "elo",
1642
1670
  strategyName: this.strategyName || this.name,
1643
1671
  strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
1644
1672
  action: "generated",
1645
- score: samplingKey,
1646
- reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), relevance ${relevance.toFixed(3)}, key ${samplingKey.toFixed(3)}`
1673
+ score: jitter,
1674
+ reason: `new card near learner ELO: distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), jitter ${jitter.toFixed(3)}`
1647
1675
  }
1648
1676
  ]
1649
1677
  };
@@ -2519,43 +2547,132 @@ var init_prescribed = __esm({
2519
2547
  }
2520
2548
  });
2521
2549
 
2550
+ // src/core/navigators/regulators.ts
2551
+ var regulators_exports = {};
2552
+ __export(regulators_exports, {
2553
+ DEFAULT_REGULATOR_CONFIG: () => DEFAULT_REGULATOR_CONFIG,
2554
+ INTAKE_CLOCK_KEY: () => INTAKE_CLOCK_KEY,
2555
+ applyReading: () => applyReading,
2556
+ frozenMsAt: () => frozenMsAt,
2557
+ intakeHours: () => intakeHours,
2558
+ intakeReading: () => intakeReading,
2559
+ resetIntakeClock: () => resetIntakeClock,
2560
+ reviewMassReading: () => reviewMassReading,
2561
+ reviewWeight: () => reviewWeight,
2562
+ stepIntakeClock: () => stepIntakeClock
2563
+ });
2564
+ function clamp01(x) {
2565
+ return Math.min(1, Math.max(0, x));
2566
+ }
2567
+ function reviewWeight(card, generatedScore, referenceScore) {
2568
+ if (card.reviewUrgency !== void 0 && generatedScore !== void 0 && generatedScore > 0) {
2569
+ return clamp01(card.reviewUrgency * (card.score / generatedScore));
2570
+ }
2571
+ return clamp01(card.score / referenceScore);
2572
+ }
2573
+ function reviewMassReading(reviews, generatedScores, config = DEFAULT_REGULATOR_CONFIG.reviewMass) {
2574
+ const mass = reviews.reduce(
2575
+ (m, c) => m + reviewWeight(c, generatedScores.get(c.cardId), config.referenceScore),
2576
+ 0
2577
+ );
2578
+ const multiplier = mass > config.healthyMass ? Math.pow(config.rate, (mass - config.healthyMass) / config.healthyMass) : 1;
2579
+ return {
2580
+ name: "review-mass",
2581
+ class: "review",
2582
+ urgency: mass,
2583
+ multiplier,
2584
+ applied: reviews.length,
2585
+ inputs: { due: reviews.length, mass, healthyMass: config.healthyMass }
2586
+ };
2587
+ }
2588
+ function resetIntakeClock(nowMs) {
2589
+ return { lastNewAt: new Date(nowMs).toISOString(), frozenMs: 0, unservableSince: null };
2590
+ }
2591
+ function frozenMsAt(state, nowMs) {
2592
+ const open = state.unservableSince ? Math.max(0, nowMs - Date.parse(state.unservableSince)) : 0;
2593
+ return state.frozenMs + open;
2594
+ }
2595
+ function intakeHours(state, nowMs) {
2596
+ const elapsed = nowMs - Date.parse(state.lastNewAt);
2597
+ return Math.max(0, elapsed - frozenMsAt(state, nowMs)) / 36e5;
2598
+ }
2599
+ function stepIntakeClock(state, nowMs, eligibleNew) {
2600
+ if (eligibleNew === 0 && !state.unservableSince) {
2601
+ return { ...state, unservableSince: new Date(nowMs).toISOString() };
2602
+ }
2603
+ if (eligibleNew > 0 && state.unservableSince) {
2604
+ return { ...state, frozenMs: frozenMsAt(state, nowMs), unservableSince: null };
2605
+ }
2606
+ return state;
2607
+ }
2608
+ function intakeReading(state, nowMs, counts, config = DEFAULT_REGULATOR_CONFIG.intake) {
2609
+ const hours = intakeHours(state, nowMs);
2610
+ const multiplier = counts.eligibleNew > 0 ? Math.pow(config.rate, hours / config.scaleHours) : 1;
2611
+ return {
2612
+ name: "intake",
2613
+ class: "new",
2614
+ urgency: hours,
2615
+ multiplier,
2616
+ applied: counts.eligibleNew,
2617
+ inputs: {
2618
+ hoursSinceNew: hours,
2619
+ frozenHours: frozenMsAt(state, nowMs) / 36e5,
2620
+ eligibleNew: counts.eligibleNew,
2621
+ newCandidates: counts.newCandidates
2622
+ }
2623
+ };
2624
+ }
2625
+ function applyReading(cards, reading) {
2626
+ if (reading.multiplier === 1) return;
2627
+ const reason = reading.name === "review-mass" ? `review mass ${reading.urgency.toFixed(1)} (healthy ${reading.inputs.healthyMass}) \u2192 \xD7${reading.multiplier.toFixed(2)}` : `${reading.urgency.toFixed(1)}h since a new card \u2192 \xD7${reading.multiplier.toFixed(2)}`;
2628
+ for (const card of cards) {
2629
+ card.score *= reading.multiplier;
2630
+ card.provenance.push({
2631
+ strategy: "regulator",
2632
+ strategyName: `Regulator: ${REGULATOR_LABEL[reading.name]}`,
2633
+ strategyId: `regulator-${reading.name}`,
2634
+ action: reading.multiplier > 1 ? "boosted" : "penalized",
2635
+ score: card.score,
2636
+ reason
2637
+ });
2638
+ }
2639
+ }
2640
+ var DEFAULT_REGULATOR_CONFIG, INTAKE_CLOCK_KEY, REGULATOR_LABEL;
2641
+ var init_regulators = __esm({
2642
+ "src/core/navigators/regulators.ts"() {
2643
+ "use strict";
2644
+ DEFAULT_REGULATOR_CONFIG = {
2645
+ reviewMass: { referenceScore: 0.95, healthyMass: 20, rate: 2 },
2646
+ intake: { rate: 2, scaleHours: 24 }
2647
+ };
2648
+ INTAKE_CLOCK_KEY = "IntakeClock";
2649
+ REGULATOR_LABEL = {
2650
+ "review-mass": "Review mass",
2651
+ intake: "Intake"
2652
+ };
2653
+ }
2654
+ });
2655
+
2522
2656
  // src/core/navigators/generators/srs.ts
2523
2657
  var srs_exports = {};
2524
2658
  __export(srs_exports, {
2525
2659
  default: () => SRSNavigator
2526
2660
  });
2527
2661
  import moment from "moment";
2528
- var DEFAULT_HEALTHY_BACKLOG, BACKLOG_GROWTH_RATE, SRSNavigator;
2662
+ var SRSNavigator;
2529
2663
  var init_srs = __esm({
2530
2664
  "src/core/navigators/generators/srs.ts"() {
2531
2665
  "use strict";
2532
2666
  init_navigators();
2533
2667
  init_SrsDebugger();
2668
+ init_regulators();
2534
2669
  init_logger();
2535
- DEFAULT_HEALTHY_BACKLOG = 20;
2536
- BACKLOG_GROWTH_RATE = 2;
2537
2670
  SRSNavigator = class extends ContentNavigator {
2538
2671
  /** Human-readable name for CardGenerator interface */
2539
2672
  name;
2540
- /** Healthy backlog threshold - when exceeded, backlog pressure kicks in */
2541
- healthyBacklog;
2542
2673
  constructor(user, course, strategyData) {
2543
2674
  super(user, course, strategyData);
2544
2675
  this.name = strategyData?.name || "SRS";
2545
- const config = this.parseConfig(strategyData?.serializedData);
2546
- this.healthyBacklog = config.healthyBacklog ?? DEFAULT_HEALTHY_BACKLOG;
2547
- }
2548
- /**
2549
- * Parse configuration from serialized JSON.
2550
- */
2551
- parseConfig(serializedData) {
2552
- if (!serializedData) return {};
2553
- try {
2554
- return JSON.parse(serializedData);
2555
- } catch {
2556
- logger.warn("[SRS] Failed to parse strategy config, using defaults");
2557
- return {};
2558
- }
2559
2676
  }
2560
2677
  /**
2561
2678
  * Get review cards scored by urgency.
@@ -2563,7 +2680,6 @@ var init_srs = __esm({
2563
2680
  * Score formula combines:
2564
2681
  * - Relative overdueness: hoursOverdue / intervalHours
2565
2682
  * - Interval recency: exponential decay favoring shorter intervals
2566
- * - Backlog pressure: boost when due reviews exceed healthy threshold
2567
2683
  *
2568
2684
  * Cards not yet due are excluded (not scored as 0).
2569
2685
  *
@@ -2600,7 +2716,6 @@ var init_srs = __esm({
2600
2716
  }
2601
2717
  }
2602
2718
  }
2603
- const backlogMultiplier = this.computeBacklogMultiplier(dueReviews.length);
2604
2719
  const notDue = reviews.filter((r) => !now.isAfter(moment.utc(r.reviewTime)));
2605
2720
  let nextDueIn = null;
2606
2721
  if (notDue.length > 0) {
@@ -2611,9 +2726,8 @@ var init_srs = __esm({
2611
2726
  nextDueIn = until.asHours() < 1 ? `${Math.round(until.asMinutes())}m` : until.asHours() < 24 ? `${Math.round(until.asHours())}h` : `${Math.round(until.asDays())}d`;
2612
2727
  }
2613
2728
  if (dueReviews.length > 0) {
2614
- const pressureNote = backlogMultiplier > 1 ? ` [backlog pressure: \xD7${backlogMultiplier.toFixed(2)}]` : ` [healthy backlog]`;
2615
2729
  logger.info(
2616
- `[SRS] Course ${courseId}: ${dueReviews.length} reviews due now (of ${reviews.length} scheduled)${pressureNote}`
2730
+ `[SRS] Course ${courseId}: ${dueReviews.length} reviews due now (of ${reviews.length} scheduled)`
2617
2731
  );
2618
2732
  } else if (reviews.length > 0) {
2619
2733
  const sortedByDue = [...reviews].sort(
@@ -2630,11 +2744,12 @@ var init_srs = __esm({
2630
2744
  logger.info(`[SRS] Course ${courseId}: No reviews scheduled`);
2631
2745
  }
2632
2746
  const scored = dueReviews.map((review) => {
2633
- const { score, reason } = this.computeUrgencyScore(review, now, backlogMultiplier);
2747
+ const { score, urgency, reason } = this.computeUrgencyScore(review, now);
2634
2748
  return {
2635
2749
  cardId: review.cardId,
2636
2750
  courseId: review.courseId,
2637
2751
  score,
2752
+ reviewUrgency: urgency,
2638
2753
  reviewID: review._id,
2639
2754
  provenance: [
2640
2755
  {
@@ -2653,47 +2768,20 @@ var init_srs = __esm({
2653
2768
  courseId,
2654
2769
  scheduledTotal: reviews.length,
2655
2770
  dueNow: dueReviews.length,
2656
- healthyBacklog: this.healthyBacklog,
2657
- backlogMultiplier,
2658
- backlogGrowthRate: BACKLOG_GROWTH_RATE,
2771
+ healthyBacklog: DEFAULT_REGULATOR_CONFIG.reviewMass.healthyMass,
2772
+ reviewMass: null,
2773
+ backlogMultiplier: 1,
2774
+ backlogGrowthRate: DEFAULT_REGULATOR_CONFIG.reviewMass.rate,
2659
2775
  topReviewScore: sorted.length > 0 ? sorted[0].score : null,
2660
2776
  nextDueIn,
2661
2777
  timestamp: Date.now()
2662
2778
  });
2663
2779
  return { cards: sorted.slice(0, limit) };
2664
2780
  }
2665
- /**
2666
- * Compute the multiplicative backlog pressure based on number of due reviews.
2667
- *
2668
- * ×1.0 at or below the healthy threshold (no boost); above it, grows as
2669
- * BACKLOG_GROWTH_RATE raised to the excess expressed in multiples of the
2670
- * healthy threshold. Uncapped — self-regulating instead: reviews winning
2671
- * slots depletes dueCount, which drops the ratio and relaxes the multiplier
2672
- * next run.
2673
- *
2674
- * Examples (with default healthyBacklog=20, BACKLOG_GROWTH_RATE=1.5):
2675
- * - 10 due reviews → ×1.00 (healthy)
2676
- * - 20 due reviews → ×1.00 (at threshold, ratio 0)
2677
- * - 40 due reviews → ×1.50 (ratio 1, 2x threshold)
2678
- * - 60 due reviews → ×2.25 (ratio 2, 3x threshold — old hard cap was ×2.00 here)
2679
- * - 100 due reviews → ×5.06 (ratio 4, 5x threshold)
2680
- * - 160 due reviews → ×17.09 (ratio 7, 8x threshold)
2681
- *
2682
- * @param dueCount - Number of reviews currently due
2683
- * @returns Multiplier applied to review urgency (>= 1.0, unbounded)
2684
- */
2685
- computeBacklogMultiplier(dueCount) {
2686
- if (dueCount <= this.healthyBacklog) {
2687
- return 1;
2688
- }
2689
- const excess = dueCount - this.healthyBacklog;
2690
- const ratio = excess / this.healthyBacklog;
2691
- return Math.pow(BACKLOG_GROWTH_RATE, ratio);
2692
- }
2693
2781
  /**
2694
2782
  * Compute urgency score for a review card.
2695
2783
  *
2696
- * Three factors:
2784
+ * Two factors:
2697
2785
  * 1. Relative overdueness = hoursOverdue / intervalHours
2698
2786
  * - 2 days overdue on 3-day interval = 0.67 (urgent)
2699
2787
  * - 2 days overdue on 180-day interval = 0.01 (not urgent)
@@ -2703,20 +2791,14 @@ var init_srs = __esm({
2703
2791
  * - 30 days (720h) → ~0.56
2704
2792
  * - 180 days → ~0.30
2705
2793
  *
2706
- * 3. Backlog pressure = global *multiplier* when review backlog exceeds the
2707
- * healthy threshold (×1.0 healthy → exponential growth, uncapped, above it).
2708
- *
2709
- * Combined: (base 0.5 + urgency factors * 0.45) × backlog multiplier.
2710
- * Per-card range before pressure: ~0.57–0.95. NOT clamped to 1.0 — under a
2711
- * heavy backlog reviews scale onto the open scale to compete with (and exceed)
2712
- * new cards; there's no ceiling at all now, so a bad enough backlog always
2713
- * wins eventually — self-regulating because winning slots depletes dueCount.
2794
+ * Combined: base 0.5 + urgency factors * 0.45, so ~0.57–0.95 per card.
2795
+ * Backlog pressure is applied later, by the regulator stage, which can lift
2796
+ * reviews onto the open scale above new cards (see regulators.ts).
2714
2797
  *
2715
2798
  * @param review - The scheduled card to score
2716
2799
  * @param now - Current time
2717
- * @param backlogMultiplier - Pre-computed backlog multiplier (>= 1.0, unbounded)
2718
2800
  */
2719
- computeUrgencyScore(review, now, backlogMultiplier) {
2801
+ computeUrgencyScore(review, now) {
2720
2802
  const scheduledAt = moment.utc(review.scheduledAt);
2721
2803
  const due = moment.utc(review.reviewTime);
2722
2804
  const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
@@ -2725,20 +2807,16 @@ var init_srs = __esm({
2725
2807
  const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
2726
2808
  const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
2727
2809
  const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
2728
- const baseScore = 0.5 + urgency * 0.45;
2729
- const score = baseScore * backlogMultiplier;
2810
+ const score = 0.5 + urgency * 0.45;
2730
2811
  const reasonParts = [
2731
2812
  `${Math.round(hoursOverdue)}h overdue`,
2732
2813
  `interval: ${Math.round(intervalHours)}h`,
2733
2814
  `relative: ${relativeOverdue.toFixed(2)}`,
2734
2815
  `recency: ${recencyFactor.toFixed(2)}`
2735
2816
  ];
2736
- if (backlogMultiplier > 1) {
2737
- reasonParts.push(`backlog: \xD7${backlogMultiplier.toFixed(2)}`);
2738
- }
2739
2817
  reasonParts.push("review");
2740
2818
  const reason = reasonParts.join(", ");
2741
- return { score, reason };
2819
+ return { score, urgency, reason };
2742
2820
  }
2743
2821
  };
2744
2822
  }
@@ -2793,6 +2871,8 @@ var init_WeightedFilter = __esm({
2793
2871
  init_contentNavigationStrategy();
2794
2872
  WeightedFilter = class {
2795
2873
  name;
2874
+ kind;
2875
+ liveOnly;
2796
2876
  inner;
2797
2877
  learnable;
2798
2878
  staticWeight;
@@ -2800,6 +2880,8 @@ var init_WeightedFilter = __esm({
2800
2880
  constructor(inner, learnable = DEFAULT_LEARNABLE_WEIGHT, staticWeight = false, strategyId) {
2801
2881
  this.inner = inner;
2802
2882
  this.name = inner.name;
2883
+ this.kind = inner.kind;
2884
+ this.liveOnly = inner.liveOnly;
2803
2885
  this.learnable = learnable;
2804
2886
  this.staticWeight = staticWeight;
2805
2887
  this.strategyId = strategyId;
@@ -2864,58 +2946,141 @@ var init_WeightedFilter = __esm({
2864
2946
  // src/core/navigators/filters/eloDistance.ts
2865
2947
  var eloDistance_exports = {};
2866
2948
  __export(eloDistance_exports, {
2867
- DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
2868
- DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
2869
- DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
2870
- createEloDistanceFilter: () => createEloDistanceFilter
2949
+ DEFAULT_ELO_DISTANCE_CONFIG: () => DEFAULT_ELO_DISTANCE_CONFIG,
2950
+ createEloDistanceFilter: () => createEloDistanceFilter,
2951
+ default: () => EloDistanceFilter,
2952
+ tagAwareGap: () => tagAwareGap
2871
2953
  });
2872
2954
  function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
2873
2955
  const normalizedDistance = distance / halfLife;
2874
2956
  const decay = Math.exp(-(normalizedDistance * normalizedDistance));
2875
2957
  return minMultiplier + (maxMultiplier - minMultiplier) * decay;
2876
2958
  }
2959
+ function resolveConfig(config) {
2960
+ return { ...DEFAULT_ELO_DISTANCE_CONFIG, ...config };
2961
+ }
2962
+ function tagAwareGap(cardTags, cardElo, userElo, minTagCount) {
2963
+ const globalGap = cardElo.global.score - userElo.global.score;
2964
+ const tags = [];
2965
+ for (const tag of cardTags) {
2966
+ const user = userElo.tags[tag];
2967
+ if (!user || user.score === COUNT_ONLY_SENTINEL || user.count < minTagCount) continue;
2968
+ const card = cardElo.tags[tag]?.score ?? cardElo.global.score;
2969
+ tags.push({
2970
+ tag,
2971
+ gap: card - user.score,
2972
+ weight: user.count / (user.count + TAG_CONFIDENCE_HALF)
2973
+ });
2974
+ }
2975
+ if (tags.length === 0) return { gap: globalGap, globalGap, tags };
2976
+ const total = tags.reduce((w, t) => w + t.weight, 0);
2977
+ const tagGap = tags.reduce((g, t) => g + t.weight * t.gap, 0) / total;
2978
+ const lambda = total / (total + 1);
2979
+ return { gap: lambda * tagGap + (1 - lambda) * globalGap, globalGap, tags };
2980
+ }
2981
+ function tagReason(tags, globalGap) {
2982
+ const shown = [...tags].sort((a, b) => Math.abs(b.gap) * b.weight - Math.abs(a.gap) * a.weight).slice(0, 3).map((t) => `${t.tag} ${t.gap >= 0 ? "+" : ""}${Math.round(t.gap)}`).join(", ");
2983
+ const more = tags.length > 3 ? `, +${tags.length - 3} more` : "";
2984
+ return ` on ${tags.length} shared tag(s) [${shown}${more}] (global ${globalGap >= 0 ? "+" : ""}${Math.round(globalGap)})`;
2985
+ }
2986
+ async function applyEloDistance(cards, context, config, source) {
2987
+ const { course, userElo, userCourseElo } = context;
2988
+ const { halfLife, minMultiplier, maxMultiplier } = config;
2989
+ const tagAware = config.tagAware && userCourseElo !== void 0;
2990
+ const missing = cards.filter((c) => tagAware || c.cardElo === void 0).map((c) => c.cardId);
2991
+ const fetched = /* @__PURE__ */ new Map();
2992
+ if (missing.length > 0) {
2993
+ const elos = await course.getCardEloData(missing);
2994
+ missing.forEach((id, i) => {
2995
+ if (elos[i]) fetched.set(id, elos[i]);
2996
+ });
2997
+ }
2998
+ return cards.map((card) => {
2999
+ const full = fetched.get(card.cardId);
3000
+ const cardElo = full?.global?.score ?? card.cardElo ?? DEFAULT_CARD_ELO;
3001
+ let distance = Math.abs(cardElo - userElo);
3002
+ let how = "";
3003
+ if (tagAware && full) {
3004
+ const t = tagAwareGap(card.tags ?? [], full, userCourseElo, config.minTagCount);
3005
+ distance = Math.abs(t.gap);
3006
+ if (t.tags.length > 0) how = tagReason(t.tags, t.globalGap);
3007
+ }
3008
+ const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
3009
+ const newScore = card.score * multiplier;
3010
+ const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
3011
+ return {
3012
+ ...card,
3013
+ cardElo,
3014
+ score: newScore,
3015
+ provenance: [
3016
+ ...card.provenance,
3017
+ {
3018
+ strategy: "eloDistance",
3019
+ strategyName: source.name,
3020
+ strategyId: source.strategyId,
3021
+ action,
3022
+ score: newScore,
3023
+ reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)})${how} \u2192 ${multiplier.toFixed(2)}x`
3024
+ }
3025
+ ]
3026
+ };
3027
+ });
3028
+ }
2877
3029
  function createEloDistanceFilter(config) {
2878
- const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
2879
- const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
2880
- const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
3030
+ const resolved = resolveConfig(config);
3031
+ const source = { name: "ELO Distance Filter", strategyId: "ELO_DISTANCE_FILTER" };
2881
3032
  return {
2882
- name: "ELO Distance Filter",
2883
- async transform(cards, context) {
2884
- const { course, userElo } = context;
2885
- const cardIds = cards.map((c) => c.cardId);
2886
- const cardElos = await course.getCardEloData(cardIds);
2887
- return cards.map((card, i) => {
2888
- const cardElo = cardElos[i]?.global?.score ?? 1e3;
2889
- const distance = Math.abs(cardElo - userElo);
2890
- const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
2891
- const newScore = card.score * multiplier;
2892
- const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
2893
- return {
2894
- ...card,
2895
- score: newScore,
2896
- provenance: [
2897
- ...card.provenance,
2898
- {
2899
- strategy: "eloDistance",
2900
- strategyName: "ELO Distance Filter",
2901
- strategyId: "ELO_DISTANCE_FILTER",
2902
- action,
2903
- score: newScore,
2904
- reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
2905
- }
2906
- ]
2907
- };
2908
- });
2909
- }
3033
+ name: source.name,
3034
+ kind: "signal",
3035
+ liveOnly: true,
3036
+ transform: (cards, context) => applyEloDistance(cards, context, resolved, source)
2910
3037
  };
2911
3038
  }
2912
- var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
3039
+ var DEFAULT_ELO_DISTANCE_CONFIG, TAG_CONFIDENCE_HALF, COUNT_ONLY_SENTINEL, DEFAULT_CARD_ELO, EloDistanceFilter;
2913
3040
  var init_eloDistance = __esm({
2914
3041
  "src/core/navigators/filters/eloDistance.ts"() {
2915
3042
  "use strict";
2916
- DEFAULT_HALF_LIFE = 200;
2917
- DEFAULT_MIN_MULTIPLIER = 0.3;
2918
- DEFAULT_MAX_MULTIPLIER = 1;
3043
+ init_navigators();
3044
+ DEFAULT_ELO_DISTANCE_CONFIG = {
3045
+ halfLife: 300,
3046
+ minMultiplier: 0.05,
3047
+ maxMultiplier: 1,
3048
+ tagAware: true,
3049
+ minTagCount: 3
3050
+ };
3051
+ TAG_CONFIDENCE_HALF = 10;
3052
+ COUNT_ONLY_SENTINEL = -1;
3053
+ DEFAULT_CARD_ELO = 1e3;
3054
+ EloDistanceFilter = class _EloDistanceFilter extends ContentNavigator {
3055
+ name;
3056
+ /** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
3057
+ static kind = "signal";
3058
+ kind = _EloDistanceFilter.kind;
3059
+ liveOnly = true;
3060
+ config;
3061
+ constructor(user, course, strategyData) {
3062
+ super(user, course, strategyData);
3063
+ this.name = strategyData.name || "ELO Distance";
3064
+ let parsed;
3065
+ try {
3066
+ parsed = strategyData.serializedData ? JSON.parse(strategyData.serializedData) : void 0;
3067
+ } catch {
3068
+ parsed = void 0;
3069
+ }
3070
+ this.config = resolveConfig(parsed);
3071
+ }
3072
+ transform(cards, context) {
3073
+ return applyEloDistance(cards, context, this.config, {
3074
+ name: this.name,
3075
+ strategyId: this.strategyId || "NAVIGATION_STRATEGY-eloDistance-default"
3076
+ });
3077
+ }
3078
+ async getWeightedCards(_limit) {
3079
+ throw new Error(
3080
+ "EloDistanceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
3081
+ );
3082
+ }
3083
+ };
2919
3084
  }
2920
3085
  });
2921
3086
 
@@ -2932,10 +3097,13 @@ var init_hierarchyDefinition = __esm({
2932
3097
  init_navigators();
2933
3098
  init_logger();
2934
3099
  DEFAULT_MIN_COUNT2 = 3;
2935
- HierarchyDefinitionNavigator = class extends ContentNavigator {
3100
+ HierarchyDefinitionNavigator = class _HierarchyDefinitionNavigator extends ContentNavigator {
2936
3101
  config;
2937
3102
  /** Human-readable name for CardFilter interface */
2938
3103
  name;
3104
+ /** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
3105
+ static kind = "gate";
3106
+ kind = _HierarchyDefinitionNavigator.kind;
2939
3107
  constructor(user, course, strategyData) {
2940
3108
  super(user, course, strategyData);
2941
3109
  this.config = this.parseConfig(strategyData.serializedData);
@@ -3202,10 +3370,13 @@ var init_userTagPreference = __esm({
3202
3370
  "src/core/navigators/filters/userTagPreference.ts"() {
3203
3371
  "use strict";
3204
3372
  init_navigators();
3205
- UserTagPreferenceFilter = class extends ContentNavigator {
3373
+ UserTagPreferenceFilter = class _UserTagPreferenceFilter extends ContentNavigator {
3206
3374
  _strategyData;
3207
3375
  /** Human-readable name for CardFilter interface */
3208
3376
  name;
3377
+ /** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
3378
+ static kind = "signal";
3379
+ kind = _UserTagPreferenceFilter.kind;
3209
3380
  constructor(user, course, strategyData) {
3210
3381
  super(user, course, strategyData);
3211
3382
  this._strategyData = strategyData;
@@ -3315,6 +3486,7 @@ var init_userTagPreference = __esm({
3315
3486
  // src/core/navigators/filters/index.ts
3316
3487
  var filters_exports = {};
3317
3488
  __export(filters_exports, {
3489
+ EloDistanceFilter: () => EloDistanceFilter,
3318
3490
  UserTagPreferenceFilter: () => UserTagPreferenceFilter,
3319
3491
  createEloDistanceFilter: () => createEloDistanceFilter
3320
3492
  });
@@ -3353,10 +3525,13 @@ var init_interferenceMitigator = __esm({
3353
3525
  DEFAULT_MIN_COUNT3 = 10;
3354
3526
  DEFAULT_MIN_ELAPSED_DAYS = 3;
3355
3527
  DEFAULT_INTERFERENCE_DECAY = 0.8;
3356
- InterferenceMitigatorNavigator = class extends ContentNavigator {
3528
+ InterferenceMitigatorNavigator = class _InterferenceMitigatorNavigator extends ContentNavigator {
3357
3529
  config;
3358
3530
  /** Human-readable name for CardFilter interface */
3359
3531
  name;
3532
+ /** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
3533
+ static kind = "signal";
3534
+ kind = _InterferenceMitigatorNavigator.kind;
3360
3535
  /** Precomputed map: tag -> set of { partner, decay } it interferes with */
3361
3536
  interferenceMap;
3362
3537
  constructor(user, course, strategyData) {
@@ -3572,10 +3747,13 @@ var init_relativePriority = __esm({
3572
3747
  DEFAULT_PRIORITY = 0.5;
3573
3748
  DEFAULT_PRIORITY_INFLUENCE = 0.5;
3574
3749
  DEFAULT_COMBINE_MODE = "max";
3575
- RelativePriorityNavigator = class extends ContentNavigator {
3750
+ RelativePriorityNavigator = class _RelativePriorityNavigator extends ContentNavigator {
3576
3751
  config;
3577
3752
  /** Human-readable name for CardFilter interface */
3578
3753
  name;
3754
+ /** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
3755
+ static kind = "signal";
3756
+ kind = _RelativePriorityNavigator.kind;
3579
3757
  constructor(user, course, strategyData) {
3580
3758
  super(user, course, strategyData);
3581
3759
  this.config = this.parseConfig(strategyData.serializedData);
@@ -3983,6 +4161,8 @@ var init_Pipeline = __esm({
3983
4161
  init_orchestration();
3984
4162
  init_PipelineDebugger();
3985
4163
  init_diversityRerank();
4164
+ init_regulators();
4165
+ init_SrsDebugger();
3986
4166
  VERBOSE_RESULTS = true;
3987
4167
  Pipeline = class extends ContentNavigator {
3988
4168
  generator;
@@ -4008,6 +4188,13 @@ var init_Pipeline = __esm({
4008
4188
  * getWeightedCards() call, then cleared.
4009
4189
  */
4010
4190
  _ephemeralHints = null;
4191
+ /**
4192
+ * The intake valve's clock (see regulators.ts), loaded from strategy state on
4193
+ * first use and kept in memory. Writes are chained so a presentation and a
4194
+ * run can't race each other's revision.
4195
+ */
4196
+ _intakeClock = null;
4197
+ _intakeClockWrite = Promise.resolve();
4011
4198
  /**
4012
4199
  * Create a new pipeline.
4013
4200
  *
@@ -4082,13 +4269,12 @@ var init_Pipeline = __esm({
4082
4269
  }
4083
4270
  }
4084
4271
  generatorSummaries = Array.from(genMap.entries()).map(([name, data]) => {
4085
- const newCards = data.cards.filter((c) => c.provenance[0]?.reason?.includes("new card"));
4086
- const reviewCards = data.cards.filter((c) => c.provenance[0]?.reason?.includes("review"));
4272
+ const reviewCount = data.cards.filter((c) => c.reviewID).length;
4087
4273
  return {
4088
4274
  name,
4089
4275
  cardCount: data.cards.length,
4090
- newCount: newCards.length,
4091
- reviewCount: reviewCards.length,
4276
+ newCount: data.cards.length - reviewCount,
4277
+ reviewCount,
4092
4278
  topScore: Math.max(...data.cards.map((c) => c.score), 0)
4093
4279
  };
4094
4280
  });
@@ -4124,19 +4310,24 @@ var init_Pipeline = __esm({
4124
4310
  cards.filter((c) => c.provenance.some((p) => p.strategy === "prescribed")).map((c) => c.cardId)
4125
4311
  );
4126
4312
  const filterImpacts = [];
4313
+ const generatedScores = new Map(cards.map((c) => [c.cardId, c.score]));
4314
+ const gated = /* @__PURE__ */ new Set();
4127
4315
  for (const filter of this.filters) {
4128
4316
  const beforeCount = cards.length;
4129
4317
  const beforeScores = new Map(cards.map((c) => [c.cardId, c.score]));
4130
4318
  cards = await filter.transform(cards, context);
4131
4319
  let boosted = 0, penalized = 0, passed = 0;
4132
4320
  const removed = beforeCount - cards.length;
4321
+ const kind = filter.kind ?? "gate";
4133
4322
  for (const card of cards) {
4134
4323
  const before = beforeScores.get(card.cardId) ?? 0;
4135
4324
  if (card.score > before) boosted++;
4136
- else if (card.score < before) penalized++;
4137
- else passed++;
4325
+ else if (card.score < before) {
4326
+ penalized++;
4327
+ if (kind === "gate") gated.add(card.cardId);
4328
+ } else passed++;
4138
4329
  }
4139
- filterImpacts.push({ name: filter.name, boosted, penalized, passed, removed });
4330
+ filterImpacts.push({ name: filter.name, kind, boosted, penalized, passed, removed });
4140
4331
  if (prescribedIds.size > 0) {
4141
4332
  const survivingIds = new Set(cards.map((c) => c.cardId));
4142
4333
  const killedPrescribed = [...prescribedIds].filter((id) => !survivingIds.has(id));
@@ -4150,7 +4341,9 @@ var init_Pipeline = __esm({
4150
4341
  }
4151
4342
  logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeScores.size} \u2192 ${cards.length} cards (\u2191${boosted} \u2193${penalized} =${passed})`);
4152
4343
  }
4344
+ const scoredCards = cards;
4153
4345
  cards = cards.filter((c) => c.score > 0);
4346
+ const regulators = await this.regulate(cards, generatedScores, gated);
4154
4347
  const hints = this._ephemeralHints;
4155
4348
  if (hints) {
4156
4349
  this._ephemeralHints = null;
@@ -4186,7 +4379,9 @@ var init_Pipeline = __esm({
4186
4379
  cards,
4187
4380
  result,
4188
4381
  context.userElo,
4189
- hints ?? void 0
4382
+ hints ?? void 0,
4383
+ scoredCards,
4384
+ regulators
4190
4385
  );
4191
4386
  captureRun(report);
4192
4387
  } catch (e) {
@@ -4365,6 +4560,77 @@ var init_Pipeline = __esm({
4365
4560
  logger.info(`[Pipeline] Hints applied: ${beforeCount} \u2192 ${cards.length} cards`);
4366
4561
  return cards;
4367
4562
  }
4563
+ /**
4564
+ * The regulator stage: measure each class's pressure and scale it.
4565
+ *
4566
+ * - Review mass: every due review's SRS urgency times the filters' net
4567
+ * effect on it.
4568
+ * - Intake: servable hours since a new card was presented, applied only to
4569
+ * eligible new cards (no gate penalized them). With none eligible, the
4570
+ * clock freezes.
4571
+ *
4572
+ * Mutates `cards` in place; returns the readings for the run report.
4573
+ */
4574
+ async regulate(cards, generatedScores, gated) {
4575
+ const config = DEFAULT_REGULATOR_CONFIG;
4576
+ const reviews = cards.filter((c) => c.reviewID);
4577
+ const newCards = cards.filter((c) => !c.reviewID);
4578
+ const eligibleNew = newCards.filter((c) => !gated.has(c.cardId));
4579
+ const mass = reviewMassReading(reviews, generatedScores, config.reviewMass);
4580
+ applyReading(reviews, mass);
4581
+ noteReviewPressure(this.course.getCourseID(), {
4582
+ mass: mass.urgency,
4583
+ healthyMass: config.reviewMass.healthyMass,
4584
+ rate: config.reviewMass.rate,
4585
+ multiplier: mass.multiplier
4586
+ });
4587
+ const now = Date.now();
4588
+ const clock = await this.loadIntakeClock(now);
4589
+ const stepped = stepIntakeClock(clock, now, eligibleNew.length);
4590
+ if (stepped !== clock) this.saveIntakeClock(stepped);
4591
+ const intake = intakeReading(
4592
+ stepped,
4593
+ now,
4594
+ { eligibleNew: eligibleNew.length, newCandidates: newCards.length },
4595
+ config.intake
4596
+ );
4597
+ applyReading(eligibleNew, intake);
4598
+ logger.info(
4599
+ `[Pipeline:regulators] review mass ${mass.urgency.toFixed(1)} over ${reviews.length} due \u2192 \xD7${mass.multiplier.toFixed(2)}; intake ${intake.urgency.toFixed(1)}h, ${eligibleNew.length}/${newCards.length} new eligible \u2192 \xD7${intake.multiplier.toFixed(2)}`
4600
+ );
4601
+ return [mass, intake];
4602
+ }
4603
+ /**
4604
+ * A card was presented. A new card's first presentation discharges the
4605
+ * intake valve: its clock restarts. Called by the SessionController.
4606
+ */
4607
+ notePresented(card) {
4608
+ if (card.status !== "new" || card.courseId !== this.course?.getCourseID()) return;
4609
+ this.saveIntakeClock(resetIntakeClock(Date.now()));
4610
+ }
4611
+ async loadIntakeClock(nowMs) {
4612
+ if (this._intakeClock) return this._intakeClock;
4613
+ let stored = null;
4614
+ try {
4615
+ stored = await this.user.getStrategyState(
4616
+ this.course.getCourseID(),
4617
+ INTAKE_CLOCK_KEY
4618
+ );
4619
+ } catch (e) {
4620
+ logger.warn(`[Pipeline:regulators] Could not read the intake clock: ${e}`);
4621
+ }
4622
+ if (stored) {
4623
+ this._intakeClock = stored;
4624
+ } else {
4625
+ this.saveIntakeClock(resetIntakeClock(nowMs));
4626
+ }
4627
+ return this._intakeClock;
4628
+ }
4629
+ saveIntakeClock(state) {
4630
+ this._intakeClock = state;
4631
+ const courseId = this.course.getCourseID();
4632
+ this._intakeClockWrite = this._intakeClockWrite.then(() => this.user.putStrategyState(courseId, INTAKE_CLOCK_KEY, state)).catch((e) => logger.warn(`[Pipeline:regulators] Could not save the intake clock: ${e}`));
4633
+ }
4368
4634
  /**
4369
4635
  * Build shared context for generator and filters.
4370
4636
  *
@@ -4375,10 +4641,11 @@ var init_Pipeline = __esm({
4375
4641
  */
4376
4642
  async buildContext() {
4377
4643
  let userElo = 1e3;
4644
+ let userCourseElo;
4378
4645
  try {
4379
4646
  const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
4380
- const courseElo = toCourseElo5(courseReg.elo);
4381
- userElo = courseElo.global.score;
4647
+ userCourseElo = toCourseElo5(courseReg.elo);
4648
+ userElo = userCourseElo.global.score;
4382
4649
  } catch (e) {
4383
4650
  logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
4384
4651
  }
@@ -4390,6 +4657,7 @@ var init_Pipeline = __esm({
4390
4657
  user: this.user,
4391
4658
  course: this.course,
4392
4659
  userElo,
4660
+ ...userCourseElo ? { userCourseElo } : {},
4393
4661
  orchestration
4394
4662
  };
4395
4663
  }
@@ -4503,7 +4771,7 @@ var init_Pipeline = __esm({
4503
4771
  cards = await this.hydrateTags(cards);
4504
4772
  const fullPool = cards.slice();
4505
4773
  const context = await this.buildContext();
4506
- for (const filter of this.filters) {
4774
+ for (const filter of this.forecastFilters()) {
4507
4775
  cards = await filter.transform(cards, context);
4508
4776
  }
4509
4777
  if (opts?.hints) {
@@ -4522,6 +4790,14 @@ var init_Pipeline = __esm({
4522
4790
  cards.sort((a, b) => b.score - a.score);
4523
4791
  return opts?.limit ? cards.slice(0, opts.limit) : cards;
4524
4792
  }
4793
+ /**
4794
+ * The filters a forecast or card-space scan applies. Those start every card at
4795
+ * 1.0 without a generator, so they skip `liveOnly` filters (ELO distance),
4796
+ * which only make sense against generator scores.
4797
+ */
4798
+ forecastFilters() {
4799
+ return this.filters.filter((f) => !f.liveOnly);
4800
+ }
4525
4801
  /**
4526
4802
  * Scan every card in the course through the filter chain and report
4527
4803
  * how many are "well indicated" (score >= threshold) for the current user.
@@ -4543,7 +4819,7 @@ var init_Pipeline = __esm({
4543
4819
  cards = await this.hydrateTags(cards);
4544
4820
  const context = await this.buildContext();
4545
4821
  const filterBreakdown = [];
4546
- for (const filter of this.filters) {
4822
+ for (const filter of this.forecastFilters()) {
4547
4823
  cards = await filter.transform(cards, context);
4548
4824
  const wi = cards.filter((c) => c.score >= THRESHOLD).length;
4549
4825
  filterBreakdown.push({ name: filter.name, wellIndicated: wi });
@@ -4607,6 +4883,7 @@ var init_Pipeline = __esm({
4607
4883
  // src/core/navigators/defaults.ts
4608
4884
  var defaults_exports = {};
4609
4885
  __export(defaults_exports, {
4886
+ createDefaultEloDistanceStrategy: () => createDefaultEloDistanceStrategy,
4610
4887
  createDefaultEloStrategy: () => createDefaultEloStrategy,
4611
4888
  createDefaultPipeline: () => createDefaultPipeline,
4612
4889
  createDefaultSrsStrategy: () => createDefaultSrsStrategy
@@ -4633,12 +4910,28 @@ function createDefaultSrsStrategy(courseId) {
4633
4910
  serializedData: ""
4634
4911
  };
4635
4912
  }
4913
+ function createDefaultEloDistanceStrategy(courseId) {
4914
+ return {
4915
+ _id: "NAVIGATION_STRATEGY-eloDistance-default",
4916
+ docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
4917
+ name: "ELO Distance (default)",
4918
+ description: "Scales every candidate, new or review, by its distance from the learner's ELO",
4919
+ implementingClass: "eloDistance" /* ELO_DISTANCE */,
4920
+ course: courseId,
4921
+ // Explicit, though the filter would default to it anyway: views show what runs.
4922
+ serializedData: JSON.stringify(DEFAULT_ELO_DISTANCE_CONFIG)
4923
+ };
4924
+ }
4636
4925
  function createDefaultPipeline(user, course) {
4637
4926
  const courseId = course.getCourseID();
4638
4927
  const eloNavigator = new ELONavigator(user, course, createDefaultEloStrategy(courseId));
4639
4928
  const srsNavigator = new SRSNavigator(user, course, createDefaultSrsStrategy(courseId));
4640
4929
  const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
4641
- const eloDistanceFilter = createEloDistanceFilter();
4930
+ const eloDistanceFilter = new EloDistanceFilter(
4931
+ user,
4932
+ course,
4933
+ createDefaultEloDistanceStrategy(courseId)
4934
+ );
4642
4935
  return new Pipeline(compositeGenerator, [eloDistanceFilter], user, course);
4643
4936
  }
4644
4937
  var init_defaults = __esm({
@@ -4654,6 +4947,131 @@ var init_defaults = __esm({
4654
4947
  }
4655
4948
  });
4656
4949
 
4950
+ // src/core/navigators/pipelinePlan.ts
4951
+ var pipelinePlan_exports = {};
4952
+ __export(pipelinePlan_exports, {
4953
+ PIPELINE_STAGES: () => PIPELINE_STAGES,
4954
+ planPipeline: () => planPipeline
4955
+ });
4956
+ function planned(strategy, role, origin) {
4957
+ const kind = role === "filter" /* FILTER */ ? getRegisteredFilterKind(strategy.implementingClass) : void 0;
4958
+ return {
4959
+ role,
4960
+ origin,
4961
+ name: strategy.name,
4962
+ implementingClass: strategy.implementingClass,
4963
+ strategy,
4964
+ ...kind ? { kind } : {}
4965
+ };
4966
+ }
4967
+ function planPipeline(strategies, courseId) {
4968
+ if (strategies.length === 0) {
4969
+ return {
4970
+ kind: "default",
4971
+ generators: [
4972
+ planned(createDefaultEloStrategy(courseId), "generator" /* GENERATOR */, "default-pipeline"),
4973
+ planned(createDefaultSrsStrategy(courseId), "generator" /* GENERATOR */, "default-pipeline")
4974
+ ],
4975
+ filters: [
4976
+ planned(
4977
+ createDefaultEloDistanceStrategy(courseId),
4978
+ "filter" /* FILTER */,
4979
+ "default-pipeline"
4980
+ )
4981
+ ],
4982
+ skipped: [],
4983
+ warnings: [],
4984
+ notes: [],
4985
+ regulators: DEFAULT_REGULATOR_CONFIG
4986
+ };
4987
+ }
4988
+ const generators = [];
4989
+ const filters = [];
4990
+ const skipped = [];
4991
+ const warnings = [];
4992
+ for (const s of strategies) {
4993
+ if (isGenerator(s.implementingClass)) {
4994
+ generators.push(planned(s, "generator" /* GENERATOR */, "strategy-doc"));
4995
+ } else if (isFilter(s.implementingClass)) {
4996
+ filters.push(planned(s, "filter" /* FILTER */, "strategy-doc"));
4997
+ } else {
4998
+ skipped.push({ strategy: s, reason: "not a registered generator or filter" });
4999
+ warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
5000
+ }
5001
+ }
5002
+ const declared = new Set(generators.map((g) => g.implementingClass));
5003
+ if (!declared.has(createDefaultEloStrategy(courseId).implementingClass)) {
5004
+ generators.push(
5005
+ planned(createDefaultEloStrategy(courseId), "generator" /* GENERATOR */, "assembler-default")
5006
+ );
5007
+ }
5008
+ if (!declared.has(createDefaultSrsStrategy(courseId).implementingClass)) {
5009
+ generators.push(
5010
+ planned(createDefaultSrsStrategy(courseId), "generator" /* GENERATOR */, "assembler-default")
5011
+ );
5012
+ }
5013
+ const eloDistance = createDefaultEloDistanceStrategy(courseId);
5014
+ if (!filters.some((f) => f.implementingClass === eloDistance.implementingClass)) {
5015
+ filters.push(planned(eloDistance, "filter" /* FILTER */, "assembler-default"));
5016
+ }
5017
+ filters.sort((a, b) => a.name.localeCompare(b.name));
5018
+ return {
5019
+ kind: "assembled",
5020
+ generators,
5021
+ filters,
5022
+ skipped,
5023
+ warnings,
5024
+ notes: [],
5025
+ regulators: DEFAULT_REGULATOR_CONFIG
5026
+ };
5027
+ }
5028
+ var PIPELINE_STAGES;
5029
+ var init_pipelinePlan = __esm({
5030
+ "src/core/navigators/pipelinePlan.ts"() {
5031
+ "use strict";
5032
+ init_navigators();
5033
+ init_regulators();
5034
+ init_defaults();
5035
+ PIPELINE_STAGES = [
5036
+ {
5037
+ key: "generate",
5038
+ title: "Generate",
5039
+ summary: "Each generator proposes candidates (up to 500 in all), scored on what is specific to its source. A card proposed by several generators keeps their mean score, raised 10% per extra generator."
5040
+ },
5041
+ {
5042
+ key: "filter",
5043
+ title: "Filter",
5044
+ summary: "Each filter multiplies candidate scores, in the order shown. A gate says a card is not ready yet; a signal expresses preference. Gates usually penalize rather than remove, so a gated card stays in the pool at a low score."
5045
+ },
5046
+ {
5047
+ key: "drop-zero",
5048
+ title: "Drop zero scores",
5049
+ summary: "Candidates whose score reached 0 leave the pool."
5050
+ },
5051
+ {
5052
+ key: "regulate",
5053
+ title: "Regulate",
5054
+ summary: "Balances reviews against new cards. Review mass: the due reviews weighed by their filtered scores; above a healthy level, every review is lifted. Intake: hours since a new card was last presented; new cards no gate penalized are lifted, and the clock stops while there are none."
5055
+ },
5056
+ {
5057
+ key: "hints",
5058
+ title: "Apply hints",
5059
+ summary: "The session's hints (from the app: an intro's follow-up, a difficulty boost) exclude, boost, or require cards. Required cards skip the filters entirely."
5060
+ },
5061
+ {
5062
+ key: "diversity",
5063
+ title: "Diversity re-rank",
5064
+ summary: "Demotes candidates that repeat a distinctive tag already ranked above them, so one concept or answer cannot take the whole head of the queue. Sees this run only, not what the session already served."
5065
+ },
5066
+ {
5067
+ key: "select",
5068
+ title: "Select",
5069
+ summary: "Highest scores first, up to the run's limit. The session mixes them into its supply queue."
5070
+ }
5071
+ ];
5072
+ }
5073
+ });
5074
+
4657
5075
  // src/core/navigators/PipelineAssembler.ts
4658
5076
  var PipelineAssembler_exports = {};
4659
5077
  __export(PipelineAssembler_exports, {
@@ -4668,16 +5086,16 @@ var init_PipelineAssembler = __esm({
4668
5086
  init_Pipeline();
4669
5087
  init_logger();
4670
5088
  init_CompositeGenerator();
4671
- init_defaults();
5089
+ init_pipelinePlan();
4672
5090
  PipelineAssembler = class {
4673
5091
  /**
4674
5092
  * Assembles a navigation pipeline from strategy documents.
4675
5093
  *
4676
- * 1. Separates into generators and filters by role
4677
- * 2. Validates at least one generator exists (or creates default ELO)
4678
- * 3. Instantiates generators - wraps multiple in CompositeGenerator
4679
- * 4. Instantiates filters
4680
- * 5. Returns Pipeline(generator, filters)
5094
+ * 1. Plans: classifies by role, adds default ELO/SRS and ELO distance, orders filters
5095
+ * (`planPipeline`)
5096
+ * 2. Instantiates generators - wraps multiple in CompositeGenerator
5097
+ * 3. Instantiates filters
5098
+ * 4. Returns Pipeline(generator, filters)
4681
5099
  *
4682
5100
  * @param input - Strategy documents plus user/course interfaces
4683
5101
  * @returns Assembled pipeline and any warnings
@@ -4693,28 +5111,17 @@ var init_PipelineAssembler = __esm({
4693
5111
  warnings
4694
5112
  };
4695
5113
  }
4696
- const generatorStrategies = [];
4697
- const filterStrategies = [];
4698
- for (const s of strategies) {
4699
- if (isGenerator(s.implementingClass)) {
4700
- generatorStrategies.push(s);
4701
- } else if (isFilter(s.implementingClass)) {
4702
- filterStrategies.push(s);
4703
- } else {
4704
- warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
5114
+ const plan = planPipeline(strategies, course.getCourseID());
5115
+ warnings.push(...plan.warnings);
5116
+ for (const n of [...plan.generators, ...plan.filters]) {
5117
+ if (n.origin === "assembler-default") {
5118
+ logger.debug(
5119
+ `[PipelineAssembler] No ${n.implementingClass} ${n.role} configured, adding default`
5120
+ );
4705
5121
  }
4706
5122
  }
4707
- const courseId = course.getCourseID();
4708
- const hasElo = generatorStrategies.some((s) => s.implementingClass === "elo" /* ELO */);
4709
- const hasSrs = generatorStrategies.some((s) => s.implementingClass === "srs" /* SRS */);
4710
- if (!hasElo) {
4711
- logger.debug("[PipelineAssembler] No ELO generator configured, adding default");
4712
- generatorStrategies.push(createDefaultEloStrategy(courseId));
4713
- }
4714
- if (!hasSrs) {
4715
- logger.debug("[PipelineAssembler] No SRS generator configured, adding default");
4716
- generatorStrategies.push(createDefaultSrsStrategy(courseId));
4717
- }
5123
+ const generatorStrategies = plan.generators.map((g) => g.strategy);
5124
+ const sortedFilterStrategies = plan.filters.map((f) => f.strategy);
4718
5125
  if (generatorStrategies.length === 0) {
4719
5126
  warnings.push("No generator strategy found");
4720
5127
  return {
@@ -4736,9 +5143,6 @@ var init_PipelineAssembler = __esm({
4736
5143
  generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
4737
5144
  }
4738
5145
  const filters = [];
4739
- const sortedFilterStrategies = [...filterStrategies].sort(
4740
- (a, b) => a.name.localeCompare(b.name)
4741
- );
4742
5146
  for (const filterStrategy of sortedFilterStrategies) {
4743
5147
  try {
4744
5148
  const nav = await ContentNavigator.create(user, course, filterStrategy);
@@ -4806,7 +5210,9 @@ var init_3 = __esm({
4806
5210
  "./generators/prescribed.ts": () => Promise.resolve().then(() => (init_prescribed(), prescribed_exports)),
4807
5211
  "./generators/srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
4808
5212
  "./generators/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
4809
- "./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports))
5213
+ "./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
5214
+ "./pipelinePlan.ts": () => Promise.resolve().then(() => (init_pipelinePlan(), pipelinePlan_exports)),
5215
+ "./regulators.ts": () => Promise.resolve().then(() => (init_regulators(), regulators_exports))
4810
5216
  });
4811
5217
  }
4812
5218
  });
@@ -4827,6 +5233,7 @@ __export(navigators_exports, {
4827
5233
  drainCapturedRuns: () => drainCapturedRuns,
4828
5234
  getActivePipeline: () => getActivePipeline,
4829
5235
  getCardOrigin: () => getCardOrigin,
5236
+ getRegisteredFilterKind: () => getRegisteredFilterKind,
4830
5237
  getRegisteredNavigator: () => getRegisteredNavigator,
4831
5238
  getRegisteredNavigatorNames: () => getRegisteredNavigatorNames,
4832
5239
  getRegisteredNavigatorRole: () => getRegisteredNavigatorRole,
@@ -4855,6 +5262,10 @@ function hasRegisteredNavigator(implementingClass) {
4855
5262
  function getRegisteredNavigatorRole(implementingClass) {
4856
5263
  return navigatorRegistry.get(implementingClass)?.role;
4857
5264
  }
5265
+ function getRegisteredFilterKind(implementingClass) {
5266
+ const ctor = navigatorRegistry.get(implementingClass)?.constructor;
5267
+ return ctor?.kind;
5268
+ }
4858
5269
  function getRegisteredNavigatorNames() {
4859
5270
  return Array.from(navigatorRegistry.keys());
4860
5271
  }
@@ -4872,17 +5283,20 @@ async function initializeNavigatorRegistry() {
4872
5283
  hierarchyModule,
4873
5284
  interferenceModule,
4874
5285
  relativePriorityModule,
4875
- userTagPreferenceModule
5286
+ userTagPreferenceModule,
5287
+ eloDistanceModule
4876
5288
  ] = await Promise.all([
4877
5289
  Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
4878
5290
  Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
4879
5291
  Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
4880
- Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports))
5292
+ Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
5293
+ Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports))
4881
5294
  ]);
4882
5295
  registerNavigator("hierarchyDefinition", hierarchyModule.default);
4883
5296
  registerNavigator("interferenceMitigator", interferenceModule.default);
4884
5297
  registerNavigator("relativePriority", relativePriorityModule.default);
4885
5298
  registerNavigator("userTagPreference", userTagPreferenceModule.default);
5299
+ registerNavigator("eloDistance", eloDistanceModule.default);
4886
5300
  logger.debug(
4887
5301
  `[NavigatorRegistry] Initialized ${navigatorRegistry.size} navigators: ${getRegisteredNavigatorNames().join(", ")}`
4888
5302
  );
@@ -4930,6 +5344,7 @@ var init_navigators = __esm({
4930
5344
  Navigators2["INTERFERENCE"] = "interferenceMitigator";
4931
5345
  Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
4932
5346
  Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
5347
+ Navigators2["ELO_DISTANCE"] = "eloDistance";
4933
5348
  return Navigators2;
4934
5349
  })(Navigators || {});
4935
5350
  NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
@@ -4944,7 +5359,8 @@ var init_navigators = __esm({
4944
5359
  ["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
4945
5360
  ["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
4946
5361
  ["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
4947
- ["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
5362
+ ["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */,
5363
+ ["eloDistance" /* ELO_DISTANCE */]: "filter" /* FILTER */
4948
5364
  };
4949
5365
  ContentNavigator = class {
4950
5366
  /** User interface for this navigation session */
@@ -6793,10 +7209,11 @@ function backlogHtml(backlog) {
6793
7209
  const rows = backlog.map((b) => {
6794
7210
  const hot = b.backlogMultiplier >= 3;
6795
7211
  const multColor = b.backlogMultiplier <= 1 ? "#86efac" : hot ? "#fca5a5" : "#fcd34d";
6796
- const headroom = b.backlogMultiplier > 1 ? `climbing (\xD7${b.backlogGrowthRate.toFixed(2)} per ${b.healthyBacklog}-review excess, unbounded)` : "healthy \u2014 no pressure";
7212
+ const headroom = b.backlogMultiplier > 1 ? `climbing (\xD7${b.backlogGrowthRate.toFixed(2)} per ${b.healthyBacklog} of mass in excess, unbounded)` : "healthy \u2014 no pressure";
7213
+ const mass = b.reviewMass !== null ? ` \xB7 mass ${b.reviewMass.toFixed(1)}` : "";
6797
7214
  const top = b.topReviewScore !== null ? b.topReviewScore.toFixed(2) : "\u2014";
6798
7215
  const next = b.nextDueIn ? ` <span style="opacity:.6">\xB7 next due ${esc(b.nextDueIn)}</span>` : "";
6799
- return `<div style="margin-left:6px"><span style="opacity:.7">${esc(b.courseId.slice(0, 8))}</span> due ${b.dueNow}/${b.scheduledTotal} <span style="opacity:.6">(healthy ${b.healthyBacklog})</span>${next}<div style="margin-left:6px">pressure <span style="color:${multColor}">\xD7${b.backlogMultiplier.toFixed(2)}</span> <span style="opacity:.6">${headroom} \xB7 top review ${top}</span></div></div>`;
7216
+ return `<div style="margin-left:6px"><span style="opacity:.7">${esc(b.courseId.slice(0, 8))}</span> due ${b.dueNow}/${b.scheduledTotal}${mass} <span style="opacity:.6">(healthy mass ${b.healthyBacklog})</span>${next}<div style="margin-left:6px">pressure <span style="color:${multColor}">\xD7${b.backlogMultiplier.toFixed(2)}</span> <span style="opacity:.6">${headroom} \xB7 top review ${top}</span></div></div>`;
6800
7217
  }).join("");
6801
7218
  return `<div style="margin-bottom:6px"><div style="color:#93c5fd">review backpressure</div>${rows}</div>`;
6802
7219
  }
@@ -6935,8 +7352,9 @@ function snapshotToText(s) {
6935
7352
  const headroom = b.backlogMultiplier > 1 ? "climbing" : "healthy";
6936
7353
  const top = b.topReviewScore !== null ? b.topReviewScore.toFixed(2) : "\u2014";
6937
7354
  const next = b.nextDueIn ? `, next due ${b.nextDueIn}` : "";
7355
+ const mass = b.reviewMass !== null ? `, mass ${b.reviewMass.toFixed(1)}` : "";
6938
7356
  lines.push(
6939
- ` ${b.courseId.slice(0, 8)}: due ${b.dueNow}/${b.scheduledTotal} (healthy ${b.healthyBacklog})${next}; pressure \xD7${b.backlogMultiplier.toFixed(2)} ${headroom}; top review ${top}`
7357
+ ` ${b.courseId.slice(0, 8)}: due ${b.dueNow}/${b.scheduledTotal}${mass} (healthy mass ${b.healthyBacklog})${next}; pressure \xD7${b.backlogMultiplier.toFixed(2)} ${headroom}; top review ${top}`
6940
7358
  );
6941
7359
  }
6942
7360
  }
@@ -9958,6 +10376,11 @@ var init_courseDB3 = __esm({
9958
10376
  setEphemeralHints(hints) {
9959
10377
  this._pendingHints = hints;
9960
10378
  }
10379
+ /** Forward a presentation to the navigator (a new card restarts its intake clock). */
10380
+ notePresented(card) {
10381
+ if (card.status !== "new") return;
10382
+ void this.createNavigator(this.userDB).then((navigator2) => navigator2.notePresented?.(card)).catch((e) => logger.warn(`[static/courseDB] Could not note a presentation: ${e}`));
10383
+ }
9961
10384
  async getWeightedCards(limit) {
9962
10385
  try {
9963
10386
  const navigator2 = await this.createNavigator(this.userDB);
@@ -10200,12 +10623,6 @@ var init_StaticDataLayerProvider = __esm({
10200
10623
  getAdminDB() {
10201
10624
  throw new Error("Admin functions not supported in static mode");
10202
10625
  }
10203
- async createUserReaderForUser(targetUsername) {
10204
- logger.warn(`StaticDataLayerProvider: Multi-user access not supported in static mode`);
10205
- logger.warn(`Request: trying to access data for ${targetUsername}`);
10206
- logger.warn(`Returning current user's data instead`);
10207
- return this.getUserDB();
10208
- }
10209
10626
  isReadOnly() {
10210
10627
  return true;
10211
10628
  }