@interleavelove/keating 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +274 -0
  2. package/bin/keating.js +31 -0
  3. package/dist/src/cli/main.js +165 -0
  4. package/dist/src/core/animation.js +372 -0
  5. package/dist/src/core/benchmark.js +238 -0
  6. package/dist/src/core/config.js +81 -0
  7. package/dist/src/core/evolution.js +224 -0
  8. package/dist/src/core/learner-state.js +88 -0
  9. package/dist/src/core/lesson-plan.js +155 -0
  10. package/dist/src/core/map.js +89 -0
  11. package/dist/src/core/paths.js +69 -0
  12. package/dist/src/core/pi-agent.js +58 -0
  13. package/dist/src/core/policy.js +53 -0
  14. package/dist/src/core/project.js +189 -0
  15. package/dist/src/core/prompt-evolution.js +337 -0
  16. package/dist/src/core/random.js +19 -0
  17. package/dist/src/core/self-improve.js +419 -0
  18. package/dist/src/core/topics.js +620 -0
  19. package/dist/src/core/types.js +1 -0
  20. package/dist/src/core/util.js +28 -0
  21. package/dist/src/core/verification.js +162 -0
  22. package/dist/src/pi/hyperteacher-extension.js +180 -0
  23. package/dist/src/runtime/pi.js +118 -0
  24. package/dist/test/animation.test.js +43 -0
  25. package/dist/test/config.test.js +36 -0
  26. package/dist/test/evolution.test.js +39 -0
  27. package/dist/test/fuzz.test.js +37 -0
  28. package/dist/test/hyperteacher-extension.test.js +122 -0
  29. package/dist/test/lesson-plan.test.js +35 -0
  30. package/dist/test/pipeline.test.js +57 -0
  31. package/dist/test/prompt-evolution.test.js +89 -0
  32. package/package.json +58 -0
  33. package/pi/prompts/bridge.md +14 -0
  34. package/pi/prompts/diagnose.md +15 -0
  35. package/pi/prompts/improve.md +39 -0
  36. package/pi/prompts/learn.md +21 -0
  37. package/pi/prompts/quiz.md +14 -0
  38. package/pi/skills/adaptive-teaching/SKILL.md +33 -0
  39. package/scripts/install/install.sh +307 -0
@@ -0,0 +1,620 @@
1
+ import { slugify, titleCase } from "./util.js";
2
+ const TOPICS = {
3
+ derivative: {
4
+ slug: "derivative",
5
+ title: "Derivative",
6
+ domain: "math",
7
+ summary: "The derivative measures how a quantity changes at an instant.",
8
+ intuition: [
9
+ "Start with average change over an interval, then shrink the interval toward a point.",
10
+ "Connect slope-of-a-graph intuition to motion: velocity is the derivative of position."
11
+ ],
12
+ formalCore: [
13
+ "Define the derivative as the limit of the difference quotient.",
14
+ "Explain differentiability as a stronger condition than continuity."
15
+ ],
16
+ prerequisites: ["functions", "limits", "slope"],
17
+ misconceptions: [
18
+ "A derivative is not just plugging into a formula; it is an instantaneous rate of change.",
19
+ "Continuity does not guarantee differentiability."
20
+ ],
21
+ examples: [
22
+ "Differentiate x^2 and interpret the result geometrically.",
23
+ "Use position and velocity for a moving particle."
24
+ ],
25
+ exercises: [
26
+ "Estimate a derivative from a table of values.",
27
+ "Compare a secant line and a tangent line."
28
+ ],
29
+ reflections: [
30
+ "Why does shrinking the interval change average rate into instantaneous rate?",
31
+ "What physical quantity becomes easier to reason about once you have derivatives?"
32
+ ],
33
+ diagramNodes: ["Prerequisites", "Intuition", "Limit", "Derivative", "Applications", "Exercises"],
34
+ formalism: 0.85,
35
+ visualizable: true,
36
+ interdisciplinaryHooks: ["motion", "optimization", "scientific models"]
37
+ },
38
+ entropy: {
39
+ slug: "entropy",
40
+ title: "Entropy",
41
+ domain: "science",
42
+ summary: "Entropy tracks how many micro-configurations are compatible with what we observe macroscopically.",
43
+ intuition: [
44
+ "Contrast neat-looking states with the many more ways disorder can be arranged.",
45
+ "Use information-theoretic intuition: surprising events carry more information."
46
+ ],
47
+ formalCore: [
48
+ "Relate thermodynamic entropy to multiplicity and log-counting.",
49
+ "Show the bridge to Shannon entropy for distributions."
50
+ ],
51
+ prerequisites: ["probability", "energy", "microstate vs macrostate"],
52
+ misconceptions: [
53
+ "Entropy is not simply 'chaos'; it is a count of compatible arrangements.",
54
+ "Higher entropy does not mean less structure everywhere."
55
+ ],
56
+ examples: [
57
+ "Mixing two gases in a box.",
58
+ "Comparing a fair coin to a biased coin."
59
+ ],
60
+ exercises: [
61
+ "Rank systems by relative entropy change.",
62
+ "Explain why logarithms appear in entropy formulas."
63
+ ],
64
+ reflections: [
65
+ "When does entropy feel like information instead of physics?",
66
+ "How does coarse-graining shape the meaning of entropy?"
67
+ ],
68
+ diagramNodes: ["Multiplicity", "Macrostate", "Entropy", "Information", "Arrow of Time"],
69
+ formalism: 0.78,
70
+ visualizable: true,
71
+ interdisciplinaryHooks: ["information theory", "statistical mechanics", "machine learning"]
72
+ },
73
+ bayes: {
74
+ slug: "bayes-rule",
75
+ title: "Bayes' Rule",
76
+ domain: "math",
77
+ summary: "Bayes' rule updates beliefs when new evidence arrives.",
78
+ intuition: [
79
+ "Start with prior belief and then scale it by how compatible the evidence is with each hypothesis.",
80
+ "Use base-rate reasoning to avoid overreacting to a positive test."
81
+ ],
82
+ formalCore: [
83
+ "Derive Bayes' rule from conditional probability.",
84
+ "Separate prior, likelihood, evidence, and posterior."
85
+ ],
86
+ prerequisites: ["conditional probability", "fractions", "base rates"],
87
+ misconceptions: [
88
+ "A highly accurate test can still produce many false positives.",
89
+ "Posterior probability is not the same as likelihood."
90
+ ],
91
+ examples: [
92
+ "Medical testing with rare disease prevalence.",
93
+ "Spam filtering using prior and evidence."
94
+ ],
95
+ exercises: [
96
+ "Compute a posterior from a confusion matrix.",
97
+ "Explain the difference between P(A|B) and P(B|A)."
98
+ ],
99
+ reflections: [
100
+ "How do priors encode context rather than bias in the pejorative sense?",
101
+ "When should you distrust your own posterior?"
102
+ ],
103
+ diagramNodes: ["Prior", "Evidence", "Likelihood", "Posterior", "Decision"],
104
+ formalism: 0.8,
105
+ visualizable: true,
106
+ interdisciplinaryHooks: ["diagnostics", "scientific inference", "epistemology"]
107
+ },
108
+ falsifiability: {
109
+ slug: "falsifiability",
110
+ title: "Falsifiability",
111
+ domain: "philosophy",
112
+ summary: "A claim is scientifically risky when observation could in principle show it false.",
113
+ intuition: [
114
+ "Compare a risky prediction to a claim that explains every possible outcome.",
115
+ "Use Popper's distinction between bold hypotheses and immunized stories."
116
+ ],
117
+ formalCore: [
118
+ "Define falsifiability as a demarcation criterion, not a full theory of science.",
119
+ "Connect the concept to test design and prediction."
120
+ ],
121
+ prerequisites: ["hypothesis", "prediction", "scientific method"],
122
+ misconceptions: [
123
+ "Unfalsifiable does not always mean meaningless; it means not testable as science.",
124
+ "Single failed tests do not automatically settle complex theories."
125
+ ],
126
+ examples: [
127
+ "General relativity versus vague pseudo-scientific claims.",
128
+ "Forecasts that specify measurable outcomes."
129
+ ],
130
+ exercises: [
131
+ "Rewrite a vague claim so it becomes testable.",
132
+ "Separate scientific, metaphysical, and rhetorical statements."
133
+ ],
134
+ reflections: [
135
+ "Why might a philosopher care about risky predictions?",
136
+ "Where does falsifiability help, and where does it oversimplify?"
137
+ ],
138
+ diagramNodes: ["Claim", "Prediction", "Test", "Failure Condition", "Revision"],
139
+ formalism: 0.58,
140
+ visualizable: true,
141
+ interdisciplinaryHooks: ["scientific practice", "epistemology", "model validation"]
142
+ },
143
+ stoicism: {
144
+ slug: "stoicism",
145
+ title: "Stoicism",
146
+ domain: "philosophy",
147
+ summary: "Stoicism trains attention toward what is under one's control and away from what is not.",
148
+ intuition: [
149
+ "Start with the dichotomy of control: actions and judgments are yours; outcomes are not.",
150
+ "Frame emotion regulation as disciplined interpretation rather than suppression."
151
+ ],
152
+ formalCore: [
153
+ "Explain virtue as the highest good in Stoic ethics.",
154
+ "Connect Stoic practice to attention, judgment, and habit."
155
+ ],
156
+ prerequisites: ["virtue ethics", "self-control", "judgment"],
157
+ misconceptions: [
158
+ "Stoicism is not emotional numbness.",
159
+ "Accepting outcomes does not mean passivity."
160
+ ],
161
+ examples: [
162
+ "Handling criticism at work.",
163
+ "Separating preparation from uncontrollable outcomes."
164
+ ],
165
+ exercises: [
166
+ "Sort concerns into controllable and uncontrollable buckets.",
167
+ "Rewrite an anxious thought in Stoic language."
168
+ ],
169
+ reflections: [
170
+ "What changes if you judge effort, not outcome, as the main target?",
171
+ "Where might Stoicism become too austere?"
172
+ ],
173
+ diagramNodes: ["Perception", "Judgment", "Control", "Action", "Reflection"],
174
+ formalism: 0.42,
175
+ visualizable: true,
176
+ interdisciplinaryHooks: ["psychology", "habit formation", "ethics"]
177
+ },
178
+ recursion: {
179
+ slug: "recursion",
180
+ title: "Recursion",
181
+ domain: "code",
182
+ summary: "Recursion solves a problem by having a function call itself on a smaller subproblem until it reaches a base case.",
183
+ intuition: [
184
+ "Think of Russian nesting dolls: open one to find a smaller version of the same thing inside.",
185
+ "Every recursive process needs a stopping point (base case) and a way to get closer to it."
186
+ ],
187
+ formalCore: [
188
+ "A recursive function calls itself with arguments that converge toward a base case.",
189
+ "The call stack stores each invocation's local state until the base case returns."
190
+ ],
191
+ prerequisites: ["functions", "call stack", "conditional branching"],
192
+ misconceptions: [
193
+ "Stack overflow is not the same as infinite recursion; it is the consequence of unbounded recursion hitting memory limits.",
194
+ "Recursion is not inherently slower than iteration; tail-call optimization can make them equivalent."
195
+ ],
196
+ examples: [
197
+ "Factorial: n! = n * (n-1)! with base case 0! = 1.",
198
+ "Fibonacci sequence computed recursively, then improved with memoization."
199
+ ],
200
+ exercises: [
201
+ "Trace the call stack for factorial(4) by hand.",
202
+ "Convert a recursive function to an iterative one using an explicit stack."
203
+ ],
204
+ reflections: [
205
+ "When is recursion clearer than iteration, and when is it a trap?",
206
+ "How does memoization change the computational cost of naive recursion?"
207
+ ],
208
+ diagramNodes: ["Base Case", "Recursive Case", "Call Stack", "Return Path", "Subproblem"],
209
+ formalism: 0.75,
210
+ visualizable: true,
211
+ interdisciplinaryHooks: ["mathematical induction", "fractal geometry", "divide and conquer algorithms"]
212
+ },
213
+ precedent: {
214
+ slug: "precedent",
215
+ title: "Legal Precedent",
216
+ domain: "law",
217
+ summary: "Precedent is the principle that courts should follow earlier decisions on similar facts to ensure consistency and predictability.",
218
+ intuition: [
219
+ "Courts treat past rulings like promises: if a similar case was decided a certain way, future cases should follow unless there is a strong reason to depart.",
220
+ "Stare decisis ('stand by things decided') is the Latin name for this commitment to consistency."
221
+ ],
222
+ formalCore: [
223
+ "The ratio decidendi (reason for deciding) of a case is the binding part; obiter dicta (things said in passing) are persuasive but not binding.",
224
+ "Precedent can be distinguished (shown to differ on material facts), overruled (explicitly rejected by a higher court), or departed from in exceptional circumstances."
225
+ ],
226
+ prerequisites: ["court hierarchy", "case law", "statutory interpretation"],
227
+ misconceptions: [
228
+ "Precedent is not absolute; courts can and do depart from or overrule past decisions.",
229
+ "Only the ratio decidendi binds, not every statement a judge makes in an opinion."
230
+ ],
231
+ examples: [
232
+ "Donoghue v Stevenson (1932) establishing the modern duty of care in negligence.",
233
+ "Brown v Board of Education (1954) overruling Plessy v Ferguson on racial segregation."
234
+ ],
235
+ exercises: [
236
+ "Read a case summary and identify the ratio decidendi versus obiter dicta.",
237
+ "Argue why a precedent should or should not apply to a new set of facts."
238
+ ],
239
+ reflections: [
240
+ "When does consistency serve justice, and when does it entrench past mistakes?",
241
+ "How does the tension between stability and adaptability shape a legal system?"
242
+ ],
243
+ diagramNodes: ["Facts", "Ratio Decidendi", "Obiter Dicta", "Binding Authority", "Distinguishing"],
244
+ formalism: 0.55,
245
+ visualizable: false,
246
+ interdisciplinaryHooks: ["political philosophy", "institutional design", "ethics of consistency"]
247
+ },
248
+ "separation-of-powers": {
249
+ slug: "separation-of-powers",
250
+ title: "Separation of Powers",
251
+ domain: "politics",
252
+ summary: "Separation of powers divides government authority among distinct branches so that no single entity can accumulate unchecked control.",
253
+ intuition: [
254
+ "Imagine three people sharing a kitchen: one decides the recipe (legislature), one cooks (executive), one tastes and judges quality (judiciary).",
255
+ "Each branch has tools to resist encroachment by the others — checks and balances."
256
+ ],
257
+ formalCore: [
258
+ "The legislature makes law, the executive enforces it, and the judiciary interprets it.",
259
+ "Checks and balances (veto, judicial review, confirmation power) prevent any branch from dominating."
260
+ ],
261
+ prerequisites: ["branches of government", "constitutionalism", "rule of law"],
262
+ misconceptions: [
263
+ "The branches are not equal in power at all times; the balance shifts with political context.",
264
+ "Separation of powers does not mean the branches never interact — overlap and negotiation are by design."
265
+ ],
266
+ examples: [
267
+ "The US President's veto power and Congress's ability to override it.",
268
+ "Judicial review as established in Marbury v Madison (1803)."
269
+ ],
270
+ exercises: [
271
+ "Map a recent political conflict to the branch interactions involved.",
272
+ "Compare separation of powers in a presidential system versus a parliamentary system."
273
+ ],
274
+ reflections: [
275
+ "What happens when one branch consistently defers to another?",
276
+ "Is the theory of separated powers a description or an aspiration?"
277
+ ],
278
+ diagramNodes: ["Legislature", "Executive", "Judiciary", "Checks", "Balances"],
279
+ formalism: 0.45,
280
+ visualizable: true,
281
+ interdisciplinaryHooks: ["constitutional law", "game theory", "institutional economics"]
282
+ },
283
+ "cognitive-bias": {
284
+ slug: "cognitive-bias",
285
+ title: "Cognitive Bias",
286
+ domain: "psychology",
287
+ summary: "Cognitive biases are systematic patterns where human judgment departs from normative rationality in predictable directions.",
288
+ intuition: [
289
+ "Your brain uses shortcuts (heuristics) that usually work but sometimes misfire in predictable ways.",
290
+ "Anchoring: the first number you hear warps your subsequent estimates even when it is irrelevant."
291
+ ],
292
+ formalCore: [
293
+ "A bias is systematic (not random) and directional (pushes judgment in a specific direction).",
294
+ "Key biases: anchoring, confirmation bias, availability heuristic, representativeness, loss aversion."
295
+ ],
296
+ prerequisites: ["heuristics", "probability", "decision-making"],
297
+ misconceptions: [
298
+ "Knowing about a bias does not automatically debias you; structured procedures are usually needed.",
299
+ "Not every error in judgment is a 'cognitive bias'; the term has specific empirical criteria."
300
+ ],
301
+ examples: [
302
+ "Anchoring in salary negotiation: the first number proposed shifts the outcome.",
303
+ "Confirmation bias in research: seeking evidence that supports your hypothesis while ignoring disconfirming data."
304
+ ],
305
+ exercises: [
306
+ "Design a simple experiment to demonstrate anchoring in a group.",
307
+ "Identify which bias is operating in a given decision scenario."
308
+ ],
309
+ reflections: [
310
+ "When are heuristics adaptive rather than biased?",
311
+ "How should we interpret bias research given the replication crisis in psychology?"
312
+ ],
313
+ diagramNodes: ["Heuristic", "Bias", "Normative Standard", "Debiasing", "Ecological Rationality"],
314
+ formalism: 0.50,
315
+ visualizable: true,
316
+ interdisciplinaryHooks: ["behavioral economics", "epistemology", "AI alignment"]
317
+ },
318
+ "evidence-based-medicine": {
319
+ slug: "evidence-based-medicine",
320
+ title: "Evidence-Based Medicine",
321
+ domain: "medicine",
322
+ summary: "Evidence-based medicine integrates the best available research evidence with clinical expertise and patient values to guide healthcare decisions.",
323
+ intuition: [
324
+ "Not all evidence is equal: a well-run randomized trial tells you more than a handful of anecdotes.",
325
+ "The number needed to treat (NNT) makes benefit concrete — how many patients must be treated for one to benefit?"
326
+ ],
327
+ formalCore: [
328
+ "The evidence hierarchy ranks study designs: systematic reviews and RCTs at the top, case reports and expert opinion at the bottom.",
329
+ "Clinical significance (effect size, NNT) and statistical significance (p-value) are distinct concepts."
330
+ ],
331
+ prerequisites: ["study design", "statistical significance", "clinical outcomes"],
332
+ misconceptions: [
333
+ "Statistical significance does not imply clinical importance; a tiny effect can be statistically significant.",
334
+ "Observational studies are not worthless — they are essential when RCTs are infeasible or unethical."
335
+ ],
336
+ examples: [
337
+ "The Cochrane review process for synthesizing trial evidence.",
338
+ "NNT for statins in primary cardiovascular prevention."
339
+ ],
340
+ exercises: [
341
+ "Calculate NNT from absolute risk reduction in a trial summary.",
342
+ "Rank three studies by their position in the evidence hierarchy and explain why."
343
+ ],
344
+ reflections: [
345
+ "When should clinical judgment override the published evidence?",
346
+ "How do patient values interact with population-level evidence?"
347
+ ],
348
+ diagramNodes: ["Evidence Hierarchy", "RCT", "Systematic Review", "Clinical Expertise", "Patient Values"],
349
+ formalism: 0.70,
350
+ visualizable: true,
351
+ interdisciplinaryHooks: ["biostatistics", "philosophy of science", "health policy"]
352
+ },
353
+ counterpoint: {
354
+ slug: "counterpoint",
355
+ title: "Counterpoint",
356
+ domain: "arts",
357
+ summary: "Counterpoint is the art of combining independent melodic voices so they sound coherent together.",
358
+ intuition: [
359
+ "Imagine two people singing different melodies at the same time — counterpoint is the set of principles that makes them harmonize rather than clash.",
360
+ "Each voice has its own melodic life, but they must agree at key moments (consonances) and resolve tension (dissonances) gracefully."
361
+ ],
362
+ formalCore: [
363
+ "Species counterpoint progresses through five species, each adding rhythmic complexity to a cantus firmus.",
364
+ "Rules govern intervals (consonant vs dissonant), voice motion (parallel, contrary, oblique), and the treatment of dissonance (passing tones, suspensions)."
365
+ ],
366
+ prerequisites: ["intervals", "consonance and dissonance", "melodic motion"],
367
+ misconceptions: [
368
+ "Counterpoint is not just 'harmony with two melodies'; it prioritizes horizontal (melodic) independence over vertical (chordal) logic.",
369
+ "Following the rules mechanically does not produce good counterpoint; the rules describe constraints within which musical taste operates."
370
+ ],
371
+ examples: [
372
+ "Bach's Two-Part Inventions as studies in imitative counterpoint.",
373
+ "First-species counterpoint: note-against-note with only consonant intervals."
374
+ ],
375
+ exercises: [
376
+ "Write a first-species counterpoint above a given cantus firmus.",
377
+ "Identify parallel fifths and octaves in a short two-voice passage."
378
+ ],
379
+ reflections: [
380
+ "Why did composers develop strict rules only to break them?",
381
+ "How does counterpoint relate to the broader tension between freedom and constraint in art?"
382
+ ],
383
+ diagramNodes: ["Cantus Firmus", "Species", "Voice Motion", "Consonance", "Resolution"],
384
+ formalism: 0.60,
385
+ visualizable: true,
386
+ interdisciplinaryHooks: ["acoustics", "mathematical structure in music", "aesthetic philosophy"]
387
+ },
388
+ "industrial-revolution": {
389
+ slug: "industrial-revolution",
390
+ title: "Industrial Revolution",
391
+ domain: "history",
392
+ summary: "The Industrial Revolution was a period of rapid technological, economic, and social transformation that began in Britain in the late 18th century.",
393
+ intuition: [
394
+ "For most of history, economic output grew barely faster than population; then something changed and output per person began doubling every few decades.",
395
+ "The revolution was not just machines — it was a shift in how energy, labor, and knowledge combined."
396
+ ],
397
+ formalCore: [
398
+ "Key factors: cheap energy (coal), institutional environment (property rights, patent law), labor supply, and capital accumulation.",
399
+ "Periodization matters: the first Industrial Revolution (~1760-1840) centered on textiles and steam; the second (~1870-1914) on steel, chemicals, and electricity."
400
+ ],
401
+ prerequisites: ["pre-industrial economy", "mercantilism", "agricultural revolution"],
402
+ misconceptions: [
403
+ "The Industrial Revolution was not purely technological; institutional, demographic, and geographic factors were equally important.",
404
+ "Living standards did not immediately improve for everyone — the first generations of factory workers often faced harsh conditions."
405
+ ],
406
+ examples: [
407
+ "The cotton gin and spinning jenny transforming textile production.",
408
+ "The railway boom of the 1840s connecting markets and reshaping geography."
409
+ ],
410
+ exercises: [
411
+ "Place five key inventions on a timeline and explain their causal connections.",
412
+ "Compare the British and continental European paths to industrialization."
413
+ ],
414
+ reflections: [
415
+ "Why did the Industrial Revolution start in Britain rather than elsewhere?",
416
+ "What parallels exist between the Industrial Revolution and today's digital transformation?"
417
+ ],
418
+ diagramNodes: ["Energy", "Technology", "Institutions", "Labor", "Periodization", "Consequences"],
419
+ formalism: 0.35,
420
+ visualizable: true,
421
+ interdisciplinaryHooks: ["economic history", "sociology of technology", "environmental history"]
422
+ },
423
+ relativity: {
424
+ slug: "relativity",
425
+ title: "Special Relativity",
426
+ domain: "science",
427
+ summary: "Special relativity reveals that space and time are linked, and that the laws of physics are the same for all observers moving at constant velocity.",
428
+ intuition: [
429
+ "Imagine you are on a perfectly smooth train: without looking out the window, you can't tell if you are moving or sitting still.",
430
+ "Light always travels at the same speed, no matter how fast you chase it. To keep the speed of light constant, time itself must stretch and space must shrink."
431
+ ],
432
+ formalCore: [
433
+ "The two postulates: the laws of physics are invariant in all inertial frames, and the speed of light in vacuum is constant for all observers.",
434
+ "Lorentz transformations describe how coordinates change between frames, leading to time dilation and length contraction."
435
+ ],
436
+ prerequisites: ["velocity", "inertial frames", "Pythagorean theorem"],
437
+ misconceptions: [
438
+ "Relativity does not mean 'everything is subjective'; it means specific measurements are relative, but the laws (and the spacetime interval) are absolute.",
439
+ "Time dilation is not an optical illusion; it is a physical change in the passage of time."
440
+ ],
441
+ examples: [
442
+ "Muons reaching the Earth's surface due to time dilation.",
443
+ "GPS satellites requiring relativistic corrections to stay synchronized."
444
+ ],
445
+ exercises: [
446
+ "Calculate the time dilation factor for a ship traveling at 0.8c.",
447
+ "Explain the 'twin paradox' and identify where the symmetry breaks."
448
+ ],
449
+ reflections: [
450
+ "How does the constant speed of light force us to abandon the idea of absolute simultaneity?",
451
+ "What does it mean for 'now' to be a local, rather than universal, concept?"
452
+ ],
453
+ diagramNodes: ["Postulates", "Light Speed", "Time Dilation", "Length Contraction", "Spacetime"],
454
+ formalism: 0.88,
455
+ visualizable: true,
456
+ interdisciplinaryHooks: ["philosophy of time", "astrophysics", "GPS technology"]
457
+ },
458
+ "social-contract": {
459
+ slug: "social-contract",
460
+ title: "Social Contract Theory",
461
+ domain: "philosophy",
462
+ summary: "Social contract theory argues that political authority and moral obligations are derived from an implicit agreement among individuals to form a society.",
463
+ intuition: [
464
+ "Imagine a 'state of nature' with no laws or government. To escape the chaos, everyone agrees to give up some freedoms in exchange for collective security.",
465
+ "The legitimacy of a ruler depends on whether they uphold their end of the bargain."
466
+ ],
467
+ formalCore: [
468
+ "Hobbes: the contract is an absolute surrender to a sovereign to avoid a life that is 'nasty, brutish, and short'.",
469
+ "Locke: the contract is conditional, intended to protect natural rights (life, liberty, property), with a right to revolution if the sovereign fails."
470
+ ],
471
+ prerequisites: ["sovereignty", "natural rights", "state of nature"],
472
+ misconceptions: [
473
+ "The 'contract' is a philosophical tool, not a historical document that people actually signed.",
474
+ "Social contract theory is not the same as pure democracy; it is about the *source* of legitimacy, not just the *form* of government."
475
+ ],
476
+ examples: [
477
+ "The US Declaration of Independence as a Lockean document.",
478
+ "Modern taxation as a trade-off for public infrastructure and safety."
479
+ ],
480
+ exercises: [
481
+ "Compare and contrast Hobbes's and Rousseau's views on the 'general will'.",
482
+ "Apply social contract theory to a modern issue, like digital privacy or vaccine mandates."
483
+ ],
484
+ reflections: [
485
+ "What happens to the contract if someone cannot 'opt out' of the state?",
486
+ "How does the theory handle obligations to future generations who didn't 'sign'?"
487
+ ],
488
+ diagramNodes: ["State of Nature", "Agreement", "Sovereign", "Rights", "Legitimacy"],
489
+ formalism: 0.52,
490
+ visualizable: true,
491
+ interdisciplinaryHooks: ["political science", "legal theory", "ethics"]
492
+ }
493
+ };
494
+ const DOMAIN_KEYWORDS = {};
495
+ for (const [kw, d] of [
496
+ ["function", "code"], ["algorithm", "code"], ["programming", "code"], ["code", "code"],
497
+ ["loop", "code"], ["variable", "code"], ["compiler", "code"], ["data-structure", "code"],
498
+ ["class", "code"], ["inheritance", "code"], ["api", "code"], ["database", "code"],
499
+ ["court", "law"], ["statute", "law"], ["legal", "law"], ["tort", "law"],
500
+ ["contract", "law"], ["constitution", "law"], ["rights", "law"], ["jurisdiction", "law"],
501
+ ["democracy", "politics"], ["election", "politics"], ["sovereignty", "politics"],
502
+ ["ideology", "politics"], ["parliament", "politics"], ["governance", "politics"],
503
+ ["memory", "psychology"], ["emotion", "psychology"], ["behavior", "psychology"],
504
+ ["cognition", "psychology"], ["perception", "psychology"], ["personality", "psychology"],
505
+ ["diagnosis", "medicine"], ["treatment", "medicine"], ["pathology", "medicine"],
506
+ ["clinical", "medicine"], ["anatomy", "medicine"], ["pharmacology", "medicine"],
507
+ ["painting", "arts"], ["sculpture", "arts"], ["music", "arts"], ["composition", "arts"],
508
+ ["poetry", "arts"], ["theatre", "arts"], ["aesthetic", "arts"], ["harmony", "arts"],
509
+ ["war", "history"], ["empire", "history"], ["revolution", "history"], ["medieval", "history"],
510
+ ["colonial", "history"], ["ancient", "history"], ["civilization", "history"],
511
+ ["theorem", "math"], ["proof", "math"], ["calculus", "math"], ["algebra", "math"],
512
+ ["geometry", "math"], ["integral", "math"], ["topology", "math"],
513
+ ["evolution", "science"], ["quantum", "science"], ["thermodynamic", "science"],
514
+ ["cell", "science"], ["gravity", "science"], ["relativity", "science"],
515
+ ["ethics", "philosophy"], ["epistemology", "philosophy"], ["metaphysics", "philosophy"],
516
+ ["logic", "philosophy"], ["existentialism", "philosophy"], ["ontology", "philosophy"]
517
+ ]) {
518
+ DOMAIN_KEYWORDS[kw] = d;
519
+ }
520
+ function guessDomain(slug) {
521
+ const words = slug.split("-");
522
+ for (const word of words) {
523
+ if (DOMAIN_KEYWORDS[word])
524
+ return DOMAIN_KEYWORDS[word];
525
+ }
526
+ return "general";
527
+ }
528
+ const DOMAIN_EXAMPLE_HINTS = {
529
+ code: {
530
+ examples: ["Write a minimal runnable example demonstrating %s.", "Trace execution step by step for a simple input."],
531
+ exercises: ["Ask the learner to predict the output of a short code snippet involving %s.", "Ask the learner to refactor or simplify a naive implementation."]
532
+ },
533
+ law: {
534
+ examples: ["Cite one leading case or statute illustrating %s.", "Show how the rule applies differently across two jurisdictions."],
535
+ exercises: ["Ask the learner to identify the ratio decidendi in a case summary.", "Ask the learner to argue both sides of a dispute involving %s."]
536
+ },
537
+ politics: {
538
+ examples: ["Give one real-world example of %s in a democratic system.", "Contrast how %s operates in two different political systems."],
539
+ exercises: ["Ask the learner to map a current event to the concept of %s.", "Ask the learner to evaluate a normative claim about %s."]
540
+ },
541
+ psychology: {
542
+ examples: ["Describe one classic experiment related to %s.", "Give an everyday example where %s affects decision-making."],
543
+ exercises: ["Ask the learner to design a simple study testing %s.", "Ask the learner to distinguish the empirical finding from folk-psychology intuition."]
544
+ },
545
+ medicine: {
546
+ examples: ["Reference a systematic review or landmark trial related to %s.", "Compute or interpret a relevant clinical metric (NNT, sensitivity, specificity)."],
547
+ exercises: ["Ask the learner to rank evidence sources by the evidence hierarchy.", "Ask the learner to distinguish mechanism-based reasoning from evidence-based conclusions about %s."]
548
+ },
549
+ arts: {
550
+ examples: ["Analyze a specific work that exemplifies %s.", "Compare two works that take different approaches to %s."],
551
+ exercises: ["Ask the learner to create a short exercise applying the technique of %s.", "Ask the learner to connect formal technique to expressive effect in a given work."]
552
+ },
553
+ history: {
554
+ examples: ["Place %s on a timeline with at least two contextual events.", "Cite a primary source relevant to %s."],
555
+ exercises: ["Ask the learner to distinguish primary sources from secondary interpretation.", "Ask the learner to compare two historians' accounts of %s."]
556
+ },
557
+ math: {
558
+ examples: ["Give one scientific or mathematical example connected to %s.", "Show a worked proof or calculation involving %s."],
559
+ exercises: ["Ask the learner to explain %s in their own words.", "Ask the learner to compare %s to a nearby concept."]
560
+ },
561
+ science: {
562
+ examples: ["Give one experimental or observational example connected to %s.", "Connect %s to a measurable prediction."],
563
+ exercises: ["Ask the learner to explain %s in their own words.", "Ask the learner to design an experiment that tests %s."]
564
+ },
565
+ philosophy: {
566
+ examples: ["Give one philosophical thought experiment connected to %s.", "Show where two major thinkers disagree about %s."],
567
+ exercises: ["Ask the learner to explain %s in their own words.", "Ask the learner to identify the strongest objection to %s."]
568
+ },
569
+ general: {
570
+ examples: ["Give one scientific or mathematical example connected to %s.", "Give one philosophical or practical example connected to %s."],
571
+ exercises: ["Ask the learner to explain %s in their own words.", "Ask the learner to compare %s to a nearby concept."]
572
+ }
573
+ };
574
+ const VISUALIZABLE_DOMAINS = new Set([
575
+ "math", "science", "code", "medicine", "psychology", "history", "arts"
576
+ ]);
577
+ function buildFallbackTopic(rawTopic) {
578
+ const title = titleCase(rawTopic.trim());
579
+ const slug = slugify(rawTopic);
580
+ const domain = guessDomain(slug);
581
+ const hints = DOMAIN_EXAMPLE_HINTS[domain];
582
+ return {
583
+ slug,
584
+ title,
585
+ domain,
586
+ summary: `${title} taught through intuition first, then structure, then transfer.`,
587
+ intuition: [
588
+ `Explain ${title} in concrete language before formal vocabulary.`,
589
+ `Anchor ${title} in one memorable metaphor and one real-world example.`
590
+ ],
591
+ formalCore: [
592
+ `State the core definition or thesis of ${title}.`,
593
+ `Separate assumptions, mechanism, and scope of ${title}.`
594
+ ],
595
+ prerequisites: ["basic vocabulary", "one motivating example"],
596
+ misconceptions: [
597
+ `${title} is not just a slogan; it has structure, assumptions, and trade-offs.`,
598
+ `Confusing an example of ${title} with the whole concept usually causes shallow understanding.`
599
+ ],
600
+ examples: hints.examples.map(e => e.replace(/%s/g, title)),
601
+ exercises: hints.exercises.map(e => e.replace(/%s/g, title)),
602
+ reflections: [
603
+ `What would mastery of ${title} let you predict, compute, or judge better?`,
604
+ `Where would ${title} likely break down or become controversial?`
605
+ ],
606
+ diagramNodes: ["Motivation", "Definition", "Mechanism", "Examples", "Limits", "Transfer"],
607
+ formalism: domain === "math" ? 0.75 : domain === "code" ? 0.70 : domain === "medicine" ? 0.65 : 0.55,
608
+ visualizable: VISUALIZABLE_DOMAINS.has(domain),
609
+ interdisciplinaryHooks: ["comparison", "application", "critique"]
610
+ };
611
+ }
612
+ export function resolveTopic(query) {
613
+ const normalized = slugify(query);
614
+ return TOPICS[normalized] ?? TOPICS[normalized.replace(/-rule$/, "")] ?? buildFallbackTopic(query);
615
+ }
616
+ export function benchmarkTopics(focusTopic) {
617
+ if (focusTopic?.trim())
618
+ return [resolveTopic(focusTopic)];
619
+ return Object.values(TOPICS);
620
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ export function clamp(value, min = 0, max = 1) {
2
+ return Math.min(max, Math.max(min, value));
3
+ }
4
+ export function mean(values) {
5
+ if (values.length === 0)
6
+ return 0;
7
+ return values.reduce((sum, value) => sum + value, 0) / values.length;
8
+ }
9
+ export function slugify(text) {
10
+ return text
11
+ .toLowerCase()
12
+ .replace(/[^a-z0-9]+/g, "-")
13
+ .replace(/^-+|-+$/g, "")
14
+ .slice(0, 48) || "topic";
15
+ }
16
+ export function titleCase(text) {
17
+ return text.replace(/\b\w/g, (char) => char.toUpperCase());
18
+ }
19
+ export function chunk(items, size) {
20
+ const chunks = [];
21
+ for (let index = 0; index < items.length; index += size) {
22
+ chunks.push(items.slice(index, index + size));
23
+ }
24
+ return chunks;
25
+ }
26
+ export function formatPercent(value) {
27
+ return `${(value * 100).toFixed(1)}%`;
28
+ }