# Packaging lessons as SCORM (for LMS upload)

Instructors can load PhilMates lessons into any SCORM-capable LMS (Canvas,
Blackboard, Moodle, D2L/Brightspace, SCORM Cloud) as self-contained packages.

## Build

```bash
node tools/build-scorm.mjs --all                 # every lesson
node tools/build-scorm.mjs bioethics/four-principles   # one lesson
```

Output lands in `dist/scorm/<topic>-<lesson>-scorm12.zip`. Upload that `.zip`
to the LMS as a SCORM package — don't unzip it first.

## What the build does

For each lesson it produces a **single-SCO SCORM 1.2** package containing:

- the lesson's `index.html` (with `../../../shared/` paths collapsed to
  `shared/`, and the SCORM adapter injected before the engine),
- the lesson's `assets/`,
- a copy of `/shared` (engine, styles, fonts, and `scorm-api.js`),
- a generated `imsmanifest.xml`.

Authoring files (`prompts.md`, etc.) are excluded. The zip is written with a
small dependency-free writer, so no `npm install` is needed.

## How tracking works

Persistence is swappable by design. The live site uses a `localStorage`
`ProgressStore` ([shared/phil-core.js](../shared/phil-core.js)); the packaged
build installs `globalThis.PhilProgressStore` from
[shared/scorm-api.js](../shared/scorm-api.js) instead — same `visited` /
`correct` / `completed` / `beliefs` surface, but backed by the LMS.

| PhilMates state                       | SCORM 1.2 element            |
| ------------------------------------- | --------------------------- |
| `phil:complete` (all questions right) | `cmi.core.lesson_status` = `passed` |
| earned credit / total questions, best attempt | `cmi.core.score.raw` (0–100, also reported mid-lesson) |
| time in the lesson this session       | `cmi.core.session_time` (on exit; the LMS sums it into total time) |
| visited slides, correct, beliefs, wrong tries, credit, best score, finish time | `cmi.suspend_data` (resume) |

Notes:

- **Grade on the score, not the status.** `passed` means the student finished.
  The score is the earned credit. Each wrong try lowers what a question can
  still earn to 80% of the last (100%, 80%, 64% …). Checksets, cloze, and
  classify items are scored part by part on every check, and a miss says how
  many parts are wrong but not which. A check earns the share of parts right,
  with nothing taken off for wrong ones, since the lessons are formative. A
  student who guessed through still scores well below one who read.
  See "Scoring" in [AUTHORING.md](../AUTHORING.md).
- **Total time** in the LMS's activity report shows who clicked through in a
  few minutes.
- **Reset never raises a score; a retake can.** In a package, Reset clears
  slides and answers but keeps wrong-try counts and credit. A day after a
  student finishes, the button becomes **Retake**: a fresh attempt with wrong
  tries and credit cleared. The gradebook keeps the best attempt, so a worse
  retake never lowers it, and a `passed` lesson stays `passed`. The wait is
  `RETAKE_WAIT_HOURS` in `shared/scorm-api.js`; set it to `0` to allow a
  retake at once. It runs on the student's own clock, so a student who changes
  the computer's date can skip it.
- **Lessons finished before retakes existed** have no recorded finish time.
  Their retake opens at once.
- The manifest has **no `masteryscore`**. With graded credit, a mastery score of
  100 would let some LMSs mark finishers as `failed`.
- Progress saved before graded credit existed keeps full credit for questions
  already solved.
- SCORM 1.2 caps `suspend_data` at 4096 chars; the adapter stores question IDs
  (not labels) and warns in the console if a lesson approaches the limit.
- The `.xsd` schema files are intentionally omitted — every major LMS validates
  against its own built-in copies. Add them to the package root if a stricter
  importer ever requires them.

## To target SCORM 2004 or xAPI later

The seam is `scorm-api.js`. A 2004 or cmi5/xAPI adapter implements the same
store surface and reports to its own data model; the build would inject that
file instead. No lesson HTML changes required.
