reference: the full school

reference: the story, the full path, the measured repository and the chapter list

pong-typescript, one small game

You can read the whole game in one sitting. It still breaks in ways worth tracing.

This is a deliberately small generality demo. It teaches one shape of state and one frame loop without a framework or a package. The SageFS school is the substantial real-world example: a large codebase whose pages and evidence are held to thousands of source lines.

Pong's uneven frame times pour into a row of equal 1/120 second slices; a cap cuts the tail of a long pause
Pong's loop spends elapsed time in equal 1/120 second slices and drops the tail of a long pause. The drawing follows advance in update.ts.

one value, four jobs

The whole round lives in one Game value in state.ts: two paddles, a ball, an accumulator and a serve direction. Four files do one job each around it.

  • input.ts samples the keyboard once per frame and returns an Input value.
  • update.ts spends elapsed time in equal fixed slices and writes the fields: paddles, ball, collision, score.
  • draw.ts reads the same fields and returns drawing commands. It writes nothing.
  • main.ts wires the loop: sample input, advance the simulation, draw what it produced.

Input feeds update, update changes state, draw reads state. Nothing circles back, so every behaviour a reader chases has one home.

the ladder

The six rungs in levels.tsv name a depth of reasoning, a measure of independence and a share of responsibility. A junior grug explains what happens. A mid grug modifies one part safely. A senior grug predicts effects across parts. A staff grug owns the boundaries between parts. A principal grug weighs alternatives against the code. A distinguished grug asks whether the architecture should exist for the problem at hand. The curriculum walks all six rungs in that order, and each topic page carries the level it teaches.

The badge reads quiz answers. Every question carries a difficulty from 1 to 6. Two right answers at a rung and every rung below it prove that rung. Rungs 5 and 6 also need one declared transfer answer, a question that asks for a change, an effect or a judgment. Badge evidence is quiz answers at those difficulties. It does not by itself prove independence or responsibility.

the route

Junior grug: state-is-one-value · input-snapshot · draw-reads-state. Mid grug: fixed-step-loop · axis-separated-collision · scoring-and-serve. Senior grug: adr-plain-state · adr-fixed-timestep · adr-axis-collision. Staff grug: boundary-and-ownership. Principal grug: counterfactual-step. Distinguished grug: design-judgment.

start here

Read state-is-one-value, the floor of the school. The six modules are plain TypeScript with explicit types and no packages to install. Reading the lessons needs no build step. A reader who has a TypeScript compiler already on the machine can type-check with tsc --noEmit, and that check is optional.

how this school knows what it teaches

Every claim on a lesson page is anchored to a source line and settled by a proof fence: the page prints a command, the sandbox runs it with no network and no borrowed state, and the fence shows what the repository answered. Claims that could not be verified were left out. What the school keeps on record:

  • Nine reviewed rows in reviews.tsv, one per lesson from the first three rungs: each records a person checking the page's claims against the exact source file it cites.
  • A risk catalogue in risks.md with 21 failure modes judged against the code: 0 fully handled by a six-file game, 4 partially answered, 2 left open, and 15 proved not applicable with an absence proof. Uncertainty stays visible there: the two open items say what would settle them.
  • A reason beside every quiz answer in the quizzes/*.why.md sidecars. The check refuses a question whose answer carries no reason, so a learner who guessed wrong gets the reason for the right answer.
  • Answer counts kept current by the engine: quizzes, citations, fences and coverage are re-read on every build, so a lesson whose source moved stops passing grugschool check ..

try it

One decision: read the accumulator in update.ts before you change any speed constant.

the path through the cave

this is the order a reader needs. a page that says learn first must be read before the page that names it.

junior grug (level 1 of 6) (3 topics)
flowchart TB
  subgraph L1["junior grug (level 1 of 6)"]
  direction TB
  T1["1 one value holds the round"]
  T2["2 one keyboard snapshot per frame"]
  T3["3 draw reads, update writes"]
  end
  T1 --> T2
  T2 --> T3
  click T1 href "state-is-one-value.html" "one value holds the round"
  click T2 href "input-snapshot.html" "one keyboard snapshot per frame"
  click T3 href "draw-reads-state.html" "draw reads, update writes"
        
mid grug (level 2 of 6) (3 topics)
flowchart TB
  subgraph L2["mid grug (level 2 of 6)"]
  direction TB
  T1["4 time arrives in equal slices"]
  T2["5 two collision passes, two answers"]
  T3["6 a goal changes one score, then waits"]
  end
  T1 --> T2
  T2 --> T3
  click T1 href "fixed-step-loop.html" "time arrives in equal slices"
  click T2 href "axis-separated-collision.html" "two collision passes, two answers"
  click T3 href "scoring-and-serve.html" "a goal changes one score, then waits"
        
senior grug (level 3 of 6) (3 topics)
flowchart TB
  subgraph L3["senior grug (level 3 of 6)"]
  direction TB
  T1["7 why the state is one plain object"]
  T2["8 why the loop pays for a fixed step"]
  T3["9 why collision keeps two passes"]
  end
  T1 --> T2
  T2 --> T3
  click T1 href "adr-plain-state.html" "why the state is one plain object"
  click T2 href "adr-fixed-timestep.html" "why the loop pays for a fixed step"
  click T3 href "adr-axis-collision.html" "why collision keeps two passes"
        
staff grug (level 4 of 6) (1 topic)
flowchart TB
  subgraph L4["staff grug (level 4 of 6)"]
  direction TB
  T1["10 who owns what"]
  end
  click T1 href "boundary-and-ownership.html" "who owns what"
        
principal grug (level 5 of 6) (1 topic)
flowchart TB
  subgraph L5["principal grug (level 5 of 6)"]
  direction TB
  T1["11 change one rule, follow the result"]
  end
  click T1 href "counterfactual-step.html" "change one rule, follow the result"
        
distinguished grug (level 6 of 6) (1 topic)
flowchart TB
  subgraph L6["distinguished grug (level 6 of 6)"]
  direction TB
  T1["12 when this shape stops fitting"]
  end
  click T1 href "design-judgment.html" "when this shape stops fitting"
        
the same path as a plain list of links
  1. one value holds the round junior grug (level 1 of 6)
  2. one keyboard snapshot per frame junior grug (level 1 of 6)learn first: one value holds the round
  3. draw reads, update writes junior grug (level 1 of 6)learn first: one value holds the round
  4. time arrives in equal slices mid grug (level 2 of 6)learn first: one value holds the round
  5. two collision passes, two answers mid grug (level 2 of 6)learn first: time arrives in equal slices
  6. a goal changes one score, then waits mid grug (level 2 of 6)learn first: two collision passes, two answers
  7. why the state is one plain object senior grug (level 3 of 6)learn first: one value holds the round
  8. why the loop pays for a fixed step senior grug (level 3 of 6)learn first: time arrives in equal slices
  9. why collision keeps two passes senior grug (level 3 of 6)learn first: two collision passes, two answers
  10. who owns what staff grug (level 4 of 6)learn first: one value holds the round, one keyboard snapshot per frame, draw reads, update writes, why the state is one plain object
  11. change one rule, follow the result principal grug (level 5 of 6)learn first: time arrives in equal slices, why collision keeps two passes, why the loop pays for a fixed step, two collision passes, two answers, a goal changes one score, then waits
  12. when this shape stops fitting distinguished grug (level 6 of 6)learn first: why the loop pays for a fixed step, why the state is one plain object, time arrives in equal slices, why collision keeps two passes

what grug found in the repo

grug read the repo before anyone wrote a topic. The numbers here come from the files. There are 1 project in 1 language. the lay of the land shows what each one measures and where they meet.

open the measured diagram and the size contrast
..TypeScript, 6 files214 lines6 loose scripts beside the projects

one chapter for each project: 1 chapter below

grug writes these with no author, from the files alone, and rebuilds them when the files change. Each chapter says what the project holds, in what order to read it, who uses it and what it uses. The topics explain why the code has this shape. Every chapter below is in the search too.

open the list of all 1 measured chapters
  • ., TypeScript, 6 source files: Input is a snapshot of the keys at one frame. Nothing else in the game reads a key.

what goes wrong for this kind of app

every app of this kind must answer the same hard questions: what happens when the network goes, when the same request arrives twice, and who may do what. The catalog names each question, says what this codebase answers, and says plainly when there is no answer. 0 answers in code, 4 partial, 2 missing, 15 not applicable. read the list.

what the levels mean

these are the six rungs of the cave. a page carries the badge of the rank it teaches.

this badge records quiz answers with a difficulty from 1 to 6. it does not measure independence or responsibility.

  1. junior grug (level 1 of 6) follow a worked trace and say what the code did
  2. mid grug (level 2 of 6) say why one file has its shape and what breaks if it changes
  3. senior grug (level 3 of 6) trace a path through the system and name the parts it joins
  4. staff grug (level 4 of 6) predict how a change in one part shows up in another
  5. principal grug (level 5 of 6) judge a claim against the code and a proof
  6. distinguished grug (level 6 of 6) teach the shape of the system to another grug and change it without breaking what sits next to it

how to learn in the cave

  1. read this page first, then walk the path above from the top. earlier topics make later ones easy.
  2. Every topic ends with questions. Say the answer out loud first, then tap. grug remembers what you miss and asks again in the pop quiz.
  3. press / on any page to search every topic.
  4. when a topic page shows a demon watch box, grug measured the file it explains. The enemy is the complexity spirit demon, worse than a t-rex, because grug can see a t-rex. The box only tells you where to look, so open the file and look.
  5. You know a topic when you can explain it to another grug and change it without breaking what sits next to it.

back to the school