The term data has two tiers. Only the definitions, and the commentary that quotes sources, follow third-party wording. Everything else is facts, short terms or text written in this project.
| Tier | What | Where | In the repository | In the PWA |
|---|---|---|---|---|
| Open | terms (name, Wylie and Tibetan script, Sanskrit with its Devanagari, aliases, chapter), Russian terms, Chinese terms (traditional characters, simplified characters and pinyin), relations and classification, the practice items (below), categories (with the words the syllogism drill says for each, the course terms mutually inclusive with a category's own that some of its words name, the pervasions among everyday categories it may take as given, the groups of kinds that are mixed up, and the stage each opens at) | src/data/drill-data.json |
plain JSON, one term per line so that diffs read | plain, precached |
| Course: definitions | d (English) and d_ru (Russian) of each term |
the server's database (course_data), and data-private/definitions.json on a machine that works with the data |
not included (git-ignored folder) | fetched from the server with the Magic Key, then kept on the device |
| Course: notes | note of each term and the group notes: commentary read only by the Claude tutor |
the server's database, and data-private/notes.json |
not included | not included, and the server never sends them out |
| Course: examples | the reference examples: the knowledge base's example notes with their classes, level (1 to 4), kind and confirmation (below) | the server's database (rows examples and examples_device), and data-private/examples.json and examples-device.json |
not included | the device part, fetched in the background with the Magic Key, then kept on the device |
The artifact build carries all of it, because the artifact is private to its owner and its tutor reads the notes; it reads data-private/. That includes the device part of the reference examples, when data-private/ has them (about 240 KB with the real ones, against the page budget in tests/unit/artifact-build.test.ts, 1.5 MiB). The tutor Worker (SERVER.md) reads the notes from its database, so the tutor sees them and a browser never receives them.
The practice items are the things the exercises compute the relations from and show in the cells: about five hundred, written for practice in the knowledge base (no source claims them). A few hundred everyday objects ("a fabric sofa", "a hot metal spoon") are generated there from a table of modern objects and the materials, colors, shapes and options each can have, so that every two everyday categories that can go together really sit together on some item; people come from a smaller table of the same kind; the rest are written by hand. Each item has its Dudra type t, its categories c, and:
st, its stage on the learning ladder, from 0 (things around you) to 12: the plainest stage at which a newcomer knows it without the course's words. A category has ansttoo, the stage at which it opens, and so may a named term (below) that opens later than its category. The data says which thing and which category belongs where; the app gives the stages their names and the rules below (src/domain/stages.ts). Data without them has everything at stage 0.may, the everyday categories its name leaves open: "a chair" may be wooden or red, so it is never used to show "furniture that is not wooden". It changes no relation, only which items may stand for a cell. An example has to say the quality its cell is about: a learner who writes "a car" for black things is asked to name it ("a black car"), with no verdict either way, and the tutor's lines do not settle it (src/domain/vague.ts). The knowledge base's build checks that every visible thing states its color, leaves the colors open or has a color that is none of the six ("a metal key"), and that every made thing does the same for its material. Temperature is the one quality taken as usual, "a blanket" being an ordinary one, except for a thing often heated in use ("a frying pan", "a cup of coffee"), which leaves "hot" open unless its name says hot or cold. "Electric" is said or absent.
contrasts lists pairs of items that belong together for a learner: an object and the mind that knows it ("the bark of a dog" and "hearing a dog bark"), or two minds of one act. The everyday categories are a closed world (two of them are mutually exclusive when no item is in both), so the knowledge base's build fails when a pair turns exclusive that was not read over by hand.
Stage 0 is everyday things alone, with no course term. Stages 1 to 9 bring the course's terms in three groups of three: form from outside (form, the eye's objects, the other senses), what things are made of and what exists (the elements, the established bases, the inner side of form and the minds), and minds and how things are known (the five sense minds, manifest and hidden phenomena, the two truths). Stages 10 to 12 are depth: chains of reasoning.
Every exercise draws from the stages the learner has switched on, any mix, at least one (the Stages section of the Progression page, with Natural progression off; rd-stages). A new device starts at stage 0. A device used before the stages keeps what it had: the levels of its reference examples (rd-exlevels, also from an import), or level 1, their default, become every stage up to that level's (level 1 is the whole ladder, to stage 9; stagesOfLevels), which leaves its pairs as they were; until its stages are changed, it also draws every pair alike as before (rd-stages-kept) and keeps Syllogisms on everyday things if it had chosen them (rd-syllogism-level). A device that started with the stages is marked (rd-ladder, kept on the device only), and stores its stages only once it chooses, so an import can still bring them. The rules are in src/domain/stages.ts:
- A category opens at its stage and stays open: it can be asked about once the highest stage that is on has reached it.
- On the Path a course term is asked about only after its stop has shown it (
src/domain/intro.ts), and each term of a stage is a segment of its ring. Some labels of a category name another course term, mutually inclusive with the category's own (the category'snamed: matter for form, external matter for external form, internal matter for internal form; manifest phenomenon, ultimate truth and specifically characterized phenomenon for functional things; conventional truth and generally characterized phenomenon for permanent things). Such a term shares the category and its questions, since their answers never differ, but it has a definition and divisions of its own: it gets its own stop and segment, right after the category's or at a later stage of its own (st: manifest phenomenon at 8, the two truths' names at 9), and its words wait out of the questions until then. A question that says one of them grades that term, and while it is open (met, its last answer not right yet), its category's questions say its words. - A wrong answer takes a term back to box 1: it is open again, and the questions lean to it until an answer on it is right. A wrong relation on a pair of two course terms counts against both, since the answer cannot say which was wrong. A definition does not come back by itself: the learner may ask for it on its stop (Show it again later), and every term met has its card on the Progression page.
- A thing is drawn when its own stage is on. A person, and what does not exist, meets the physical categories (Form, what is below it, and the everyday categories of forms) only from stage 5, where "a person is not its body" is taught; a mind may meet them from the start.
- A pair of categories is new at the highest of the categories' stages and, for each cell the whole data fills, the lowest stage of a thing in that cell (
pairStage), so the relation shown is always the true one and every cell has a thing the learner knows. Relations and Pervasions draw the pairs new at a stage that is on (poolAt), about half of them new at the highest one and the rest from below, and just after a stage was added its first few pairs lean to three possibilities (rd-stage-lean). Stages the practice list has nothing new at (9 to 12) draw from every pair. A cell's example is a thing of a stage that is on where the cell has one. - Categories asks about the practice items of the stages that are on and, where the device holds them, the reference examples of those stages, with the categories open there; a category an item's name leaves open (
may) is never asked. Up to stage 4 few of the wrong options are near misses. While the highest stage on has no things of its own (form, the elements, the five sense minds), the things of the stage below it are asked about its new terms. Every exercise counts, and a stage that brings new terms comes with the first of them instead, once the stage below has brought all of its own and fewer terms are open than the learner's pace allows (nextStageDueinsrc/domain/intro.ts); only a stage without new terms (stage 0), or one the learner chose to stay on, waits for the run. Its saved answers carry the thing'sstage. - Syllogisms keep to everyday reasons and predicates up to stage 4, with "Show the structure" on until it is switched off, and take the course's terms from stage 5. On the Path a share of them (a quarter while the exercise is new, then half) asks one of the stage's new terms that is not right yet, with the course's words at any stage; Find an instance leans to those terms the same way, and a right answer in either counts for the terms it used.
- Up to stage 4, a category that opened at the highest stage that is on shows its definition with the question, in Relations and Categories (where the device can read the definitions); from stage 5 on, the definitions are a tap away in the text.
- The negation track is offered on a result of Relations once the plain pairs go well (five right relations in a row), and both sides once the negated pairs do; it runs alongside the stages. On the Path it can be set from stage 2 and is offered from stage 3, while fewer course terms are open than the learner's pace allows.
- Stage 9 is the last stage of the ladder. Stages 10 to 12 are the layers of depth (one layer, two layers, three or more): they never come by themselves; a result offers the first once the last answer on each term of stage 9 is right and each next one after five right in a row, and the Difficulty section of the Progression page sets them.
- The tutor is told the learner's highest stage, in every exercise it explains: up to stage 4 it explains in everyday words, at stages 5 to 7 with the definitions, and from stage 8 as for the course.
The Magic Key is a few random words joined by dashes, for example lotus-river-candle-stone (four words from the EFF long word list: about 52 bits). It is typed or dictated with spaces, in any case, or arrives in the study group's link, after the #: https://<host>/#k=lotus-river-candle-stone (src/ai/magic-key.ts reads all of these the same way). It opens two things on the server: the definitions (GET /api/course) and the tutor (POST /api/tutor). A request proves that it has the key without sending it: HMAC-SHA256(key, "riglam/tutor-proof/1:" + device id) (SERVER.md).
Because the key is words, guessing is slowed by the server: a caller (a hash of its address, not stored) gets 30 wrong proofs per hour, after which the answer is "try later" until the next hour. A wrong guess costs nothing but the count.
| Where the key is | Why |
|---|---|
The study group's link, after the # |
Browsers never send the part after # to a server. The app takes the key out of the address at once and keeps it on the device (localStorage, riglam.magicKey), together with the definitions it fetched, so the definitions work offline and on later visits without the link. |
The Worker's secret RIGLAM_DATA_KEY (wrangler secret put) |
The server checks proofs against it. Without it, or with a value that is not the words of a Magic Key (the 43-character key of earlier versions), the tutor reports itself off and /api/course answers "not granted". |
The key never goes into the repository, a commit or pull request text, a comment, a log or the project's memory. tests/unit/data-files.test.ts fails if a tracked file holds a definition or a note in the clear, or, when the key is in the environment, the key itself.
A person with an account (docs/SERVER.md, "Accounts and sync") does not need to keep the words: a device that has the key makes its account carry it, and a device that signs in to that account gets it. After the key is changed, the devices of such accounts take the new one by themselves. Anyone who had the old key and made an account carries the new key too, so before changing the key because of a leak, look at every account that carries it (has_key = 1 in users), not only those made since the leak (an older account that showed the leaked key afterwards carries it too), and delete the ones that are not the group's.
The knowledge base keeps example notes: a thing, a representation, a relation, a negation, a combination of two things or a statement, each with the classes (terms) it is an instance of and is not, whether it exists, a level from 1 (a plain thing) to 4, how well the sources confirm it (confirmed in two or more, textbook, commentator), and sometimes a one-sentence gloss of why it is a good example. Its exporter writes them as one JSON file, {format: "riglam-examples", version: 2, sources: {id: {tier}}, items: [...]}, whose items have the keys n (name), al (aliases), cls, not, ne, lv, sc, k (kind), f (form), cf (confirmation), cn, inc, bg, gloss, and, for the server only, src (the places in the sources), web, base and mem (the members of a combination). The types are in src/ai-shared/examples.ts.
npm run data:import-examples -- <examples.json> checks the file against the open data (every class is a term, every item has a level and a source, no two have the same name) and writes it to data-private/examples.json, together with the device part, examples-device.json, which src/data/examples.js makes from it: the same items without src, web, base and mem, without aliases in Chinese or Tibetan script, with s, the ids of the sources an item is in (ids of the course tier, the reference texts, left out), and with the built stamp of the open data it was checked against. data:check and data:publish refuse a device part that was not made from the full one for this open data. The examples are optional: without them data:publish loads the definitions and notes only, and the app has no examples.
On the server, the tutor's lookup of an example (classify_example) falls back to the full part when the practice list does not have the thing, and a third tool, examples_of, gives it examples of a term (the term's own first, then those of its subclasses, up to a level it chooses, 2 unless the learner asks for harder ones, with the class each is an instance of, how well it is confirmed and why it is a good one), and a device with the Magic Key gets the device part from GET /api/course/examples (docs/SERVER.md). A device asks for it only after the definitions' check found the key fitting, in the background, and keeps it under riglam.examples with its own version; forgetting the key forgets it too. placeByClass (src/domain/reference.ts) places an example in a category by its classes alone: yes when the category's term is in its chain, no by an exclusion the data records or a class it is not, otherwise nothing.
The page reads the device part into state.EX and uses it in four places. The stop of a term shows up to three examples (cardExamples, src/domain/card-examples.ts): the everyday things of the practice list that are instances of the term or of a term mutually inclusive with it (everything is an existent, and so a hidden phenomenon), so that a learner meets "a dog" and "the roundness of a ball" and not the course's words (the term's own first, then the plainest stage, one of each branch below the term and then of each branch below those, the things only the course's words name last; Person is drawn by hand, a dog, a neighbor and an ant, because the list calls a cat and an ant alike "an animal"), each with its stage; the reference examples only fill what the list lacks, with the reason they are good ones on a tap. A term the list has nothing for shows reference examples only. An example's stage is its own st where the export gives one, else its level's: level 1 is stage 8, level 2 stage 10, and each level after it a stage up (exampleStage). The exporter numbers its stages by a ladder of nine (1 everyday things, 2 what is seen, 3 what is heard, smelled, tasted or touched, 4 the textbook's own things, what does not exist and minds, 5 a sense or mental consciousness, 6 the course's words, things named or glossed by them, 7 one step, 8 two steps, 9 more), and each goes to the stage that opens what it needs: 0, 2, 3, 5, 6, 8, 10, 11 and 12. The reference of a cell of a practice pair (the example shown for what the learner left empty or got wrong) may be one of them too (witnessesOf in src/domain/reference.ts, the more of pairOf): a confirmed or textbook example, of a kind a cell takes (a thing or a representation; a relation or a negation from stage 10 on; never a combination or a statement), without an expert background, of the stages that are on (above), whose cell placeByClass proves for both categories. The practice list still decides the relation and which cells are empty, so an example only joins a cell the list fills, and an example the list has under the same name is the list's. Categories draws some of the things it shows from them, from the same stages (drawPlace in src/domain/place.ts, the exercise in src/app/categories/). Find an instance checks a thing the learner names by them when the practice list does not have it (every example of that name, whatever the stages: gradeInstance in src/domain/instance.ts), and offers their names as the learner writes.
data-private/ (git-ignored) holds definitions.json and notes.json (and, where the examples were imported, examples.json and examples-device.json) on every machine that builds the artifact, runs the full tests or changes the data. The server holds the same two texts in the table course_data (worker/migrations/0003_course_data.sql), loaded by npm run data:publish. The Worker reads them at most once a minute, so new data needs no deploy.
Without data-private/: npm run build:pwa, the unit tests that do not need it, and the PWA specs that do not need it work. npm run build:artifact stops with a message, because an artifact built without definitions must never replace the live one.
- With the key (from the link, or kept from an earlier visit): the terms in the notes and in Claude's explanations that have a definition are dot-underlined, and a tap opens the definition in place (a term's higher categories in its card open the same way). The first unlock needs the network; the definitions are then kept on the device, and each later visit asks the server in the background whether they changed.
- Without it: the terms, translations and relations work and nothing greets the reader with the key. Terms have no underlines. The key is entered on the Magic Key page of Settings, which takes the words or the whole link (
takeKeyinsrc/pwa/unlock.ts). Explain shows grayed when the server has a tutor, and a tap opens that page, as do a flag, the Magic Key link in the roadmap's foot and the Magic Key row in Settings; it opens by itself only when a key went wrong at the start (a link whose key does not fit, a key that was changed), and says what. A key that does not fit is refused and not kept. A key that fits is taken into the running page with no reload (platform.onKey): the definitions and the tutor open, the pair and answer on the screen stay, and the page goes back to where it was opened; Explain or a flag, if that is what opened it, goes on. - A key the server stops accepting (after a change of the secret) is forgotten, together with the kept definitions, on the next visit with a connection; the visit after that opens the Magic Key page once, with a message that the key was changed.
- An app added to the iPhone home screen has storage of its own, separate from Safari, and a link cannot be opened inside it. Its dialog is the way in: type or paste the key there once.
- If the browser's storage is cleared, the app asks again.
npm run data:key # print a new Magic Key (four random words)
npm run data:import -- full.json # split a knowledge-base export into src/data/drill-data.json and data-private/
npm run data:import-examples -- examples.json # check the knowledge base's reference examples and write them, and the device part, into data-private/
npm run data:export -- full.json # the full data, definitions and notes put back
npm run data:check # check that the open file holds no definition or note and data-private/ matches it (every term needs a definition, the examples fit the open data; publish makes the same check)
npm run data:publish # load data-private/ into the production database, the examples too when they are there (wrangler; --config <file> for another database)
npm run data:sql -- out.sql # the statements publish runs, to load by other means
npm run data:fixture # write made-up definitions, notes and examples into data-private/ (refuses to overwrite real ones; --replace does)To refresh the data from the knowledge base (which lives outside this repository), export the full file there and run npm run data:import -- <that file>, then npm run data:publish. Files that did not change are not rewritten, and a part that did not change keeps its version on the server. D1 refuses a statement of more than about 100 KB and the examples are several times that, so a long part is written in pieces of at most 80 KB into a scratch row (<kind>~part) and moved into place with one short statement (scripts/lib/course-sql.mjs); a run that fails midway can leave the scratch row, which the next run overwrites, but never a half-written part. Never commit a file with definitions in it; npm run test:unit catches it.
CI never has the real course data. Before the build it runs npm run data:fixture, which writes invented definitions and notes for every term of the open data (scripts/lib/made-up-course.mjs): the same shape and about the same lengths as the real ones, Russian text included, a few terms without a Russian definition or with the "no definition in the reference" placeholder, notes on a quarter of the terms and on a third of the categories, and 80 invented examples whose classes are terms picked at random (with every field of the format, so that what the device part leaves out is tested). So the artifact build, the specs and the server tests run in full, and a log or a test report can show nothing that is not made up. The tests that read the real text (the real course data in tests/worker/kit.test.ts, the leak scans in tests/unit/data-files.test.ts, which also fail when a tracked file holds a gloss or more than five names of examples) pass on the made-up text too, and are worth running with the real data before publishing it (npm run check on a machine that has data-private/).
To change the key (a leak, or someone who should no longer open new versions): npm run data:key, wrangler secret put RIGLAM_DATA_KEY, hand out the new words or link. Devices that have the old key lose access on their next visit with a connection and ask for the new one, unless they belong to an account that carries the key. This does not take back copies already fetched.
It keeps the definitions out of search engines, link previews, the host's files, a scrape of the site and the repository. It does not stop someone who holds the key from copying what they can read, and it does not hide the open tier, which is meant to be shareable.