@vue-skuilder/db 0.1.30 → 0.1.31-b

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.1.30",
7
+ "version": "0.1.31-b",
8
8
  "description": "Database layer for vue-skuilder",
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/index.mjs",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@nilock2/pouchdb-authentication": "^1.0.2",
51
- "@vue-skuilder/common": "0.1.30",
51
+ "@vue-skuilder/common": "0.1.31-b",
52
52
  "cross-fetch": "^4.1.0",
53
53
  "moment": "^2.29.4",
54
54
  "pouchdb": "^9.0.0",
@@ -1,4 +1,12 @@
1
1
  import type { WeightedCard, StrategyContribution } from './index';
2
+ import {
3
+ getRegisteredNavigatorNames,
4
+ getRegisteredNavigatorRole,
5
+ NavigatorRoles,
6
+ type Navigators,
7
+ isGenerator,
8
+ isFilter,
9
+ } from './index';
2
10
  import { logger } from '../../util/logger';
3
11
 
4
12
  // ============================================================================
@@ -381,6 +389,76 @@ export const pipelineDebugAPI = {
381
389
  logger.info('[Pipeline Debug] Run history cleared.');
382
390
  },
383
391
 
392
+ /**
393
+ * Show the navigator registry: all registered classes and their roles.
394
+ *
395
+ * Useful for verifying that consumer-defined navigators were registered
396
+ * before pipeline assembly.
397
+ */
398
+ showRegistry(): void {
399
+ const names = getRegisteredNavigatorNames();
400
+ if (names.length === 0) {
401
+ logger.info('[Pipeline Debug] Navigator registry is empty.');
402
+ return;
403
+ }
404
+
405
+ // eslint-disable-next-line no-console
406
+ console.group('📦 Navigator Registry');
407
+ // eslint-disable-next-line no-console
408
+ console.table(
409
+ names.map((name) => {
410
+ const registryRole = getRegisteredNavigatorRole(name);
411
+ const builtinRole = NavigatorRoles[name as Navigators];
412
+ const effectiveRole = builtinRole || registryRole || '⚠️ NONE';
413
+ const source = builtinRole ? 'built-in' : registryRole ? 'consumer' : 'unclassified';
414
+ return {
415
+ name,
416
+ role: effectiveRole,
417
+ source,
418
+ isGenerator: isGenerator(name),
419
+ isFilter: isFilter(name),
420
+ };
421
+ })
422
+ );
423
+ // eslint-disable-next-line no-console
424
+ console.groupEnd();
425
+ },
426
+
427
+ /**
428
+ * Show strategy documents from the last pipeline run and how they mapped
429
+ * to the registry.
430
+ *
431
+ * If no runs are captured yet, falls back to showing just the registry.
432
+ */
433
+ showStrategies(): void {
434
+ this.showRegistry();
435
+
436
+ if (runHistory.length === 0) {
437
+ logger.info('[Pipeline Debug] No pipeline runs captured yet — cannot show strategy doc mapping.');
438
+ return;
439
+ }
440
+
441
+ const run = runHistory[0];
442
+ // eslint-disable-next-line no-console
443
+ console.group('🔌 Pipeline Strategy Mapping (last run)');
444
+ logger.info(`Generator: ${run.generatorName}`);
445
+ if (run.generators && run.generators.length > 0) {
446
+ for (const g of run.generators) {
447
+ logger.info(` 📥 ${g.name}: ${g.cardCount} cards (${g.newCount} new, ${g.reviewCount} reviews)`);
448
+ }
449
+ }
450
+ if (run.filters.length > 0) {
451
+ logger.info('Filters:');
452
+ for (const f of run.filters) {
453
+ logger.info(` 🔸 ${f.name}: ↑${f.boosted} ↓${f.penalized} =${f.passed} ✕${f.removed}`);
454
+ }
455
+ } else {
456
+ logger.info('Filters: (none)');
457
+ }
458
+ // eslint-disable-next-line no-console
459
+ console.groupEnd();
460
+ },
461
+
384
462
  /**
385
463
  * Show help.
386
464
  */
@@ -393,6 +471,8 @@ Commands:
393
471
  .showRun(id|index) Show summary of a specific run (by index or ID suffix)
394
472
  .showCard(cardId) Show provenance trail for a specific card
395
473
  .explainReviews() Analyze why reviews were/weren't selected
474
+ .showRegistry() Show navigator registry (classes + roles)
475
+ .showStrategies() Show registry + strategy mapping from last run
396
476
  .listRuns() List all captured runs in table format
397
477
  .export() Export run history as JSON for bug reports
398
478
  .clear() Clear run history
@@ -88,30 +88,41 @@ export default class ELONavigator extends ContentNavigator implements CardGenera
88
88
  const cardIds = newCards.map((c) => c.cardID);
89
89
  const cardEloData = await this.course.getCardEloData(cardIds);
90
90
 
91
- // Score new cards by ELO distance
91
+ // Score new cards by ELO distance, then apply weighted sampling without
92
+ // replacement using the Efraimidis-Spirakis (A-Res) algorithm:
93
+ //
94
+ // key = U ^ (1 / rawScore) where U ~ Uniform(0, 1)
95
+ //
96
+ // Sorting by key descending produces a weighted random sample: high-score
97
+ // cards are still preferred, but cards with equal scores are shuffled
98
+ // uniformly rather than deterministically. This prevents the same failed
99
+ // cards from looping back every session when many cards share similar ELO.
100
+ //
101
+ // Edge case: rawScore=0 → key=0, never selected (correct exclusion).
92
102
  const scored: WeightedCard[] = newCards.map((c, i) => {
93
103
  const cardElo = cardEloData[i]?.global?.score ?? 1000;
94
104
  const distance = Math.abs(cardElo - userGlobalElo);
95
- const score = Math.max(0, 1 - distance / 500);
105
+ const rawScore = Math.max(0, 1 - distance / 500);
106
+ const samplingKey = rawScore > 0 ? Math.random() ** (1 / rawScore) : 0;
96
107
 
97
108
  return {
98
109
  cardId: c.cardID,
99
110
  courseId: c.courseID,
100
- score,
111
+ score: samplingKey,
101
112
  provenance: [
102
113
  {
103
114
  strategy: 'elo',
104
115
  strategyName: this.strategyName || this.name,
105
116
  strategyId: this.strategyId || 'NAVIGATION_STRATEGY-ELO-default',
106
117
  action: 'generated',
107
- score,
108
- reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`,
118
+ score: samplingKey,
119
+ reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), raw ${rawScore.toFixed(3)}, key ${samplingKey.toFixed(3)}`,
109
120
  },
110
121
  ],
111
122
  };
112
123
  });
113
124
 
114
- // Sort by score descending
125
+ // Sort by sampling key descending (weighted sample without replacement)
115
126
  scored.sort((a, b) => b.score - a.score);
116
127
 
117
128
  const result = scored.slice(0, limit);
@@ -2,6 +2,7 @@ import { CardHistory, CardRecord, QuestionRecord } from '@db/core/types/types-le
2
2
  import { areQuestionRecords } from '@db/core/util';
3
3
  import { Update } from '@db/impl/couch/updateQueue';
4
4
  import moment from 'moment';
5
+ import { isTaggedPerformance } from '@vue-skuilder/common';
5
6
  import { logger } from '../util/logger';
6
7
 
7
8
  type Moment = moment.Moment;
@@ -39,7 +40,9 @@ function newQuestionInterval(user: DocumentUpdater, cardHistory: CardHistory<Que
39
40
  }
40
41
 
41
42
  if (currentAttempt.isCorrect) {
42
- const skill = Math.min(1.0, Math.max(0.0, currentAttempt.performance as number));
43
+ const rawPerf = currentAttempt.performance;
44
+ const numericPerf = isTaggedPerformance(rawPerf) ? rawPerf._global : rawPerf;
45
+ const skill = Math.min(1.0, Math.max(0.0, numericPerf));
43
46
  logger.debug(`Demontrated skill: \t${skill}`);
44
47
  const interval: number = lastInterval * (0.75 + skill);
45
48
  cardHistory.lapses = getLapses(cardHistory.records);