@vue-skuilder/db 0.2.34 → 0.2.36

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 (262) hide show
  1. package/CLAUDE.md +15 -4
  2. package/build.entries.mjs +12 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  4. package/dist/{contentSource-CTQ4kWhR.d.cts → contentSource-D_E7JaxR.d.ts} +2 -2
  5. package/dist/core/UserDBDebugger.mjs +285 -0
  6. package/dist/core/UserDBDebugger.mjs.map +1 -0
  7. package/dist/core/bulkImport/cardProcessor.mjs +106 -0
  8. package/dist/core/bulkImport/cardProcessor.mjs.map +1 -0
  9. package/dist/core/{index.js → index.cjs} +6438 -7784
  10. package/dist/core/index.cjs.map +1 -0
  11. package/dist/core/index.d.ts +5 -5
  12. package/dist/core/index.mjs +20 -11368
  13. package/dist/core/interfaces/contentSource.mjs +20 -0
  14. package/dist/core/interfaces/contentSource.mjs.map +1 -0
  15. package/dist/core/navigators/Pipeline.mjs +723 -0
  16. package/dist/core/navigators/Pipeline.mjs.map +1 -0
  17. package/dist/core/navigators/PipelineAssembler.mjs +86 -0
  18. package/dist/core/navigators/PipelineAssembler.mjs.map +1 -0
  19. package/dist/core/navigators/PipelineDebugger.mjs +771 -0
  20. package/dist/core/navigators/PipelineDebugger.mjs.map +1 -0
  21. package/dist/core/navigators/SrsDebugger.mjs +34 -0
  22. package/dist/core/navigators/SrsDebugger.mjs.map +1 -0
  23. package/dist/core/navigators/StrategyPressureDebugger.mjs +19 -0
  24. package/dist/core/navigators/StrategyPressureDebugger.mjs.map +1 -0
  25. package/dist/core/navigators/defaults.mjs +96 -0
  26. package/dist/core/navigators/defaults.mjs.map +1 -0
  27. package/dist/core/navigators/diversityRerank.mjs +85 -0
  28. package/dist/core/navigators/diversityRerank.mjs.map +1 -0
  29. package/dist/core/navigators/filters/WeightedFilter.mjs +81 -0
  30. package/dist/core/navigators/filters/WeightedFilter.mjs.map +1 -0
  31. package/dist/core/navigators/filters/eloDistance.mjs +244 -0
  32. package/dist/core/navigators/filters/eloDistance.mjs.map +1 -0
  33. package/dist/core/navigators/filters/hierarchyDefinition.mjs +235 -0
  34. package/dist/core/navigators/filters/hierarchyDefinition.mjs.map +1 -0
  35. package/dist/core/navigators/filters/interferenceMitigator.mjs +201 -0
  36. package/dist/core/navigators/filters/interferenceMitigator.mjs.map +1 -0
  37. package/dist/core/navigators/filters/relativePriority.mjs +135 -0
  38. package/dist/core/navigators/filters/relativePriority.mjs.map +1 -0
  39. package/dist/core/navigators/filters/userTagPreference.mjs +101 -0
  40. package/dist/core/navigators/filters/userTagPreference.mjs.map +1 -0
  41. package/dist/core/navigators/generators/CompositeGenerator.mjs +203 -0
  42. package/dist/core/navigators/generators/CompositeGenerator.mjs.map +1 -0
  43. package/dist/core/navigators/generators/elo.mjs +77 -0
  44. package/dist/core/navigators/generators/elo.mjs.map +1 -0
  45. package/dist/core/navigators/generators/prescribed.mjs +676 -0
  46. package/dist/core/navigators/generators/prescribed.mjs.map +1 -0
  47. package/dist/core/navigators/generators/srs.mjs +158 -0
  48. package/dist/core/navigators/generators/srs.mjs.map +1 -0
  49. package/dist/core/navigators/index.mjs +345 -0
  50. package/dist/core/navigators/index.mjs.map +1 -0
  51. package/dist/core/navigators/pipelinePlan.mjs +109 -0
  52. package/dist/core/navigators/pipelinePlan.mjs.map +1 -0
  53. package/dist/core/navigators/regulators.mjs +128 -0
  54. package/dist/core/navigators/regulators.mjs.map +1 -0
  55. package/dist/core/orchestration/gradient.mjs +101 -0
  56. package/dist/core/orchestration/gradient.mjs.map +1 -0
  57. package/dist/core/orchestration/index.mjs +115 -0
  58. package/dist/core/orchestration/index.mjs.map +1 -0
  59. package/dist/core/orchestration/learning.mjs +140 -0
  60. package/dist/core/orchestration/learning.mjs.map +1 -0
  61. package/dist/core/orchestration/recording.mjs +64 -0
  62. package/dist/core/orchestration/recording.mjs.map +1 -0
  63. package/dist/core/orchestration/signal.mjs +40 -0
  64. package/dist/core/orchestration/signal.mjs.map +1 -0
  65. package/dist/core/types/contentNavigationStrategy.mjs +10 -0
  66. package/dist/core/types/contentNavigationStrategy.mjs.map +1 -0
  67. package/dist/core/types/hydration.mjs +13 -0
  68. package/dist/core/types/hydration.mjs.map +1 -0
  69. package/dist/core/types/strategyState.mjs +16 -0
  70. package/dist/core/types/strategyState.mjs.map +1 -0
  71. package/dist/core/types/studySession.mjs +14 -0
  72. package/dist/core/types/studySession.mjs.map +1 -0
  73. package/dist/core/types/types-legacy.mjs +44 -0
  74. package/dist/core/types/types-legacy.mjs.map +1 -0
  75. package/dist/core/util/index.mjs +31 -0
  76. package/dist/core/util/index.mjs.map +1 -0
  77. package/dist/core/versionStamps.mjs +46 -0
  78. package/dist/core/versionStamps.mjs.map +1 -0
  79. package/dist/courseConfigRegistration.mjs +306 -0
  80. package/dist/courseConfigRegistration.mjs.map +1 -0
  81. package/dist/{dataLayerProvider-rlLE2Mf-.d.ts → dataLayerProvider-BDshhSp_.d.ts} +1 -1
  82. package/dist/diagnostics/dataset.mjs +118 -0
  83. package/dist/diagnostics/dataset.mjs.map +1 -0
  84. package/dist/diagnostics/derive.mjs +318 -0
  85. package/dist/diagnostics/derive.mjs.map +1 -0
  86. package/dist/diagnostics/{index.js → index.cjs} +130 -1
  87. package/dist/diagnostics/index.cjs.map +1 -0
  88. package/dist/diagnostics/index.d.ts +108 -5
  89. package/dist/diagnostics/index.mjs +7 -914
  90. package/dist/diagnostics/loader.mjs +151 -0
  91. package/dist/diagnostics/loader.mjs.map +1 -0
  92. package/dist/diagnostics/pipeline.mjs +161 -0
  93. package/dist/diagnostics/pipeline.mjs.map +1 -0
  94. package/dist/diagnostics/tagElo.mjs +177 -0
  95. package/dist/diagnostics/tagElo.mjs.map +1 -0
  96. package/dist/diagnostics/text.mjs +174 -0
  97. package/dist/diagnostics/text.mjs.map +1 -0
  98. package/dist/factory.mjs +70 -0
  99. package/dist/factory.mjs.map +1 -0
  100. package/dist/impl/common/BaseUserDB.mjs +1103 -0
  101. package/dist/impl/common/BaseUserDB.mjs.map +1 -0
  102. package/dist/impl/common/userDBHelpers.mjs +49 -0
  103. package/dist/impl/common/userDBHelpers.mjs.map +1 -0
  104. package/dist/impl/common/userDBKeys.mjs +45 -0
  105. package/dist/impl/common/userDBKeys.mjs.map +1 -0
  106. package/dist/impl/couch/CouchDBSyncStrategy.mjs +272 -0
  107. package/dist/impl/couch/CouchDBSyncStrategy.mjs.map +1 -0
  108. package/dist/impl/couch/CourseSyncService.mjs +242 -0
  109. package/dist/impl/couch/CourseSyncService.mjs.map +1 -0
  110. package/dist/impl/couch/PouchDataLayerProvider.mjs +74 -0
  111. package/dist/impl/couch/PouchDataLayerProvider.mjs.map +1 -0
  112. package/dist/impl/couch/adminDB.mjs +61 -0
  113. package/dist/impl/couch/adminDB.mjs.map +1 -0
  114. package/dist/impl/couch/auth.mjs +33 -0
  115. package/dist/impl/couch/auth.mjs.map +1 -0
  116. package/dist/impl/couch/classroomDB.mjs +227 -0
  117. package/dist/impl/couch/classroomDB.mjs.map +1 -0
  118. package/dist/impl/couch/clientCache.mjs +15 -0
  119. package/dist/impl/couch/clientCache.mjs.map +1 -0
  120. package/dist/impl/couch/courseAPI.mjs +183 -0
  121. package/dist/impl/couch/courseAPI.mjs.map +1 -0
  122. package/dist/impl/couch/courseDB.mjs +729 -0
  123. package/dist/impl/couch/courseDB.mjs.map +1 -0
  124. package/dist/impl/couch/courseLookupDB.mjs +94 -0
  125. package/dist/impl/couch/courseLookupDB.mjs.map +1 -0
  126. package/dist/impl/couch/{index.js → index.cjs} +6911 -10367
  127. package/dist/impl/couch/index.cjs.map +1 -0
  128. package/dist/impl/couch/index.d.ts +12 -5
  129. package/dist/impl/couch/index.mjs +134 -12146
  130. package/dist/impl/couch/index.mjs.map +1 -1
  131. package/dist/impl/couch/pouchdb-setup.mjs +15 -0
  132. package/dist/impl/couch/pouchdb-setup.mjs.map +1 -0
  133. package/dist/impl/couch/updateQueue.mjs +101 -0
  134. package/dist/impl/couch/updateQueue.mjs.map +1 -0
  135. package/dist/impl/couch/user-course-relDB.mjs +55 -0
  136. package/dist/impl/couch/user-course-relDB.mjs.map +1 -0
  137. package/dist/impl/static/NoOpSyncStrategy.mjs +49 -0
  138. package/dist/impl/static/NoOpSyncStrategy.mjs.map +1 -0
  139. package/dist/impl/static/StaticDataLayerProvider.mjs +94 -0
  140. package/dist/impl/static/StaticDataLayerProvider.mjs.map +1 -0
  141. package/dist/impl/static/StaticDataUnpacker.mjs +311 -0
  142. package/dist/impl/static/StaticDataUnpacker.mjs.map +1 -0
  143. package/dist/impl/static/courseDB.mjs +368 -0
  144. package/dist/impl/static/courseDB.mjs.map +1 -0
  145. package/dist/impl/static/coursesDB.mjs +38 -0
  146. package/dist/impl/static/coursesDB.mjs.map +1 -0
  147. package/dist/impl/static/{index.js → index.cjs} +2461 -5992
  148. package/dist/impl/static/index.cjs.map +1 -0
  149. package/dist/impl/static/index.d.ts +4 -4
  150. package/dist/impl/static/index.mjs +6 -10741
  151. package/dist/{index-CVGehe_t.d.ts → index-BLDpFYG3.d.ts} +1 -1
  152. package/dist/{index.js → index.cjs} +14070 -14239
  153. package/dist/index.cjs.map +1 -0
  154. package/dist/index.d.ts +12 -23
  155. package/dist/index.mjs +38 -16937
  156. package/dist/pouch/{index.js → index.cjs} +5 -1
  157. package/dist/pouch/index.cjs.map +1 -0
  158. package/dist/pouch/index.mjs +2 -19
  159. package/dist/study/ItemQueue.mjs +95 -0
  160. package/dist/study/ItemQueue.mjs.map +1 -0
  161. package/dist/study/MixerDebugger.mjs +303 -0
  162. package/dist/study/MixerDebugger.mjs.map +1 -0
  163. package/dist/study/SessionController.mjs +1187 -0
  164. package/dist/study/SessionController.mjs.map +1 -0
  165. package/dist/study/SessionDebugger.mjs +271 -0
  166. package/dist/study/SessionDebugger.mjs.map +1 -0
  167. package/dist/study/SessionOverlay.mjs +407 -0
  168. package/dist/study/SessionOverlay.mjs.map +1 -0
  169. package/dist/study/SourceMixer.mjs +45 -0
  170. package/dist/study/SourceMixer.mjs.map +1 -0
  171. package/dist/study/SpacedRepetition.mjs +108 -0
  172. package/dist/study/SpacedRepetition.mjs.map +1 -0
  173. package/dist/study/TagFilteredContentSource.mjs +136 -0
  174. package/dist/study/TagFilteredContentSource.mjs.map +1 -0
  175. package/dist/study/services/CardHydrationService.mjs +172 -0
  176. package/dist/study/services/CardHydrationService.mjs.map +1 -0
  177. package/dist/study/services/EloService.mjs +217 -0
  178. package/dist/study/services/EloService.mjs.map +1 -0
  179. package/dist/study/services/ResponseProcessor.mjs +190 -0
  180. package/dist/study/services/ResponseProcessor.mjs.map +1 -0
  181. package/dist/study/services/SrsService.mjs +49 -0
  182. package/dist/study/services/SrsService.mjs.map +1 -0
  183. package/dist/study/services/tagRecent.mjs +65 -0
  184. package/dist/study/services/tagRecent.mjs.map +1 -0
  185. package/dist/{types-dXWfyz9B.d.ts → types-DChCz22D.d.ts} +1 -1
  186. package/dist/{types-legacy-BkOYOR6U.d.cts → types-legacy-fT5Y1Wuy.d.ts} +1 -1
  187. package/dist/userDBKeys-ne1g4Xuq.d.ts +16 -0
  188. package/dist/util/Loggable.mjs +14 -0
  189. package/dist/util/Loggable.mjs.map +1 -0
  190. package/dist/util/dataDirectory.mjs +47 -0
  191. package/dist/util/dataDirectory.mjs.map +1 -0
  192. package/dist/util/logger.mjs +86 -0
  193. package/dist/util/logger.mjs.map +1 -0
  194. package/dist/util/migrator/FileSystemAdapter.mjs +18 -0
  195. package/dist/util/migrator/FileSystemAdapter.mjs.map +1 -0
  196. package/dist/util/migrator/StaticToCouchDBMigrator.mjs +428 -0
  197. package/dist/util/migrator/StaticToCouchDBMigrator.mjs.map +1 -0
  198. package/dist/util/migrator/types.mjs +11 -0
  199. package/dist/util/migrator/types.mjs.map +1 -0
  200. package/dist/util/migrator/validation.mjs +334 -0
  201. package/dist/util/migrator/validation.mjs.map +1 -0
  202. package/dist/util/packer/CouchDBToStaticPacker.mjs +438 -0
  203. package/dist/util/packer/CouchDBToStaticPacker.mjs.map +1 -0
  204. package/dist/util/packer/{index.js → index.cjs} +73 -9
  205. package/dist/util/packer/index.cjs.map +1 -0
  206. package/dist/util/packer/index.d.ts +3 -3
  207. package/dist/util/packer/index.mjs +2 -537
  208. package/eslint.config.mjs +9 -1
  209. package/package.json +25 -13
  210. package/rolldown.config.mjs +44 -0
  211. package/src/core/UserDBDebugger.ts +47 -46
  212. package/src/core/navigators/Pipeline.ts +10 -10
  213. package/src/core/navigators/PipelineDebugger.ts +55 -55
  214. package/src/core/navigators/filters/eloDistance.ts +11 -1
  215. package/src/core/navigators/generators/elo.ts +5 -1
  216. package/src/core/navigators/index.ts +9 -3
  217. package/src/diagnostics/derive.ts +6 -0
  218. package/src/diagnostics/index.ts +1 -0
  219. package/src/diagnostics/tagElo.ts +257 -0
  220. package/src/factory.ts +10 -1
  221. package/src/impl/common/BaseUserDB.ts +1 -3
  222. package/src/impl/common/index.ts +2 -0
  223. package/src/impl/common/userDBHelpers.ts +4 -58
  224. package/src/impl/common/userDBKeys.ts +64 -0
  225. package/src/impl/couch/courseDB.ts +15 -3
  226. package/src/impl/couch/index.ts +2 -18
  227. package/src/impl/couch/pouchdb-setup.ts +8 -0
  228. package/src/index.ts +1 -1
  229. package/src/study/MixerDebugger.ts +46 -46
  230. package/src/study/SessionDebugger.ts +20 -20
  231. package/src/study/SessionOverlay.ts +4 -4
  232. package/src/util/logger.ts +112 -13
  233. package/tests/core/navigators/eloGenerator.test.ts +36 -0
  234. package/tsup.config.ts +24 -21
  235. package/dist/SyncStrategy-BXliog1m.d.cts +0 -116
  236. package/dist/classroomDB-DLTtLZct.d.cts +0 -86
  237. package/dist/contentSource-JmWYu8IK.d.ts +0 -2007
  238. package/dist/core/index.d.cts +0 -521
  239. package/dist/core/index.js.map +0 -1
  240. package/dist/core/index.mjs.map +0 -1
  241. package/dist/dataLayerProvider-DfI_KYAe.d.cts +0 -61
  242. package/dist/diagnostics/index.d.cts +0 -458
  243. package/dist/diagnostics/index.js.map +0 -1
  244. package/dist/diagnostics/index.mjs.map +0 -1
  245. package/dist/impl/couch/index.d.cts +0 -620
  246. package/dist/impl/couch/index.js.map +0 -1
  247. package/dist/impl/static/index.d.cts +0 -232
  248. package/dist/impl/static/index.js.map +0 -1
  249. package/dist/impl/static/index.mjs.map +0 -1
  250. package/dist/index-Ktg72jKb.d.cts +0 -137
  251. package/dist/index.d.cts +0 -1663
  252. package/dist/index.js.map +0 -1
  253. package/dist/index.mjs.map +0 -1
  254. package/dist/pouch/index.d.cts +0 -1
  255. package/dist/pouch/index.js.map +0 -1
  256. package/dist/pouch/index.mjs.map +0 -1
  257. package/dist/types-D0oQeJAi.d.cts +0 -58
  258. package/dist/types-legacy-BkOYOR6U.d.ts +0 -168
  259. package/dist/util/packer/index.d.cts +0 -5
  260. package/dist/util/packer/index.js.map +0 -1
  261. package/dist/util/packer/index.mjs.map +0 -1
  262. package/src/study/getCardDataShape.ts +0 -34
@@ -478,16 +478,16 @@ function formatProvenance(provenance: StrategyContribution[]): string {
478
478
  function printRunSummary(run: PipelineRunReport): void {
479
479
  // eslint-disable-next-line no-console
480
480
  console.group(`🔍 Pipeline Run: ${run.courseId} (${run.courseName || 'unnamed'})`);
481
- logger.info(`Run ID: ${run.runId}`);
482
- logger.info(`Time: ${run.timestamp.toISOString()}`);
483
- logger.info(`User ELO: ${run.userElo ?? 'unknown'}`);
484
- logger.info(`Generator: ${run.generatorName} → ${run.generatedCount} candidates`);
481
+ logger.print(`Run ID: ${run.runId}`);
482
+ logger.print(`Time: ${run.timestamp.toISOString()}`);
483
+ logger.print(`User ELO: ${run.userElo ?? 'unknown'}`);
484
+ logger.print(`Generator: ${run.generatorName} → ${run.generatedCount} candidates`);
485
485
 
486
486
  if (run.generators && run.generators.length > 0) {
487
487
  // eslint-disable-next-line no-console
488
488
  console.group('Generator breakdown:');
489
489
  for (const g of run.generators) {
490
- logger.info(
490
+ logger.print(
491
491
  ` ${g.name}: ${g.cardCount} cards (${g.newCount} new, ${g.reviewCount} reviews, top: ${g.topScore.toFixed(2)})`
492
492
  );
493
493
  }
@@ -499,13 +499,13 @@ function printRunSummary(run: PipelineRunReport): void {
499
499
  // eslint-disable-next-line no-console
500
500
  console.group('Filter impact:');
501
501
  for (const f of run.filters) {
502
- logger.info(` ${f.name}: ↑${f.boosted} ↓${f.penalized} =${f.passed} ✕${f.removed}`);
502
+ logger.print(` ${f.name}: ↑${f.boosted} ↓${f.penalized} =${f.passed} ✕${f.removed}`);
503
503
  }
504
504
  // eslint-disable-next-line no-console
505
505
  console.groupEnd();
506
506
  }
507
507
 
508
- logger.info(
508
+ logger.print(
509
509
  `Result: ${run.finalCount} cards selected (${run.newSelected} new, ${run.reviewsSelected} reviews)`
510
510
  );
511
511
  // eslint-disable-next-line no-console
@@ -805,7 +805,7 @@ export const pipelineDebugAPI = {
805
805
  */
806
806
  showRun(idOrIndex: string | number = 0): void {
807
807
  if (runHistory.length === 0) {
808
- logger.info('[Pipeline Debug] No runs captured yet.');
808
+ logger.print('[Pipeline Debug] No runs captured yet.');
809
809
  return;
810
810
  }
811
811
 
@@ -814,7 +814,7 @@ export const pipelineDebugAPI = {
814
814
  if (typeof idOrIndex === 'number') {
815
815
  run = runHistory[idOrIndex];
816
816
  if (!run) {
817
- logger.info(
817
+ logger.print(
818
818
  `[Pipeline Debug] No run found at index ${idOrIndex}. History length: ${runHistory.length}`
819
819
  );
820
820
  return;
@@ -822,7 +822,7 @@ export const pipelineDebugAPI = {
822
822
  } else {
823
823
  run = runHistory.find((r) => r.runId.endsWith(idOrIndex));
824
824
  if (!run) {
825
- logger.info(`[Pipeline Debug] No run found matching ID '${idOrIndex}'.`);
825
+ logger.print(`[Pipeline Debug] No run found matching ID '${idOrIndex}'.`);
826
826
  return;
827
827
  }
828
828
  }
@@ -846,16 +846,16 @@ export const pipelineDebugAPI = {
846
846
  if (card) {
847
847
  // eslint-disable-next-line no-console
848
848
  console.group(`🎴 Card: ${cardId}`);
849
- logger.info(`Course: ${card.courseId}`);
850
- logger.info(`Origin: ${card.origin}`);
851
- logger.info(`Card ELO: ${card.cardElo ?? 'unknown'} | User ELO: ${run.userElo ?? 'unknown'}`);
852
- logger.info(`Final score: ${card.finalScore.toFixed(3)}`);
853
- logger.info(`Selected: ${card.selected ? 'Yes ✅' : 'No ❌'}`);
849
+ logger.print(`Course: ${card.courseId}`);
850
+ logger.print(`Origin: ${card.origin}`);
851
+ logger.print(`Card ELO: ${card.cardElo ?? 'unknown'} | User ELO: ${run.userElo ?? 'unknown'}`);
852
+ logger.print(`Final score: ${card.finalScore.toFixed(3)}`);
853
+ logger.print(`Selected: ${card.selected ? 'Yes ✅' : 'No ❌'}`);
854
854
  if (card.tags && card.tags.length > 0) {
855
- logger.info(`Tags (${card.tags.length}): ${card.tags.join(', ')}`);
855
+ logger.print(`Tags (${card.tags.length}): ${card.tags.join(', ')}`);
856
856
  }
857
- logger.info('Provenance:');
858
- logger.info(formatProvenance(card.provenance));
857
+ logger.print('Provenance:');
858
+ logger.print(formatProvenance(card.provenance));
859
859
  // eslint-disable-next-line no-console
860
860
  console.groupEnd();
861
861
  return;
@@ -866,13 +866,13 @@ export const pipelineDebugAPI = {
866
866
  // breadcrumb rather than a flat "not found".
867
867
  const runsWithTails = runHistory.filter((r) => r.discardedTail && r.discardedTail.count > 0);
868
868
  if (runsWithTails.length > 0) {
869
- logger.info(
869
+ logger.print(
870
870
  `[Pipeline Debug] Card '${cardId}' not found in retained cards. ` +
871
871
  `${runsWithTails.length} run(s) have discarded tails that were not retained — ` +
872
872
  `the card may have been a low-score candidate. See run.discardedTail for ranges.`
873
873
  );
874
874
  } else {
875
- logger.info(`[Pipeline Debug] Card '${cardId}' not found in recent runs.`);
875
+ logger.print(`[Pipeline Debug] Card '${cardId}' not found in recent runs.`);
876
876
  }
877
877
  },
878
878
 
@@ -881,7 +881,7 @@ export const pipelineDebugAPI = {
881
881
  */
882
882
  explainReviews(): void {
883
883
  if (runHistory.length === 0) {
884
- logger.info('[Pipeline Debug] No runs captured yet.');
884
+ logger.print('[Pipeline Debug] No runs captured yet.');
885
885
  return;
886
886
  }
887
887
 
@@ -896,10 +896,10 @@ export const pipelineDebugAPI = {
896
896
  const selectedReviews = allReviews.filter((c) => c.selected);
897
897
 
898
898
  if (allReviews.length === 0) {
899
- logger.info('❌ No reviews were generated. Check SRS logs for why.');
899
+ logger.print('❌ No reviews were generated. Check SRS logs for why.');
900
900
  } else if (selectedReviews.length === 0) {
901
- logger.info(`⚠️ ${allReviews.length} reviews generated but none selected.`);
902
- logger.info('Possible reasons:');
901
+ logger.print(`⚠️ ${allReviews.length} reviews generated but none selected.`);
902
+ logger.print('Possible reasons:');
903
903
 
904
904
  // Check if new cards scored higher
905
905
  const topNewScore = Math.max(
@@ -909,7 +909,7 @@ export const pipelineDebugAPI = {
909
909
  const topReviewScore = Math.max(...allReviews.map((c) => c.finalScore), 0);
910
910
 
911
911
  if (topReviewScore < topNewScore) {
912
- logger.info(
912
+ logger.print(
913
913
  ` - New cards scored higher (top new: ${topNewScore.toFixed(2)}, top review: ${topReviewScore.toFixed(2)})`
914
914
  );
915
915
  }
@@ -917,15 +917,15 @@ export const pipelineDebugAPI = {
917
917
  // Show top review that didn't make it
918
918
  const topReview = allReviews.sort((a, b) => b.finalScore - a.finalScore)[0];
919
919
  if (topReview) {
920
- logger.info(` - Top review score: ${topReview.finalScore.toFixed(3)}`);
921
- logger.info(' - Its provenance:');
922
- logger.info(formatProvenance(topReview.provenance));
920
+ logger.print(` - Top review score: ${topReview.finalScore.toFixed(3)}`);
921
+ logger.print(' - Its provenance:');
922
+ logger.print(formatProvenance(topReview.provenance));
923
923
  }
924
924
  } else {
925
- logger.info(`✅ ${selectedReviews.length}/${allReviews.length} reviews selected.`);
926
- logger.info('Top selected review:');
925
+ logger.print(`✅ ${selectedReviews.length}/${allReviews.length} reviews selected.`);
926
+ logger.print('Top selected review:');
927
927
  const topSelected = selectedReviews.sort((a, b) => b.finalScore - a.finalScore)[0];
928
- logger.info(formatProvenance(topSelected.provenance));
928
+ logger.print(formatProvenance(topSelected.provenance));
929
929
  }
930
930
 
931
931
  // eslint-disable-next-line no-console
@@ -948,7 +948,7 @@ export const pipelineDebugAPI = {
948
948
  */
949
949
  showPrescribed(groupId?: string): void {
950
950
  if (runHistory.length === 0) {
951
- logger.info('[Pipeline Debug] No runs captured yet.');
951
+ logger.print('[Pipeline Debug] No runs captured yet.');
952
952
  return;
953
953
  }
954
954
 
@@ -961,7 +961,7 @@ export const pipelineDebugAPI = {
961
961
  console.group(`🧭 Prescribed Debug (${run.courseId})`);
962
962
 
963
963
  if (prescribedCards.length === 0) {
964
- logger.info('No prescribed-generated cards were present in the most recent run.');
964
+ logger.print('No prescribed-generated cards were present in the most recent run.');
965
965
  // eslint-disable-next-line no-console
966
966
  console.groupEnd();
967
967
  return;
@@ -1003,7 +1003,7 @@ export const pipelineDebugAPI = {
1003
1003
  .sort((a, b) => Number(b.finalScore) - Number(a.finalScore));
1004
1004
 
1005
1005
  if (rows.length === 0) {
1006
- logger.info(
1006
+ logger.print(
1007
1007
  `[Pipeline Debug] No prescribed cards matched group '${groupId}' in the most recent run.`
1008
1008
  );
1009
1009
  // eslint-disable-next-line no-console
@@ -1042,18 +1042,18 @@ export const pipelineDebugAPI = {
1042
1042
  }
1043
1043
  }
1044
1044
 
1045
- logger.info(`Prescribed cards in run: ${rows.length}`);
1046
- logger.info(`Selected prescribed cards: ${selectedRows.length}`);
1047
- logger.info(
1045
+ logger.print(`Prescribed cards in run: ${rows.length}`);
1046
+ logger.print(`Selected prescribed cards: ${selectedRows.length}`);
1047
+ logger.print(
1048
1048
  `Blocked prescribed targets referenced: ${blockedTargetSet.size > 0 ? [...blockedTargetSet].join(', ') : 'none'}`
1049
1049
  );
1050
- logger.info(
1050
+ logger.print(
1051
1051
  `Resolved support tags referenced: ${supportTagSet.size > 0 ? [...supportTagSet].join(', ') : 'none'}`
1052
1052
  );
1053
- logger.info(
1053
+ logger.print(
1054
1054
  `Authored support cards emitted: ${authoredSupportSet.size > 0 ? [...authoredSupportSet].join(', ') : 'none'}`
1055
1055
  );
1056
- logger.info(
1056
+ logger.print(
1057
1057
  `Discovered support cards emitted: ${discoveredSupportSet.size > 0 ? [...discoveredSupportSet].join(', ') : 'none'}`
1058
1058
  );
1059
1059
 
@@ -1066,7 +1066,7 @@ export const pipelineDebugAPI = {
1066
1066
  */
1067
1067
  listRuns(): void {
1068
1068
  if (runHistory.length === 0) {
1069
- logger.info('[Pipeline Debug] No runs captured yet.');
1069
+ logger.print('[Pipeline Debug] No runs captured yet.');
1070
1070
  return;
1071
1071
  }
1072
1072
 
@@ -1089,8 +1089,8 @@ export const pipelineDebugAPI = {
1089
1089
  */
1090
1090
  export(): string {
1091
1091
  const json = JSON.stringify(runHistory, null, 2);
1092
- logger.info('[Pipeline Debug] Run history exported. Copy the returned string or use:');
1093
- logger.info(' copy(window.skuilder.pipeline.export())');
1092
+ logger.print('[Pipeline Debug] Run history exported. Copy the returned string or use:');
1093
+ logger.print(' copy(window.skuilder.pipeline.export())');
1094
1094
  return json;
1095
1095
  },
1096
1096
 
@@ -1099,7 +1099,7 @@ export const pipelineDebugAPI = {
1099
1099
  */
1100
1100
  clear(): void {
1101
1101
  runHistory.length = 0;
1102
- logger.info('[Pipeline Debug] Run history cleared.');
1102
+ logger.print('[Pipeline Debug] Run history cleared.');
1103
1103
  },
1104
1104
 
1105
1105
  /**
@@ -1111,7 +1111,7 @@ export const pipelineDebugAPI = {
1111
1111
  showRegistry(): void {
1112
1112
  const names = getRegisteredNavigatorNames();
1113
1113
  if (names.length === 0) {
1114
- logger.info('[Pipeline Debug] Navigator registry is empty.');
1114
+ logger.print('[Pipeline Debug] Navigator registry is empty.');
1115
1115
  return;
1116
1116
  }
1117
1117
 
@@ -1147,26 +1147,26 @@ export const pipelineDebugAPI = {
1147
1147
  this.showRegistry();
1148
1148
 
1149
1149
  if (runHistory.length === 0) {
1150
- logger.info('[Pipeline Debug] No pipeline runs captured yet — cannot show strategy doc mapping.');
1150
+ logger.print('[Pipeline Debug] No pipeline runs captured yet — cannot show strategy doc mapping.');
1151
1151
  return;
1152
1152
  }
1153
1153
 
1154
1154
  const run = runHistory[0];
1155
1155
  // eslint-disable-next-line no-console
1156
1156
  console.group('🔌 Pipeline Strategy Mapping (last run)');
1157
- logger.info(`Generator: ${run.generatorName}`);
1157
+ logger.print(`Generator: ${run.generatorName}`);
1158
1158
  if (run.generators && run.generators.length > 0) {
1159
1159
  for (const g of run.generators) {
1160
- logger.info(` 📥 ${g.name}: ${g.cardCount} cards (${g.newCount} new, ${g.reviewCount} reviews)`);
1160
+ logger.print(` 📥 ${g.name}: ${g.cardCount} cards (${g.newCount} new, ${g.reviewCount} reviews)`);
1161
1161
  }
1162
1162
  }
1163
1163
  if (run.filters.length > 0) {
1164
- logger.info('Filters:');
1164
+ logger.print('Filters:');
1165
1165
  for (const f of run.filters) {
1166
- logger.info(` 🔸 ${f.name}: ↑${f.boosted} ↓${f.penalized} =${f.passed} ✕${f.removed}`);
1166
+ logger.print(` 🔸 ${f.name}: ↑${f.boosted} ↓${f.penalized} =${f.passed} ✕${f.removed}`);
1167
1167
  }
1168
1168
  } else {
1169
- logger.info('Filters: (none)');
1169
+ logger.print('Filters: (none)');
1170
1170
  }
1171
1171
  // eslint-disable-next-line no-console
1172
1172
  console.groupEnd();
@@ -1182,7 +1182,7 @@ export const pipelineDebugAPI = {
1182
1182
  */
1183
1183
  async diagnoseCardSpace(threshold?: number): Promise<CardSpaceDiagnosis | null> {
1184
1184
  if (!_activePipeline) {
1185
- logger.info('[Pipeline Debug] No active pipeline. Run a session first.');
1185
+ logger.print('[Pipeline Debug] No active pipeline. Run a session first.');
1186
1186
  return null;
1187
1187
  }
1188
1188
  return _activePipeline.diagnoseCardSpace({ threshold });
@@ -1196,13 +1196,13 @@ export const pipelineDebugAPI = {
1196
1196
  */
1197
1197
  async showTagElo(tagFilter?: string | string[]): Promise<void> {
1198
1198
  if (!_activePipeline) {
1199
- logger.info('[Pipeline Debug] No active pipeline. Run a session first.');
1199
+ logger.print('[Pipeline Debug] No active pipeline. Run a session first.');
1200
1200
  return;
1201
1201
  }
1202
1202
  const status = await _activePipeline.getTagEloStatus(tagFilter);
1203
1203
  const entries = Object.entries(status).sort(([a], [b]) => a.localeCompare(b));
1204
1204
  if (entries.length === 0) {
1205
- logger.info(`[Pipeline Debug] No tag ELO data found${tagFilter ? ` for pattern: ${tagFilter}` : ''}.`);
1205
+ logger.print(`[Pipeline Debug] No tag ELO data found${tagFilter ? ` for pattern: ${tagFilter}` : ''}.`);
1206
1206
  return;
1207
1207
  }
1208
1208
  // eslint-disable-next-line no-console
@@ -1304,7 +1304,7 @@ export const pipelineDebugAPI = {
1304
1304
  * Show help.
1305
1305
  */
1306
1306
  help(): void {
1307
- logger.info(`
1307
+ logger.print(`
1308
1308
  🔧 Pipeline Debug API
1309
1309
 
1310
1310
  Commands:
@@ -159,7 +159,7 @@ export function mountMultiDimEloToggle(): void {
159
159
  } catch (e) {
160
160
  logger.warn(`[EloDistance] multiDimElo not persisted (localStorage unavailable): ${e}`);
161
161
  }
162
- logger.info(
162
+ logger.print(
163
163
  `[EloDistance] multiDimElo ${multiDimElo ? 'on: tag-aware' : 'off: per strategy config'}` +
164
164
  ' ELO distance from the next replan'
165
165
  );
@@ -207,6 +207,16 @@ interface TagGap {
207
207
  * cards and act like a second global rating. The framework may want the
208
208
  * course to say which tags are skills (cf. LP's diagnostics interpreter
209
209
  * `isSkillTag`), e.g. as tag patterns in the strategy config.
210
+ * The admin ELO viewer (in progress, 2026-10) answers the same question for
211
+ * display with its own tag batches (role × namespace). Before tag-aware goes
212
+ * on by default, make that one predicate:
213
+ * - a serializable selector (roles, prefix patterns), beside `tagRoles.ts`
214
+ * in common, so a strategy doc can carry it;
215
+ * - an `EloDistanceConfig` field for it, read by `tagAwareGap`;
216
+ * - `tagAwareGap` moved to a pure module (this file imports `core`, which
217
+ * the diagnostics entry can't), so the viewer can show what the filter
218
+ * would compute;
219
+ * - the viewer's default batch read from the course's eloDistance config.
210
220
  * 3. New cards matter most, and that dump couldn't show them. An unseen
211
221
  * card's tag ratings fall back to its global, so for new cards this reads
212
222
  * "card global vs the learner's rating on that skill". Measuring it needs a
@@ -83,9 +83,13 @@ export default class ELONavigator extends ContentNavigator implements CardGenera
83
83
  ]);
84
84
  const notNew = new Set([...activeCards.map((ac) => ac.cardID), ...seenCards]);
85
85
  // const tActive = performance.now(); // [perf] parked
86
+ // Centre the window on this generator's user's ELO, passed explicitly:
87
+ // `elo: 'user'` would have the course DB resolve its own notion of the
88
+ // current user, which isn't necessarily the user this pipeline runs for
89
+ // (e.g. an admin running a learner's pipeline read-only).
86
90
  const newCards = (
87
91
  await this.course.getCardsCenteredAtELO(
88
- { limit, elo: 'user' },
92
+ { limit, elo: userGlobalElo },
89
93
  (c: QualifiedCardID) => !notNew.has(c.cardID)
90
94
  )
91
95
  ).map((c) => ({ ...c, status: 'new' as const }));
@@ -619,13 +619,19 @@ export abstract class ContentNavigator implements StudyContentSource {
619
619
 
620
620
  let NavigatorImpl;
621
621
 
622
+ // Specifiers built at runtime, never template literals: bundlers expand
623
+ // `import(`./generators/${x}`)` into a glob over the directory, which in a
624
+ // per-module dist matches .map and .d.ts files and breaks the app's build.
625
+ // This fallback only resolves from source (no '.mjs' variation).
626
+ const load = (specifier: string) => import(/* @vite-ignore */ specifier);
627
+
622
628
  // Try different extension variations
623
629
  const variations = ['.ts', '.js', ''];
624
630
 
625
631
  for (const ext of variations) {
626
632
  // Try generators directory
627
633
  try {
628
- const module = await import(`./generators/${implementingClass}${ext}`);
634
+ const module = await load(`./generators/${implementingClass}${ext}`);
629
635
  NavigatorImpl = module.default;
630
636
  if (NavigatorImpl) break;
631
637
  } catch (e) {
@@ -634,7 +640,7 @@ export abstract class ContentNavigator implements StudyContentSource {
634
640
 
635
641
  // Try filters directory
636
642
  try {
637
- const module = await import(`./filters/${implementingClass}${ext}`);
643
+ const module = await load(`./filters/${implementingClass}${ext}`);
638
644
  NavigatorImpl = module.default;
639
645
  if (NavigatorImpl) break;
640
646
  } catch (e) {
@@ -643,7 +649,7 @@ export abstract class ContentNavigator implements StudyContentSource {
643
649
 
644
650
  // Try current directory (legacy)
645
651
  try {
646
- const module = await import(`./${implementingClass}${ext}`);
652
+ const module = await load(`./${implementingClass}${ext}`);
647
653
  NavigatorImpl = module.default;
648
654
  if (NavigatorImpl) break;
649
655
  } catch (e) {
@@ -13,6 +13,7 @@ import type {
13
13
  StudySessionRunSummary,
14
14
  } from '../core/types/studySession';
15
15
  import type { CardSummary, DatasetRecord, LearnerDataset } from './dataset';
16
+ import type { TagBatch } from './tagElo';
16
17
 
17
18
  /**
18
19
  * Course-supplied meaning for the generic views. Every member is optional and
@@ -30,6 +31,11 @@ export interface DiagnosticsInterpreters {
30
31
  snapshotMetrics?(snapshot: SessionStateSnapshot): Record<string, number>;
31
32
  /** Which `snapshotMetrics` labels count as progress (for `stalled`). Default: none. */
32
33
  progressMetrics?: string[];
34
+ /**
35
+ * Named tag batches for the ELO view, offered beside the namespace × role
36
+ * batches it finds on its own. Default: none.
37
+ */
38
+ tagBatches?: TagBatch[];
33
39
  }
34
40
 
35
41
  export const isSkillTag = (i: DiagnosticsInterpreters | undefined, tag: string): boolean =>
@@ -15,6 +15,7 @@ export * from './loader';
15
15
  export * from './derive';
16
16
  export * from './text';
17
17
  export * from './pipeline';
18
+ export * from './tagElo';
18
19
  export type {
19
20
  SessionEloEvent,
20
21
  SessionStateSnapshot,
@@ -0,0 +1,257 @@
1
+ /**
2
+ * A learner's per-tag ELO, read for display: one row per tag on their course
3
+ * registration, the batches a view filters those rows by, and each rating's
4
+ * trajectory through the dataset's sessions.
5
+ *
6
+ * The source is the learner's `CourseElo` (global + per-tag `{score, count,
7
+ * recent}`). Session `eloEvents` add trajectories (per-tag before → after,
8
+ * from when sessions began recording them); card-history records add when a
9
+ * tag was first and last named by a response.
10
+ */
11
+ import {
12
+ COUNT_ONLY_SCORE,
13
+ isCountOnlyTag,
14
+ tagRole,
15
+ type CourseElo,
16
+ type EloRank,
17
+ type TagPresentation,
18
+ type TagRole,
19
+ } from '@vue-skuilder/common';
20
+ import type { LearnerDataset } from './dataset';
21
+
22
+ // ============================================================================
23
+ // Batches
24
+ // ============================================================================
25
+
26
+ /**
27
+ * A set of tags to view together, as data: every criterion given must hold.
28
+ *
29
+ * Plain data on purpose. Choosing which tags count is the same question the
30
+ * tag-aware ELO distance filter has open (`tagAwareGap` in
31
+ * `filters/eloDistance.ts`); a serializable batch can later move into a
32
+ * strategy config and serve both.
33
+ */
34
+ export interface TagBatch {
35
+ id: string;
36
+ label: string;
37
+ /** Tag namespaces (see {@link tagNamespace}); `''` is tags with none. */
38
+ namespaces?: string[];
39
+ /** Tag roles; `'none'` is tags without one. */
40
+ roles?: Array<TagRole | 'none'>;
41
+ /** Tags starting with any of these. */
42
+ prefixes?: string[];
43
+ /** Tags starting with any of these are left out. */
44
+ excludePrefixes?: string[];
45
+ }
46
+
47
+ /** What precedes a tag's role segment: `gpc` in `gpc:exercise:x`, `''` in `expose:x`. */
48
+ function beforeRole(tag: string, role: TagRole): string {
49
+ // tagRole takes the leftmost role segment; the leftmost of this one is it.
50
+ const match = new RegExp(`(^|:)${role}:(?=.)`).exec(tag);
51
+ return match ? tag.slice(0, match.index) : '';
52
+ }
53
+
54
+ /**
55
+ * The colon-delimited segments that scope a tag: what comes before its role
56
+ * (`gpc:exercise:x` → `gpc`), else its first segment (`concept:match:x` →
57
+ * `concept`). `''` for a tag with neither (`femur`, `expose:x`).
58
+ */
59
+ export function tagNamespace(tag: string): string {
60
+ const role = tagRole(tag);
61
+ if (role) return beforeRole(tag, role);
62
+ const colon = tag.indexOf(':');
63
+ return colon > 0 ? tag.slice(0, colon) : '';
64
+ }
65
+
66
+ export function matchesTagBatch(tag: string, batch: TagBatch, role = tagRole(tag)): boolean {
67
+ if (batch.namespaces && !batch.namespaces.includes(tagNamespace(tag))) return false;
68
+ if (batch.roles && !batch.roles.includes(role ?? 'none')) return false;
69
+ if (batch.prefixes && !batch.prefixes.some((p) => tag.startsWith(p))) return false;
70
+ if (batch.excludePrefixes?.some((p) => tag.startsWith(p))) return false;
71
+ return true;
72
+ }
73
+
74
+ /** The namespace × role batch a tag falls in, e.g. `gpc:exercise`, `concept`, or `(no namespace)`. */
75
+ export function tagGroupBatch(tag: string): TagBatch {
76
+ const role = tagRole(tag);
77
+ const ns = tagNamespace(tag);
78
+ const id = [ns, role].filter(Boolean).join(':') || '(no namespace)';
79
+ return { id, label: id, namespaces: [ns], roles: [role ?? 'none'] };
80
+ }
81
+
82
+ // ============================================================================
83
+ // Rows
84
+ // ============================================================================
85
+
86
+ export interface TagEloRow {
87
+ tag: string;
88
+ role: TagRole | null;
89
+ namespace: string;
90
+ /** Id of the tag's {@link tagGroupBatch}. */
91
+ group: string;
92
+ /**
93
+ * The learner's rating on the tag. Null for a count-only tag: a bookkeeping
94
+ * role (`intro`, `expose`), or the count-only sentinel.
95
+ */
96
+ score: number | null;
97
+ /**
98
+ * A real score stored on a bookkeeping-role tag, from before roles were
99
+ * count-only. Not a rating: the framework ignores it.
100
+ */
101
+ staleScore?: number;
102
+ count: number;
103
+ /** `score − global`; null when score is. */
104
+ vsGlobal: number | null;
105
+ /** The rating's ring buffer of recent first attempts, oldest first. */
106
+ recent: TagPresentation[];
107
+ /** First-attempt correct entries in `recent`. */
108
+ recentOk: number;
109
+ /** First and last response whose per-tag performance named the tag, or a recent entry. */
110
+ firstSeen: string | null;
111
+ lastSeen: string | null;
112
+ /** ELO events on the tag in the dataset's sessions. */
113
+ events: number;
114
+ }
115
+
116
+ export interface EloPoint {
117
+ at: string;
118
+ score: number;
119
+ }
120
+
121
+ export interface TagEloView {
122
+ global: EloRank;
123
+ /** Every tag on the registration, highest score first, count-only tags last. */
124
+ rows: TagEloRow[];
125
+ /** The namespace × role batches present, graded ones first. */
126
+ groups: TagBatch[];
127
+ /**
128
+ * Ratings through the dataset's ELO events: each series starts at its first
129
+ * event's `before`, has a point per event, and ends at the current score at
130
+ * `asOf`. A move between recorded events (a session that didn't save its
131
+ * events) shows as a step at the next event, or at `asOf`. Tags with no
132
+ * events have no series; count-only tags have none.
133
+ */
134
+ series: { global: EloPoint[]; tags: Record<string, EloPoint[]> };
135
+ /** The first ELO event, or null: trajectories start here. */
136
+ seriesFrom: string | null;
137
+ }
138
+
139
+ /** The learner's `CourseElo` for the dataset's course, or null if not registered. */
140
+ export function learnerCourseElo(ds: LearnerDataset): CourseElo | null {
141
+ const elo = ds.registration?.courses?.find((c) => c.courseID === ds.courseId)?.elo;
142
+ if (typeof elo === 'number') return { global: { score: elo, count: 0 }, tags: {}, misc: {} };
143
+ if (!elo || typeof elo !== 'object' || !elo.global) return null;
144
+ return { ...elo, tags: elo.tags ?? {}, misc: elo.misc ?? {} };
145
+ }
146
+
147
+ function minIso(a: string | null, b: string): string {
148
+ return a === null || b < a ? b : a;
149
+ }
150
+
151
+ function maxIso(a: string | null, b: string): string {
152
+ return a === null || b > a ? b : a;
153
+ }
154
+
155
+ /**
156
+ * Extend a series by one event. A `before` that differs from where the line
157
+ * stands gets its own point: the rating moved between recorded events (a
158
+ * session that closed without saving its events), shown as a step here.
159
+ */
160
+ function step(line: EloPoint[], at: string, before: number, after: number): void {
161
+ if (before !== COUNT_ONLY_SCORE && line[line.length - 1]?.score !== before)
162
+ line.push({ at, score: before });
163
+ line.push({ at, score: after });
164
+ }
165
+
166
+ /** The learner's per-tag ELO for display. Null if the dataset has no registration for its course. */
167
+ export function tagEloView(ds: LearnerDataset): TagEloView | null {
168
+ const elo = learnerCourseElo(ds);
169
+ if (!elo) return null;
170
+
171
+ // When each tag was named by a response, from card history.
172
+ const seen = new Map<string, { first: string | null; last: string | null }>();
173
+ for (const h of ds.cardHistories) {
174
+ for (const r of h.records) {
175
+ const p = r.performance as unknown;
176
+ if (!p || typeof p !== 'object') continue;
177
+ for (const tag of Object.keys(p)) {
178
+ if (tag === '_global') continue;
179
+ const s = seen.get(tag) ?? { first: null, last: null };
180
+ s.first = minIso(s.first, r.timeStamp);
181
+ s.last = maxIso(s.last, r.timeStamp);
182
+ seen.set(tag, s);
183
+ }
184
+ }
185
+ }
186
+
187
+ // Trajectories, from session ELO events in time order.
188
+ const events = ds.sessions
189
+ .flatMap((s) => s.eloEvents ?? [])
190
+ .sort((a, b) => a.at.localeCompare(b.at));
191
+ const globalSeries: EloPoint[] = [];
192
+ const tagSeries: Record<string, EloPoint[]> = {};
193
+ const eventCounts = new Map<string, number>();
194
+ for (const e of events) {
195
+ step(globalSeries, e.at, e.global.before, e.global.after);
196
+ for (const [tag, t] of Object.entries(e.tags ?? {})) {
197
+ eventCounts.set(tag, (eventCounts.get(tag) ?? 0) + 1);
198
+ if (t.score === null || isCountOnlyTag(tag) || t.after === COUNT_ONLY_SCORE) continue;
199
+ step((tagSeries[tag] ??= []), e.at, t.before, t.after);
200
+ }
201
+ }
202
+
203
+ const rows: TagEloRow[] = Object.entries(elo.tags).map(([tag, rank]) => {
204
+ const role = tagRole(tag);
205
+ const countOnly = isCountOnlyTag(tag) || rank.score === COUNT_ONLY_SCORE;
206
+ const score = countOnly ? null : rank.score;
207
+ const recent = rank.recent ?? [];
208
+ let { first, last } = seen.get(tag) ?? { first: null, last: null };
209
+ for (const p of recent) {
210
+ first = minIso(first, p.at);
211
+ last = maxIso(last, p.at);
212
+ }
213
+ return {
214
+ tag,
215
+ role,
216
+ namespace: tagNamespace(tag),
217
+ group: tagGroupBatch(tag).id,
218
+ score,
219
+ ...(countOnly && rank.score !== COUNT_ONLY_SCORE ? { staleScore: rank.score } : {}),
220
+ count: rank.count,
221
+ vsGlobal: score === null ? null : score - elo.global.score,
222
+ recent,
223
+ recentOk: recent.filter((p) => p.ok).length,
224
+ firstSeen: first,
225
+ lastSeen: last,
226
+ events: eventCounts.get(tag) ?? 0,
227
+ };
228
+ });
229
+ rows.sort((a, b) =>
230
+ a.score === null || b.score === null
231
+ ? Number(a.score === null) - Number(b.score === null) || a.tag.localeCompare(b.tag)
232
+ : b.score - a.score || a.tag.localeCompare(b.tag)
233
+ );
234
+
235
+ // Close each line at the current rating, so it reaches `asOf` and shows any
236
+ // move the events didn't record.
237
+ if (globalSeries.length > 0) globalSeries.push({ at: ds.asOf, score: elo.global.score });
238
+ for (const row of rows) {
239
+ const line = tagSeries[row.tag];
240
+ if (line && row.score !== null) line.push({ at: ds.asOf, score: row.score });
241
+ }
242
+
243
+ const groups = new Map<string, TagBatch>();
244
+ for (const row of rows) if (!groups.has(row.group)) groups.set(row.group, tagGroupBatch(row.tag));
245
+ const countOnlyGroup = (b: TagBatch): boolean =>
246
+ b.roles?.some((r) => r === 'intro' || r === 'expose') ?? false;
247
+
248
+ return {
249
+ global: elo.global,
250
+ rows,
251
+ groups: [...groups.values()].sort(
252
+ (a, b) => Number(countOnlyGroup(a)) - Number(countOnlyGroup(b)) || a.id.localeCompare(b.id)
253
+ ),
254
+ series: { global: globalSeries, tags: tagSeries },
255
+ seriesFrom: events[0]?.at ?? null,
256
+ };
257
+ }