Skip to content

feat(modules): Add Folders and Repo Sourced Lessons - #36

Merged
mathewdunne merged 7 commits into
mathewdunne:mainfrom
eprig:eprig/add-git-modules
Nov 25, 2026
Merged

mathewdunne merged 7 commits into
mathewdunne:mainfrom
eprig:eprig/add-git-modules

Conversation

@eprig

@eprig eprig commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends the lesson catalog beyond "a subdir in one catalog repo". A module can
now be sourced from its own public GitHub repository, and the catalog modules
array can be a recursive tree of folders and modules. The Switch Project picker
renders that tree as collapsible, multi-level sections.

Closes the gap that made premade curricula (e.g. FRCSoftware.org, where each
stage is a separate repo) impossible to express without duplicating them into a
team's catalog.

Changes

Contracts (packages/contracts/src/index.ts)

  • lessonModuleSchema now accepts exactly one source: subdir (existing) or
    repo (new). repo accepts https://github.com/owner/repo(.git) or
    owner/repo shorthand; schemas are strict and cross-validate:
    • both or neither of subdir/repo is rejected;
    • preserveGit: true is rejected without repo.
  • preserveGit defaults to false. With repo, it keeps the shallow clone's
    .git (history and origin) in the student workspace; otherwise .git is
    removed as before.
  • Added lessonFolderSchema (folder, optional description, order,
    recursive modules) and lessonCatalogEntrySchema (module or folder).
    Folder names are trimmed, 1–80 chars, single path segment (no /, \, or
    control characters).
  • lessonCatalogSchema / lessonCatalogResponseSchema now use the entry union
    and validate the whole tree: module ids unique globally, folder names unique
    among siblings, repeated ids/duplicate folders reported with full paths.
  • Added isLessonFolder(), flattenLessonModules() (depth-first), and the
    LessonCatalogEntry, LessonFolder, LessonFolderName, LessonModuleRepo
    types.

Control plane

  • catalog.ts: sorting is now recursive by order at every level; folders and
    modules share one ordering scale, array order only breaks ties. Module lookup
    flattens nested folders so /api/lessons/load resolves ids anywhere in the
    tree.
  • app/websocket.ts: forwards subdir, repo, and preserveGit to the
    lesson-load context (subdir may now be null).
  • imports.ts: added normalizeCatalogModuleRepo() (reuses the GitHub-only
    URL parser used by team imports). Catalog loads now:
    • shallow-clone a repo module's root (git clone --depth 1, argv, no shell);
    • keep the sparse-clone path for remote-catalog subdir modules and the
      copy path for bundled modules;
    • reject modules with ambiguous/missing sources;
    • drop .git except for repo modules with preserveGit;
    • retain size cap, empty-root validation, workspace swap, editor cache clear,
      and current_module recording.

Web (apps/web)

  • useLessons() and lib/contracts.ts now carry the recursive
    LessonCatalogEntry type and folder helpers.
  • SwitchProjectDialog: recursive rendering of folders with expand/collapse
    chevrons, optional folder descriptions (visible when collapsed), and module
    counts. Collapse state is keyed by folder path and resets on catalog change.
  • New module-groups.ts helpers: grouping consecutive modules into grids,
    counting modules in a subtree, checking for the current module, and numbering
    modules depth-first in render order.

Docs

  • AGENTS.md: updated Lessons & Modules overview.
  • New decision logs: 049-repo-sourced-lesson-modules.md and
    050-module-folders.md (both Accepted); indexed in docs/decisions/README.md.
  • Updated docs/lessons/authoring-modules.md (manifest format, repo,
    preserveGit, folders) and docs/lessons/overview.md.

Tests

  • Contracts: schema/property coverage for repo validation, preserveGit,
    folder trees, duplicate detection, and flattenLessonModules.
  • Control: catalog sorting/lookup, imports (clone, .git handling, validation),
    lesson routes, and path-traversal security.
  • Web: SwitchProjectDialog folder tree interactions plus new
    module-groups.test.ts.
  • scripts/catalog-integrity.test.ts: manifest parses against the new schema.

Compatibility / notes

  • schemaVersion stays 1; existing subdir modules and bundled catalogs need
    no changes.
  • Clients must use the updated shared contracts — the /api/lessons modules
    field is now a union array.
  • Repo modules use the default branch only; a different revision must be
    published there.
  • Empty folders validate but are skipped in the picker.
  • Catalog loads remain gitless by default and are intentionally a discard +
    reload (no server-side backup); preserveGit is opt-in for repo modules.

Disclaimer

This PR was written by opencode's big pickle model including the change log. I'm open to suggestions for changes because of my limited knowledge of this project.

@eprig
eprig marked this pull request as ready for review November 20, 2026 03:09
@eprig

eprig commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@mathewdunne Could you take a look at this please?

@mathewdunne

Copy link
Copy Markdown
Owner

@eprig sorry, I didn't see this until you tagged me (my GitHub notifications clearly aren't set up properly), I'll try to fix it tomorrow

@mathewdunne

Copy link
Copy Markdown
Owner

@eprig was removing the lesson numbers intentional? I kind of like having them, so if you don't mind, I'll push another commit to this branch adding them back?

There are a couple other minor bugs claude flagged, I can fix those as well. For the most part looks good though!

@eprig

eprig commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Yes removing the numbers was intentional, mainly because they can get split across folders. I can see it being useful when having individual lessons, but when there are multiple folders it can get messy.

- Treat a repo module clone holding only .git as empty, so an empty
  repository fails the load instead of replacing the project with nothing.
- Ignore unknown keys on modules and folders again, and pick the folder
  or module schema by the presence of `folder` so errors point at the
  failing field instead of a vague union error.
- Show "No lessons are available yet." when the catalog has only empty
  folders.
- Log the module repo as cloneUrl for repo-module loads.
- Correct the comment on why catalog loads are not rate-limited.
- Reject dot-only owner/repo segments such as `../x` in module repos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mathewdunne

mathewdunne commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Yes removing the numbers was intentional, mainly because they can get split across folders. I can see it being useful when having individual lessons, but when there are multiple folders it can get messy.

@eprig Thoughts on this approach?
Lessons are numbered only in lists that contain no folders, so a flat catalog shows 1, 2, 3 as before, and each folder holding only lessons numbers its own lessons from 1. A list that mixes lessons and folders has no numbers, so a number never jumps across a folder.

If you're okay with that I'll implement it and then merge. I also have a fix ready for these minor bugs:

Item Fix
1 Don't count .git when checking whether a repo module's clone is empty, so an empty repo fails instead of loading as a blank project. Add a test for it.
3 Remove .strict() from modules so stray keys are dropped again. Use whether an entry has a folder key to tell folders from modules, instead of relying on the strict check failing. Add a test that an extra key still loads.
4 Show "No lessons are available yet." whenever there are no modules, even if empty folders exist (use countCatalogModules(modules) === 0). Add a test.
5 Make the "import started" log name the module's repo when one is being cloned.
6 Fix the out-of-date comment only; rate limiting stays as it is.
7 Reject . and .. as the owner or repo name in the owner/repo shorthand. Add a test.

@eprig

eprig commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Sounds good 👍

mathewdunne and others added 2 commits November 25, 2026 15:26
A flat catalog counts 1, 2, 3 as it did before folders, and a folder
holding only lessons numbers its own from 1. A list that mixes lessons
and folders stays unnumbered, so a number never jumps across a folder.
Hidden empty folders do not count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mathewdunne
mathewdunne merged commit 84de3a6 into mathewdunne:main Nov 25, 2026
1 check passed
@eprig
eprig deleted the eprig/add-git-modules branch November 25, 2026 20:47
@mathewdunne

Copy link
Copy Markdown
Owner

@eprig v6.10.0 has the changes, feel free to let me know or raise another PR if you have any other issues!

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.

2 participants