Skip to content

Add eight general-purpose learning blocks (architecture, charts, role-play and more) - #358

Merged
AQIB-NAWAB merged 1 commit into
mainfrom
feat/interactive-learning-blocks
Dec 3, 2026
Merged

AQIB-NAWAB merged 1 commit into
mainfrom
feat/interactive-learning-blocks

Conversation

@AQIB-NAWAB

Copy link
Copy Markdown
Collaborator

What this adds

Eight new portable canvas renderers that any course can use, not only tech courses. Authors write each one as a ```canvas fence with plain YAML or JSON. The chapter is stored in the database as text, so every block is stored as code, never as a picture.

Renderer What it is for What the learner does
architecture System diagrams: parts, arrows, networks inside networks Taps a part to see what it does and what it connects to, drags parts, turns traffic dots on or off
chart Pie, bar and line charts for research and finance lessons Reads it (view mode), or guesses the hidden values and then reveals them (guess mode)
guess-reveal Commit to a number before seeing the answer Moves a slider, locks the guess, sees the gap and the explanation
scale-picker Teaching "how much": tone, effort, detail, risk (works for fitness, writing, ops) Explores each point on the scale, then picks the best one for a situation
log-explorer Finding the cause in a log Filters by level, searches, taps the line, checks the answer
command-explainer Reading a command part by part Taps a part or uses the arrow keys, or presses "Explain all"
role-play Practising a conversation (customer, manager, patient) Picks replies in a branching chat; optional read aloud and answer by voice
self-check-cards Recall practice Flips a card, marks "I knew it" or "Not yet", reviews only the misses

The step-by-step diagram we also discussed is not added: a ```flow fence with a packet: line already steps through with Back and Next.

The architecture canvas, in more detail

  • AI writes code, not a PNG: the course agent (or an author) writes nodes, edges and groups. Groups can sit inside groups, for example a VPC that contains subnets. A typical diagram is 1 to 2 KB of text, and it can be searched and edited.
  • Same icons as the labs: the icons come from the design lab's Glyph set, so diagrams and labs look the same. There are 17 part types plus external.
  • Automatic layout: columns follow the arrows, and parts of one group stay together. Cards grow to fit their names, so text never leaves a card.
  • Phone layout: when the panel is too narrow to read left to right, the diagram switches to top to bottom. Parts outside a group are pushed clear of the group's border.
  • Dragging: dragging a part, or Shift + arrow keys, moves it. "Copy code" gives the author the same diagram with x and y filled in, ready to paste into the chapter.
  • Checked before it draws: an arrow to a part that does not exist, an id used twice, a part in two groups, or a group inside itself is refused. The reader then shows the quiet fallback, never a half-drawn diagram.

How it fits the existing code

  • Each renderer follows the flip-deck pattern:
    • models/<name>.ts holds the zod schema with .passthrough(), a check<Name>() function with plain-English problems, and pure state functions.
    • primitives/<name>.tsx holds the component, inside BeatFrame.
    • primitives/<name>.spec.md holds the spec.
    • frontend/tests/unit/canvas/<name>.test.ts holds the tests.
  • Registration:
    • PORTABLE_CANVAS_RENDERERS in models/portable.ts, which also re-exports each schema.
    • The InteractiveCanvas switch. Each new case runs the schema, then the cross-checks, before it renders.
    • PORTABLE_CANVAS_RENDERER_NAMES in server/src/shared/mdx/canvas-tags.ts, synced to frontend/src/shared, so publishing accepts the new names.
  • packages/learning-ui/package.json gets export entries for the 16 new files.
  • Rules followed: theme-aware Tailwind tokens only (no hex), no SMIL <animate> (the traffic dots reuse FlowPulse), 44px targets, polite live regions, prefers-reduced-motion, and amber (never red) for a wrong answer.

Docs and preview

  • docs/interactive-learning-blocks.md: an author guide with a copyable example for each renderer.
  • /zz-learning-blocks: a dev page with no login, like /zz-diagram-gallery. Every example goes through the real chapter pipeline.
  • learning-blocks-docs.test.ts: parses every example in the guide and on the dev page with the real schema and checks, so the docs cannot drift from the code.

Testing

  • Frontend: pnpm vitest run passes 202 files, 5,124 tests (3 skipped). tsc --noEmit reports 0 errors. ESLint is clean on the new frontend files.
  • Server: the MDX tests pass, including 2 new canvas-tags cases. tsc --noEmit reports 0 errors after prisma generate. sync-shared:check reports the copy is in sync.
  • Browser (Chrome via Playwright, on /zz-learning-blocks):
    • All 9 examples render at 1280px, at 390px, and in dark mode, with no console errors.
    • The page is 390px wide at 390px, so nothing scrolls sideways. Long log lines scroll inside their own pane.
    • Clicked through each renderer: chart reveal, guess lock, scale pick, log check, command part, role-play reply to ending, card flip and grade, and architecture select and drag.

Not tested, or open

  • Voice in role-play: the microphone and speech output were not tried by hand in Chrome or Safari. Both are feature-detected and hidden when the browser lacks them.
  • Screen readers: not checked with a real screen reader. Labels and live regions exist and are covered only by server-render tests.
  • Server-side data checks: the publish check (courses:check) validates the renderer name, title and limits, but not the full data schema. The schemas live in packages/learning-ui, which the server does not import. Bad data is caught in the reader and shows the quiet fallback. Moving the schemas into server/src/shared would let publishing refuse bad data too. That could be a follow-up.
  • Existing server test: remark-learning-log.test.ts fails locally with "Invalid environment configuration", because it needs a server .env. It is not related to this change.
  • Agent IP: the course-writing guide in the separate agent-IP repo is not updated yet.

🤖 Generated with Claude Code

New ```canvas renderers any course can use: architecture, chart,
guess-reveal, scale-picker, log-explorer, command-explainer, role-play
and self-check-cards. Each has a zod schema, cross-checks, pure model
functions, a theme-aware component in BeatFrame, a spec and tests.

- architecture: a system diagram written as data (parts, arrows, nested
  groups) with the design lab's icons; tap for details, drag to move,
  Copy code writes x and y back; left to right, or top to bottom when
  the panel is narrow.
- chart: pie, bar or line, view only or guess then reveal.
- Registered in PORTABLE_CANVAS_RENDERERS, InteractiveCanvas (schema
  and checks before render) and the publish check's renderer list.
- docs/interactive-learning-blocks.md and the /zz-learning-blocks dev
  page; a test keeps every example valid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AQIB-NAWAB
AQIB-NAWAB merged commit 3cd2cc7 into main Dec 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant