diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..b69f8508 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,28 @@ +name: Docs + +# The docs held to the code (design/build.md), on every pull request and push to main, whatever it +# changes: ci.yml starts no run for a change to the docs alone. + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + # package.json names pnpm, which the action would look for to cache its store. + package-manager-cache: false + # No install: the script needs Node and git alone. + - run: node scripts/docs.mjs diff --git a/.gitignore b/.gitignore index 7bcd415f..17d686cb 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ coverage # local agent skills .agents/ +.claude/ skills-lock.json # Generated by the runtime's build from its stylesheet's font list; `pnpm build` in packages/runtime. diff --git a/ACCESSIBILITY.md b/ACCESSIBILITY.md index 5543d4e5..8eac3cf9 100644 --- a/ACCESSIBILITY.md +++ b/ACCESSIBILITY.md @@ -12,9 +12,10 @@ keyboard-only run found. | The player (``) | one iframe and no controls of its own: whether focus can get into the content and out again, the frame's accessible name, fullscreen, how failures are reported | this project | | The content type | every control, label, focus order, keyboard interaction, live region, caption and colour inside the frame | H5P, per content type and **per library version** | -The player does not change the content's markup: it serves the files in the package to the -H5P runtime unmodified. A content type behaves the same here as it does on h5p.com, Moodle or -WordPress with the same library version. H5P's own +The player serves the files in the package to the H5P runtime unmodified. Played untrusted, the +default, the content goes through the check an H5P site runs on it, which strips the markup its +libraries' semantics do not allow. A content type behaves the same here as it does on h5p.com, +Moodle or WordPress with the same library version. H5P's own [accessibility report](https://h5p.com/pdfs/h5p-vpat-april-2026.pdf) and [content-type recommendations](https://help.h5p.com/hc/en-us/articles/7505649072797-Content-types-recommendations) are the reference for that part. They cover the content types upgraded to H5P's new look and diff --git a/AGENTS.md b/AGENTS.md index 215801b8..ebf797fd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -72,10 +72,12 @@ The player, by area: Across the repository: build shape, types, publishing and Node versions (22 LTS or 24 LTS) in [`design/build.md`](design/build.md), with the two rules for writing: **a comment is two lines at -most, and says why** (`pnpm comments` checks it), and **a doc is short, and true to the code**; tests and CI in [`design/testing.md`](design/testing.md); -licensing and names in [`design/licensing.md`](design/licensing.md), where the player is MIT and -carries no GPL code, reaching `@missing-elements/h5p-runtime` only over HTTP and `postMessage`; what -is not built yet in [`design/scope.md`](design/scope.md). +most, and says why** (`pnpm comments` checks it), and **a doc is short, and true to the code** +(`pnpm docs:check` checks what a script can read, and the +[`docs-check` skill](skills/docs-check/SKILL.md) reads the rest after a change); tests and CI in [`design/testing.md`](design/testing.md); licensing and names in +[`design/licensing.md`](design/licensing.md), where the player is MIT and carries no GPL code, +reaching `@missing-elements/h5p-runtime` only over HTTP and `postMessage`; what is not built yet +in [`design/scope.md`](design/scope.md). ## Commands @@ -91,6 +93,7 @@ pnpm test:unit # fast, no browser pnpm test:browser pnpm typecheck # every package pnpm lint # oxlint with type-aware rules; after typecheck +pnpm docs:check # where a doc and the code disagree; --changed lists the docs to read again pnpm build # the player: types, element, both workers; builds the runtime package on the way pnpm verify course.h5p # play a package in a headless browser and report whether it works pnpm author build source.json course.h5p # after pnpm build, or the player's build:plan diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fd529648..7385ec1a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,6 +40,7 @@ pnpm test:browser pnpm typecheck pnpm lint # after typecheck, whose declarations it reads pnpm comments # a comment is two lines at most +pnpm docs:check # the docs say what the code does pnpm build ``` diff --git a/apps/skills/tests/front-matter.test.ts b/apps/skills/tests/front-matter.test.ts index 6190610d..68890fd4 100644 --- a/apps/skills/tests/front-matter.test.ts +++ b/apps/skills/tests/front-matter.test.ts @@ -15,13 +15,17 @@ describe("the skills' front matter", () => { const front = /^---\n([\s\S]*?)\n---\n/.exec(text)?.[1] expect(front, 'front matter between two --- lines').toBeDefined() const fields = new Map() + let nests = false for (const line of front!.split('\n')) { - const [, key, value] = /^([a-z-]+): (.+)$/.exec(line) ?? [] + // `metadata:` opens a map of indented lines: its `internal` keeps a skill out of an install. + if (line === 'metadata:') { nests = true; continue } + const [, indent, key, value] = /^( {2})?([a-z-]+): (.+)$/.exec(line) ?? [] expect(key, `"${line.slice(0, 40)}" is a key and a value`).toBeDefined() + expect(!indent || nests, `${key}: an indented line belongs under metadata:`).toBe(true) expect(value, `${key}: a colon followed by a space or the line's end ends a plain value`).not.toMatch(/:(?: |$)/) expect(value, `${key}: a space followed by # starts a comment`).not.toMatch(/ #/) expect(value, `${key}: a plain value cannot start with an indicator`).not.toMatch(/^[-?:,[\]{}#&*!|>'"%@`]/) - fields.set(key, value) + if (!indent) fields.set(key, value) } expect(fields.get('name')).toBe(name) expect(name).toMatch(/^[a-z0-9]+(?:-[a-z0-9]+)*$/) diff --git a/design/build.md b/design/build.md index b5867612..875cfa7d 100644 --- a/design/build.md +++ b/design/build.md @@ -173,10 +173,115 @@ checkout, run `pnpm typecheck` first. ## Docs -**A doc is short, and true to the code** (#289). The READMEs, `docs/` and the demo's pages are for -people integrating the packages: what to do and what happens, with no history and no retelling of -this folder. Every claim is checked by running the command or reading the source; where a doc looks -wrong, the code settles it, never a comment or this folder's account of it. +**A doc is short, and true to the code** (#289). The READMEs, the licence notices, `docs/` and the +demo's pages are for people integrating the packages: what to do and what happens, with no history +and no retelling of this folder. Every claim is checked by running the command or reading the +source; where a doc looks wrong, the code settles it, never a comment or this folder's account of +it. + +**The docs come from the code, never the other way round.** A doc that disagrees with the code is +changed. Code that looks wrong is reported and left alone: a sentence in a doc is not evidence of +what the code should do. + +**`pnpm docs:check` holds the docs to what a script can read from the code** (#350). +`scripts/docs.mjs` lists each place where they disagree, and `docs.yml` runs it on every change, a +change to the docs alone included, which `ci.yml` starts no run for. It needs Node and git, no +install. It checks that: + +- a link into the repository reaches a file, and its fragment a heading there; +- no file names the repository as it was before its rename; +- every package is in the README, `SECURITY.md`, both issue templates and `AGENTS.md`, and a count + of the packages and apps is right; +- a `pnpm` script, a package of ours or a skill that a doc names exists; +- a command's README and its usage text name the same options; +- `docs/libraries.md` and the embed command give the pack's sizes as `parts/index.json` has them; +- a version a doc or a page pins one of our packages at is the one its `package.json` has, so a + bump changes the pins in `docs/setup.md`, the runtime's README and the demo's setup page in the + same commit. A pin on main then names a version npm does not serve until `publish.yml` has run; + by hand, the pins were left a version behind twice in a month (2564304, 950f152); +- `docs/api.md` names every attribute the element reads, and every state, progress phase and + error code. + +It skips vendored code, build output and the changelog. The skill's type files are read, since +only their second half is generated and the first is written by hand. A check +that can no longer read its source, as when a type is renamed or a file moved, is a miss that +names it, never a pass. + +**What a script cannot read, a reader checks, against the sources `scripts/docs.json` gives each +doc.** The map names, for every README, `docs/` page, policy and skill, the files that decide what +it says: a path, a path ending in `/` for all below it, or `*` for one name. The check fails for +such a doc with no entry and for a path that is gone, so the map cannot go stale unseen. +`pnpm docs:check --changed [commit]` lists each source a change touched since the branch left +`origin/main`, or since the commit given, tests left out, with the command that shows its change +and the docs that describe it. A change already pushed to main is not after that line, so an +answer of nothing names the commit it looked from. With no `origin/main` and no commit given it +refuses, since `HEAD` in its place would answer nothing for a branch's commits. `--all [doc...]` +lists every doc with its sources, or the docs named, and refuses a name the map has no doc for. +The reading itself is the `docs-check` skill, in `skills/` beside the +ones for people integrating the packages, since `.claude/` is each person's own and not in the +repository: each finding cites the line of source that decides it, and is checked a second time +before a doc is changed. A copy of a claim under `design/` is reported, not changed, since there +the design may be what is right. The skill is marked `metadata.internal`, since `npx skills add` +offers what `skills/` holds: `skills` 1.10.1 offers it to people integrating the packages without +the mark, and with it only when asked for by name. + +**A scan goes one doc at a time, each finished before the next.** Every doc with its sources is +292 KB of docs and 1.6 MB of code, more than one reader holds at once, so the skill's scan reads, +checks and changes a doc before it opens the next, and takes the docs to scan by name. A scan of +the whole repository is several such scans, a package or a folder each. + +The reasons, from 2026-12-04. Two scans by hand found 9 stale claims and then 15 more, so a scan +finds what it happens to read; the second reading is there because 4 of those 15 were wrong. The +script checks what both scans checked by hand each time: links, names, lists, options and sizes. +Phrases of history ("up to 0.9", "no longer") stay with the reader: a pattern for them flagged 16 +lines, 7 of them wrongly (another library's version, "loaded now") and the other 9 kept on purpose. + +The skill's wording was measured on the weakest model, in a clone seeded with a changed default, +a changed option default and a removed option, beside a refactor nobody could notice, and scored +by the files each run left. Two wordings: + +- Docs first, each with its sources, and a finding dropped where the code looked wrong. Of 2 + runs, one read the docs of one source and passed over the six of the other; both left the check + failing over an option that the seed declared and never read, which they judged unfinished. +- Source by source, a line for each change a person could notice before any doc is read, a line + for each doc read, and the code never judged. 2 of 2 changed all five docs, left the copy under + `design/` and the code alone and ended with the check passing, in 22 and 32 tool calls. The + refactor changed nothing under either wording, in 5 tool calls and then 4. + +A third round measured the commit to look from and the scan. The same change left uncommitted, +and committed and pushed and asked of as "my last commit", had all five docs changed each time, +in 24 tool calls. Two scans of five named docs, seeded with four wrong numbers and a sentence of +history, with one doc left clean, each put the five right, in 45 and 58 tool calls. One of them +changed two claims more, both true to the code and neither seeded: a statement released while +the page is hidden carries no revision, and the message for a package missing some of its +libraries. + +The map was held against the history: 203 times a `feat`, `fix` or `perf` commit changed a doc +beside code, four docs at most. The code was a source the map gives that doc in 163 of them, and +in 172 once the sources that showed were added: the runtime's boot script for the API and resume +pages, the element for `docs/untrusted.md`, the author's library for both MCP servers. The other +31 are version numbers, folders since moved and docs changed in passing. + +The docs those tests had not read were then scanned whole: ten scans of one to seven docs each, +21 to 56 tool calls a scan. Four found nothing. The other six raised 20 findings, each then held +against its source line by hand. 14 were drift and are fixed: a title's limit in bytes and not +characters, media formats a list left out, an encrypted entry said to be noted where it stops the +run. Five were history, and four of them went, the notices' too. The fifth stays, since it says +what happens now: npm on an older Node still installs an embed from before 1.0. One finding said +the same as the doc in other words, and was dropped. Two scans named sources the map lacked for a +doc, since added. + +A review of the pull request raised 14 comments, 11 apart from repeats, and ten held. The check +took `1.2 MB` as said by a line saying `11.2 MB`, `--all` passed over a name the map lacks, and +`--changed` answered nothing where `HEAD` stood in for a missing `origin/main`. Three docs gave +the normalizer's `revision` as the whole of `context.revision`, which the libraries' part follows, +and two said a damaged entry stops a run that never reads it. The skill's first step said to +change the file a line names, and a line can name code: with a pack size seeded, a run on the +weakest model changed the doc, left the embed command's usage text and reported it, in 23 tool +calls. The eleventh asked for a run on every branch's push, which checks a pull request twice. +Its second review held three more: the skill's type files were out of every check, so a change to +the author's media list listed none of the four that name its formats; a map that has moved, and +a fragment such as `#%`, stopped the check with a stack trace. **The README shows the product in pictures, each one re-made when what it shows changes.** They are in `docs/media/`. Those of the site's pages, `player.png` and `scorm.png`, are rendered from the diff --git a/design/commands.md b/design/commands.md index 535938bb..da719d22 100644 --- a/design/commands.md +++ b/design/commands.md @@ -13,10 +13,13 @@ pnpm dev # vendors assets, builds fixtures, serves the demo on :51 pnpm test # every package: the player's unit + browser suites, the normalizer's and verifier's tests pnpm test:unit # fast, no browser pnpm test:browser -H5P_TEST_BROWSER=firefox pnpm test:engine # the player's browser suite and the app's tests in - # Firefox, or webkit; after `playwright install firefox webkit` in the player +H5P_TEST_BROWSER=firefox pnpm test:engine # the player's browser suite, the app's tests and the journeys + # in Firefox, or webkit; after `playwright install firefox webkit` in the player pnpm typecheck # every package pnpm lint # oxlint, with its type-aware rules, after the type check: design/build.md +pnpm comments # every comment past two lines: design/build.md +pnpm docs:check # where a doc and the code disagree in what a script can read; --changed + # lists the docs a change calls for reading again: design/build.md pnpm build # the player: types, element, both workers; builds the runtime package on the way pnpm normalize course.h5p # rewrite a package so it streams: media stored, mp4 index first pnpm verify course.h5p # play a package in a headless browser and report whether it works diff --git a/design/testing.md b/design/testing.md index 94acb695..38d0989c 100644 --- a/design/testing.md +++ b/design/testing.md @@ -12,7 +12,8 @@ is one of the docs below. The player, the verifier, the skills, the embed packag journeys take most of the time, so each tests in a job of its own, side by side, and the rest in one more. Every package that has a `typecheck` script runs it whatever the change, since each package's check writes the types the next one reads. A change to `design/`, `docs/`, a root `.md`, `LICENSE` or `.coderabbit.yaml` alone starts -no run. The `scope` job in `ci.yml` decides. +no run of `ci.yml`, whose `scope` job decides. `docs.yml` runs for every pull request and push to main, whatever it changes: it is +`pnpm docs:check` alone, the docs held to the code (`design/build.md`). **The costly checks run weekly and by hand.** These are Firefox and WebKit, the player's browser files that wait out real time, the content-type sweep, and the VS Code extension in a real editor, diff --git a/docs/revision.md b/docs/revision.md index 80c8a2bb..d36607f6 100644 --- a/docs/revision.md +++ b/docs/revision.md @@ -1,7 +1,7 @@ # Which build a learner completed -Every `xapi` and `finished` statement carries two xAPI fields, filled in unless the content set -them itself: +Every `xapi` and `finished` statement about an Activity carries two xAPI fields, filled in unless +the content set them itself: ```json "context": { @@ -10,6 +10,9 @@ them itself: } ``` +On a host without `Range`, statements wait for the archive's index to be read, and go out without +`revision` if the load ends or the page is hidden first, rather than be lost with the tab. + `revision` is a SHA-256 over the archive's index: each entry's name, CRC, sizes and compression method, in archive order. A change to any of those, or to the order, gives a new value; a change to an entry's date alone does not. The same file always gives the same one. When `libraries` supplied libraries, what supplied them follows: @@ -19,8 +22,8 @@ library, sorted and a line each. So the libraries a package carries but played a version count, and a pack release that changes none of a package's libraries leaves its revision as it was. The element's `revision` property holds it once the package is indexed. -**At release**, record it: the normalizer prints the revision of the file it writes. Keep the -published `.h5p`, from which anyone can recompute it. +**At release**, record it: the normalizer prints the file's own part, the one before +`; libraries`. Keep the published `.h5p`, from which anyone can recompute it. The recipe does not change within a major version of the player, and a major that changes it gives the new value a prefix of its own ([Compatibility](https://github.com/missing-elements/h5p-toolkit/blob/main/docs/compatibility.md)). diff --git a/docs/verify.md b/docs/verify.md index cbf8e024..5ffbda40 100644 --- a/docs/verify.md +++ b/docs/verify.md @@ -27,7 +27,7 @@ The check cannot say whether the content is right; a person decides that by play `--preview` checks nothing and opens the package in the real player in the person's own browser, served from their computer with `Range`, as a static host serves it. It works for any content type, and a large video starts at once. Its page has a Download button for the file. It -ends a few seconds after its last tab closes: +ends ten seconds after its last tab closes: ```bash npx @missing-elements/h5p-verify@latest course.h5p --preview diff --git a/package.json b/package.json index 143e4331..d241247d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test:engine": "pnpm --filter @missing-elements/h5p-offline-player test:engine && pnpm --filter @missing-elements/h5p-demo test && pnpm --filter @missing-elements/h5p-journeys test", "typecheck": "pnpm -r typecheck", "comments": "node scripts/comments.mjs", + "docs:check": "node scripts/docs.mjs", "lint": "oxlint --type-aware --deny-warnings", "normalize": "node packages/normalize/bin/h5p-normalize.mjs", "verify": "node packages/verify/bin/h5p-verify.mjs", diff --git a/packages/author/README.md b/packages/author/README.md index 789c701e..144d1f8e 100644 --- a/packages/author/README.md +++ b/packages/author/README.md @@ -56,7 +56,7 @@ is the workflow around it. | Field | Meaning | |---|---| | `type` | The content type's machine name, such as `H5P.Blanks`; the pack's newest version is used | -| `title` | The title, at most 255 characters | +| `title` | The title, on one line and at most 255 bytes in UTF-8 | | `language` | A BCP 47 tag, `en`, `de-AT`; it picks the libraries' translation of their interface texts | | `license` | An H5P licence code: `U` (undisclosed), `CC BY`, `CC BY-SA`, `CC BY-ND`, `CC BY-NC`, `CC BY-NC-SA`, `CC BY-NC-ND`, `CC0 1.0`, `CC PDM`, `GNU GPL`, `PD`, `ODC PDDL`, `C`; `licenseVersion` for a CC BY one | | `authors` | `[{ "name": "…", "role": "Author" }]`, the role one of Author, Editor, Licensee, Originator | diff --git a/packages/embed/README.md b/packages/embed/README.md index 0b7e8dba..65b7bddf 100644 --- a/packages/embed/README.md +++ b/packages/embed/README.md @@ -250,10 +250,6 @@ for has not been checked yet. pass mark; a failed attempt, or content that reports only `completed`, leaves the lesson open. It keeps no score. -Write again any zip made by embed 1.3.0 or earlier: SCORM Cloud cannot import it ("IO Error -processing zip"), nor, likely, can some other Java-based LMSs; ILIAS loses the time of a session -the learner ends by closing the tab, and Chamilo does not record that it was left unfinished. - ## As a library ```js diff --git a/packages/libraries/README.md b/packages/libraries/README.md index 50deb3b3..22a8e31d 100644 --- a/packages/libraries/README.md +++ b/packages/libraries/README.md @@ -57,9 +57,9 @@ would refuse to fetch. ## Licences Each library keeps its own licence, named here word for word as `libraries.txt` names it: mostly -MIT; also MPL (H5P.ImageJuxtaposition), MPL2 (TimelineJS), pd, public domain (H5P.TextUtilities and H5P.Timer), -GPL3 (H5P.MaterialDesignIcons) and GPL-3.0 (flowplayer). H5P.MathDisplay is MIT and bundles -MathJax, Speech Rule Engine and mhchem, all Apache-2.0. +MIT; also MPL (H5P.ImageJuxtaposition), MPL2 (TimelineJS), pd (public domain: H5P.TextUtilities +and H5P.Timer), GPL3 (H5P.MaterialDesignIcons) and GPL-3.0 (flowplayer). H5P.MathDisplay is MIT +and bundles MathJax, Speech Rule Engine and mhchem, all Apache-2.0. [`libraries.txt`](libraries.txt) lists each one's version, licence and authors; serve it beside the pack. diff --git a/packages/normalize/README.md b/packages/normalize/README.md index 64bf0e23..bc4a3519 100644 --- a/packages/normalize/README.md +++ b/packages/normalize/README.md @@ -29,11 +29,14 @@ Installed (`npm install --save-dev @missing-elements/h5p-normalize`), the comman | `-q, --quiet` | only the summary | | `-h, --help` | | -An entry whose bytes do not match their CRC stops the run with its name; an encrypted entry is -refused. `unzip -t` is an independent check of the output. - -The summary's `revision` line is what the player puts in `context.revision` on every xAPI -statement for the written file (for a dry run, the input). Record it at release. +An entry the run rewrites whose bytes do not match their CRC stops it with the entry's name; one +copied as it is goes unread, and a dry run reads fewer still. An encrypted entry is refused. +`unzip -t` is an independent check of the output. + +The summary's `revision` line is what the player puts in `context.revision` on the xAPI +statements for the written file (for a dry run, the input), unless the content set its own, +before `; libraries` and their fingerprint where the page's `libraries` supplied any. Record it +at release ([Which build a learner completed](https://github.com/missing-elements/h5p-toolkit/blob/main/docs/revision.md)). `archiveFingerprint(path)` returns the same from code. ## From code diff --git a/packages/player/NOTICE.md b/packages/player/NOTICE.md index 4de9adb5..c201393e 100644 --- a/packages/player/NOTICE.md +++ b/packages/player/NOTICE.md @@ -2,7 +2,7 @@ `@missing-elements/h5p-offline-player` is published under the MIT licence, and so is everything in it: `dist/h5p-player.js`, `dist/h5p-sw.js`, `dist/h5p-sw-mount.js`, `dist/h5p-jobs.js`, -`types/` and the sources under `src/` and `scripts/` in the repository — see [LICENSE](LICENSE). +`dist/h5p-plan.js`, `types/` and the sources under `src/` and `scripts/` in the repository — see [LICENSE](https://github.com/missing-elements/h5p-toolkit/blob/main/LICENSE). Two things are worth knowing beyond that. ## zip.js — BSD-3-Clause @@ -47,11 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## The H5P runtime is not in this package The element plays content inside a frame that runs the H5P core runtime, and that runtime is -**GPL-3.0** — it is the core of [h5p/h5p-php-library](https://github.com/h5p/h5p-php-library), -which came by way of [h5p-standalone](https://github.com/tunapanda/h5p-standalone) until the -runtime vendored it from upstream at a commit. Up to 0.4 this package shipped -it under `dist/frame-assets/` and was published as `(MIT AND GPL-3.0-only)`. From 0.5 it does -not: the runtime, its stylesheet and fonts, and the script that boots it inside the frame are +**GPL-3.0** — it is the core of [h5p/h5p-php-library](https://github.com/h5p/h5p-php-library). +The runtime, its stylesheet and fonts, and the script that boots it inside the frame are [`@missing-elements/h5p-runtime`](https://www.npmjs.com/package/@missing-elements/h5p-runtime), a package of its own under the GPL, with its own `NOTICE.md`. A site installs that package, serves it from a CDN or copies its `dist/` next to the element, and the element names its files; diff --git a/packages/player/README.md b/packages/player/README.md index 9395e27c..937822cf 100644 --- a/packages/player/README.md +++ b/packages/player/README.md @@ -78,8 +78,8 @@ too. Set `trusted` only on packages you made, to play them with their own code. On a site with signed-in users, keep it off, or embed the player from a domain of its own, as [Which setup](https://github.com/missing-elements/h5p-toolkit/blob/main/docs/setup.md#which-setup) explains. -Coming from 1.x, `trusted` replaces `untrusted`: every package now plays untrusted unless the page -sets `trusted`, and one that needs its own copy of a library the pack lacks is refused until then. +Every package plays untrusted unless the page sets `trusted`, and one that needs its own copy of a +library the pack lacks is refused until then. A trusted package, and a library bundle, are read only from the origin their address names. [Setting up the player](https://github.com/missing-elements/h5p-toolkit/blob/main/docs/setup.md) also covers a page without a bundler, Rollup and esbuild, and the one-prompt install on Lovable; [the element's API](https://github.com/missing-elements/h5p-toolkit/blob/main/docs/api.md) lists every attribute, property and event. diff --git a/packages/runtime/NOTICE.md b/packages/runtime/NOTICE.md index 6178f896..cac38376 100644 --- a/packages/runtime/NOTICE.md +++ b/packages/runtime/NOTICE.md @@ -23,11 +23,6 @@ inlined as data URLs, its Inter and Open Sans faces moved to `fonts/` and listed [repository](https://github.com/missing-elements/h5p-toolkit/tree/main/packages/runtime) holds the files as upstream has them, and `scripts/sync-core.mjs` takes them from upstream. -Until 2026-10-18 the core came by way of [h5p-standalone](https://github.com/tunapanda/h5p-standalone), -whose copy of it records no upstream revision -([tunapanda/h5p-standalone#188](https://github.com/tunapanda/h5p-standalone/issues/188)); none of -h5p-standalone's own code is in this package any more. - The full licence text is in [LICENSE](LICENSE) and, so that it travels with the files, in `dist/LICENSE.txt`; `dist/NOTICE.txt` lists the files and names the h5p-php-library commit they were built from, which is the corresponding source together with this package's build. Keep both @@ -59,8 +54,8 @@ against its libraries' semantics. That one is a port: of `H5PContentValidator` i from [h5p/h5p-php-library](https://github.com/h5p/h5p-php-library) at commit `cb64a1f3884408487c3178e31fc140f5d45ca165`, **GPL-3.0**, and of the HTML filter that class copied from Drupal 7's `includes/common.inc` (`filter_xss` and its helpers, based on kses by Ulf -Harnhammar), Copyright Drupal contributors, **GPL-2.0-or-later**, which the GPL-3.0 accepts. It -was ported on 2026-08-11. Where it departs from the original, it is stricter, or it has to be: +Harnhammar), Copyright Drupal contributors, **GPL-2.0-or-later**, which the GPL-3.0 accepts. +Where it departs from the original, it is stricter, or it has to be: - A sub-content library is accepted when a field names the same machine name and major version, not only the exact string: the player serves the newest minor it can reach and upgrades the diff --git a/scripts/docs.json b/scripts/docs.json new file mode 100644 index 00000000..85a99e5a --- /dev/null +++ b/scripts/docs.json @@ -0,0 +1,243 @@ +{ + "README.md": [ + "packages/*/package.json", + "packages/*/bin/", + "packages/player/src/h5p-offline-player.ts", + "skills/*/SKILL.md", + ".github/workflows/libraries.yml", + ".github/workflows/l10n.yml", + ".github/workflows/content-types.yml" + ], + "ACCESSIBILITY.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/src/sw/frame-document.ts", + "packages/runtime/src/frame-boot.ts", + "packages/runtime/src/l10n.ts" + ], + "SECURITY.md": [ + "packages/*/package.json", + "packages/player/src/sw/frame-document.ts", + "packages/player/src/sw/mount.ts", + "packages/player/src/shared/entry-names.ts", + "packages/runtime/src/content-check.ts", + "packages/author/lib/", + "packages/mcp/lib/" + ], + "CONTRIBUTING.md": [ + "package.json", + ".github/workflows/ci.yml", + ".github/workflows/docs.yml" + ], + "AGENTS.md": [ + "package.json", + "pnpm-workspace.yaml", + "packages/*/package.json", + "apps/*/package.json" + ], + "design/commands.md": [ + "package.json", + "packages/*/package.json", + "apps/*/package.json" + ], + "docs/api.md": [ + "packages/player/src/", + "packages/runtime/src/finished.ts", + "packages/runtime/src/frame-boot.ts" + ], + "docs/author-api.md": [ + "packages/author/lib/", + "packages/author/package.json" + ], + "docs/cmi5.md": [ + "packages/cmi5/src/", + "packages/cmi5/package.json", + "packages/runtime/src/finished.ts" + ], + "docs/compatibility.md": [ + "packages/*/package.json", + "packages/*/bin/", + "packages/player/src/shared/revision.ts", + "packages/player/src/shared/pkg-id.ts", + "packages/embed/lib/", + "packages/libraries/scripts/parts.mjs" + ], + "docs/development.md": [ + "package.json", + "apps/*/package.json" + ], + "docs/frame-csp.md": [ + "packages/player/src/sw/frame-document.ts" + ], + "docs/h5p-standalone.md": [ + "packages/player/src/h5p-offline-player.ts" + ], + "docs/libraries.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/src/plan.ts", + "packages/player/src/shared/library-sources.ts", + "packages/player/src/shared/content-libraries.ts", + "packages/player/src/shared/pack.ts", + "packages/player/src/shared/pack-index.ts", + "packages/player/src/sw/library-load.ts", + "packages/player/src/sw/pack-plan.ts", + "packages/runtime/src/content-upgrade.ts", + "packages/libraries/scripts/parts.mjs", + "packages/libraries/parts/index.json", + "packages/player/src/shared/constants.ts" + ], + "docs/privacy.md": [ + "packages/player/src/sw/frame-document.ts", + "packages/player/src/user-data-store.ts", + "packages/player/src/shared/constants.ts", + "packages/player/src/shared/pack.ts", + "packages/embed/site/", + "packages/embed/scorm/", + "packages/cmi5/src/" + ], + "docs/resume.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/src/user-data-store.ts", + "packages/player/src/shared/constants.ts", + "packages/runtime/src/frame-boot.ts" + ], + "docs/revision.md": [ + "packages/player/src/shared/revision.ts", + "packages/normalize/lib/fingerprint.mjs" + ], + "docs/setup.md": [ + "packages/player/package.json", + "packages/runtime/package.json", + "packages/player/src/h5p-offline-player.ts", + "packages/player/page/page.css", + "packages/embed/bin/" + ], + "docs/single-worker.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/src/sw/mount.ts", + "packages/player/src/sw/routes.ts", + "packages/player/src/sw/sw-entry.ts", + "packages/player/src/shared/constants.ts" + ], + "docs/streaming-video.md": [ + "packages/normalize/lib/", + "packages/player/src/shared/source.ts", + "packages/player/src/shared/source-reader.ts" + ], + "docs/troubleshooting.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/src/shared/protocol.ts", + "packages/player/src/sw/frame-document.ts", + "packages/player/src/shared/constants.ts", + "packages/runtime/src/frame-boot.ts" + ], + "docs/untrusted.md": [ + "packages/player/src/sw/frame-document.ts", + "packages/player/src/sw/mount.ts", + "packages/player/src/shared/entry-names.ts", + "packages/player/src/shared/content-libraries.ts", + "packages/runtime/src/content-check.ts", + "packages/player/src/h5p-offline-player.ts", + "packages/verify/bin/" + ], + "docs/verify.md": [ + "packages/verify/bin/", + "packages/verify/lib/" + ], + "packages/author/README.md": [ + "packages/author/bin/", + "packages/author/lib/", + "packages/author/package.json" + ], + "packages/cmi5/README.md": [ + "packages/cmi5/src/", + "packages/cmi5/package.json" + ], + "packages/embed/README.md": [ + "packages/embed/bin/", + "packages/embed/lib/", + "packages/embed/site/", + "packages/embed/scorm/", + "packages/embed/package.json" + ], + "packages/libraries/README.md": [ + "packages/libraries/scripts/parts.mjs", + "packages/libraries/index.d.ts", + "packages/libraries/install.d.ts", + "packages/libraries/package.json" + ], + "packages/mcp-app/README.md": [ + "packages/mcp-app/bin/", + "packages/mcp-app/lib/", + "packages/mcp-app/play/", + "packages/mcp-app/package.json", + "packages/author/lib/", + "packages/mcp/lib/answers.mjs" + ], + "packages/mcp/README.md": [ + "packages/mcp/bin/", + "packages/mcp/lib/", + "packages/mcp/package.json", + "packages/author/lib/", + "packages/verify/lib/" + ], + "packages/normalize/README.md": [ + "packages/normalize/bin/", + "packages/normalize/lib/", + "packages/normalize/package.json" + ], + "packages/player/README.md": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/package.json" + ], + "packages/player/NOTICE.md": [ + "packages/player/package.json" + ], + "packages/runtime/README.md": [ + "packages/runtime/src/", + "packages/runtime/scripts/build.mjs", + "packages/runtime/index.d.ts", + "packages/runtime/package.json" + ], + "packages/runtime/NOTICE.md": [ + "packages/runtime/src/content-check.ts", + "packages/runtime/scripts/sync-core.mjs" + ], + "packages/verify/README.md": [ + "packages/verify/bin/", + "packages/verify/lib/", + "packages/verify/package.json" + ], + "packages/vscode/README.md": [ + "packages/vscode/src/", + "packages/vscode/package.json" + ], + "skills/docs-check/": [ + "scripts/docs.mjs" + ], + "skills/h5p-author/": [ + "packages/author/bin/", + "packages/author/lib/", + "packages/mcp/lib/", + "packages/mcp-app/lib/" + ], + "skills/h5p-normalize/": [ + "packages/normalize/bin/", + "packages/normalize/lib/" + ], + "skills/h5p-player-setup/": [ + "packages/player/src/h5p-offline-player.ts", + "packages/player/package.json", + "packages/embed/bin/" + ], + "skills/h5p-player-setup/references/options.md": [ + "packages/player/src/shared/constants.ts" + ], + "skills/h5p-to-scorm/": [ + "packages/embed/bin/", + "packages/embed/lib/" + ], + "skills/h5p-verify/": [ + "packages/verify/bin/", + "packages/verify/lib/" + ] +} diff --git a/scripts/docs.mjs b/scripts/docs.mjs new file mode 100644 index 00000000..20d2ce5c --- /dev/null +++ b/scripts/docs.mjs @@ -0,0 +1,404 @@ +#!/usr/bin/env node +// Holds the docs to what a script can read from the code, and exits with 1 on a miss: design/build.md. +// Usage: node scripts/docs.mjs [--changed [commit] | --all [doc...]] (those two list what a reader goes through) +import { execFileSync } from 'node:child_process' +import { existsSync, readFileSync, statSync } from 'node:fs' +import { dirname, join, posix, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' + +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') +const REPO = 'missing-elements/h5p-toolkit' +// The repository's name until it was renamed. The npm package keeps the word, after an `@`. +const OLD_REPO = new RegExp(`(? execFileSync('git', ['-C', root, '-c', 'core.quotepath=off', ...args], { encoding: 'utf8', maxBuffer: 1 << 28, stdio: ['ignore', 'pipe', 'ignore'] }).split('\n').filter(Boolean) +/** @param {string} file */ +const read = (file) => readFileSync(join(root, file), 'utf8') +/** @param {string} file */ +const json = (file) => JSON.parse(read(file)) + +// Untracked files count too, so a doc can link to a file the same change adds. +const all = git('ls-files', '--cached', '--others', '--exclude-standard').filter((file) => existsSync(join(root, file))) +const files = all.filter((file) => !SKIPPED.test(file)) +const docs = files.filter((file) => file.endsWith('.md')) +const exists = new Set(all) +const folders = new Set(all.flatMap((file) => file.split('/').slice(0, -1).map((_, at, parts) => parts.slice(0, at + 1).join('/'))).concat('')) + +/** @type {string[]} */ +const misses = [] +/** @param {string} file @param {number} at @param {string} message */ +const miss = (file, at, message) => misses.push(`${file}${at ? `:${at}` : ''}: ${message}`) + +/** + * A doc's lines, each with whether it is in a fenced block, where a link or a heading is an example. + * @param {string} text + */ +function lines(text) { + let fence = '' + return text.split('\n').map((line, index) => { + const mark = /^\s*(```|~~~)/.exec(line)?.[1] ?? '' + const code = fence !== '' || mark !== '' + if (mark && !fence) fence = mark + else if (mark && mark === fence) fence = '' + return { line, at: index + 1, code } + }) +} + +/** + * A path of `docs.json` as a test of a file: `*` stands for one name, and a path ending in `/` for + * all below it. + * @param {string} path + */ +function within(path) { + const pattern = new RegExp(`^${path.split('*').map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('[^/]*')}${path.endsWith('/') ? '' : '$'}`) + return (/** @type {string} */ file) => pattern.test(file) +} + +const packages = files.filter((file) => /^packages\/[^/]+\/package\.json$/.test(file)).map((file) => ({ folder: file.split('/')[1], ...json(file) })) +const apps = files.filter((file) => /^apps\/[^/]+\/package\.json$/.test(file)).map((file) => ({ folder: file.split('/')[1], ...json(file) })) +/** @type {Map>} */ +const scripts = new Map([['', json('package.json').scripts], ...[...packages, ...apps].map((each) => /** @type {[string, Record]} */ ([each.name, each.scripts ?? {}]))]) +/** @type {Record} */ +// The map moved is a message, not a stack trace, as for every file the checks read by name. +const sources = existsSync(join(root, MAP)) ? json(MAP) : refuse(`${MAP} is gone, and this script reads it: bring the script up to date.`) + +// ---- Links: every link into this repository reaches a file, and its fragment a heading there. + +const OWN = new RegExp(`^https://(?:github\\.com/${REPO}(?:/(?:blob|tree|raw)/main(?:/([^#?]*))?)?|raw\\.githubusercontent\\.com/${REPO}/(?:refs/heads/)?main/([^#?]*))(?:\\?[^#]*)?(?:#(.*))?$`) + +/** + * Where a link leads in this repository, or `null` for one that leaves it. + * @param {string} from @param {string} link + */ +function pointsAt(from, link) { + const own = OWN.exec(link) + if (own) return { path: (own[1] ?? own[2] ?? '').replace(/\/$/, ''), fragment: own[3] ?? '' } + if (/^[a-z][a-z0-9+.-]*:|^\/\//i.test(link)) return null + const [path, fragment = ''] = link.split('#') + // GitHub reads a path that starts with `/` from the repository's root. + const to = path === '' ? from : posix.normalize(posix.join(path.startsWith('/') ? '' : posix.dirname(from), decodeURIComponent(path.split('?')[0]))).replace(/^\/|\/$/g, '') + return { path: to === '.' ? '' : to, fragment } +} + +/** @type {Map>} */ +const headings = new Map() +/** + * The fragments a doc answers to: its headings as GitHub names them, and any id it sets. + * @param {string} doc + */ +function anchors(doc) { + let found = headings.get(doc) + if (found) return found + found = new Set() + /** @type {Map} */ + const seen = new Map() + for (const { line, code } of lines(read(doc))) { + for (const [, id] of line.matchAll(/\b(?:id|name)="([^"]+)"/g)) found.add(id.toLowerCase()) + const heading = code ? null : /^ {0,3}#{1,6}\s+(.+?)\s*#*$/.exec(line) + if (!heading) continue + const slug = heading[1].replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[`*]/g, '').toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu, '').replace(/\s/g, '-') + const count = seen.get(slug) ?? 0 + seen.set(slug, count + 1) + found.add(count ? `${slug}-${count}` : slug) + } + headings.set(doc, found) + return found +} + +function checkLinks() { + for (const doc of docs) { + for (const { line, at, code } of lines(read(doc))) { + if (code) continue + // A link written as code is an example of one. + for (const found of line.replace(/`[^`]*`/g, '``').matchAll(/\]\(\s*]+)>?[^)]*\)|\b(?:src|href)="([^"]+)"|^\s*\[[^\]]+\]:\s*(\S+)/g)) { + const link = found[1] ?? found[2] ?? found[3] + const to = pointsAt(doc, link) + if (!to) continue + const folder = folders.has(to.path) + if (!folder && !exists.has(to.path)) { + miss(doc, at, `links to ${link}, and there is no ${to.path}`) + continue + } + const readme = posix.join(to.path, 'README.md') + const target = !folder ? to.path : exists.has(readme) ? readme : '' + // GitHub gives a folder's page the fragment `readme`, whatever the README's headings. + if (!to.fragment || !target.endsWith('.md') || (folder && to.fragment === 'readme')) continue + let heading = to.fragment + try { + heading = decodeURIComponent(to.fragment) + } catch { + // A fragment such as `#%` that no decoding reads: no heading has it, so it is a miss below. + } + if (!anchors(target).has(heading.toLowerCase())) miss(doc, at, `links to ${link}, and ${target} has no heading for #${to.fragment}`) + } + } + } +} + +// ---- Names: the repository's old name is gone, and every package is in every list of them. + +function checkNames() { + for (const file of files) { + if (!TEXT.test(file)) continue + read(file).split('\n').forEach((line, index) => { + if (OLD_REPO.test(line)) miss(file, index + 1, `names the repository as it was: it is ${REPO}`) + }) + } + // The extension is listed by its marketplace name, which its package's `displayName` begins with. + const label = (/** @type {{ name: string, displayName?: string }} */ each) => each.displayName?.replace(/ by .*$/, '') ?? each.name.replace(/^@[^/]+\//, '') + for (const list of LISTS) { + const text = read(list) + for (const each of packages) { + if (!new RegExp(`(? `packages/${one.folder}/`), ...apps.map((one) => `apps/${one.folder}/`)]) { + if (!agents.includes(each)) miss('AGENTS.md', 0, `does not say what ${each} is`) + } + for (const doc of docs) { + for (const { line, at } of lines(read(doc))) { + const counted = /\b(\w+) packages and (\w+) apps\b/.exec(line) + if (!counted || !WORDS.includes(counted[1]) || !WORDS.includes(counted[2])) continue + if (counted[1] !== WORDS[packages.length] || counted[2] !== WORDS[apps.length]) miss(doc, at, `counts ${counted[1]} packages and ${counted[2]} apps: there are ${packages.length} and ${apps.length}`) + } + } +} + +// ---- Commands: every `pnpm` script, `npx` package and skill a doc names is there to run. + +/** The name of the package a folder holds, `''` for the root, else the folder as written. */ +function packageIn(/** @type {string} */ folder) { + const path = posix.normalize(folder).replace(/\/$/, '') + if (path === '.') return '' + const kind = path.split('/')[0] + return (kind === 'packages' ? packages : kind === 'apps' ? apps : []).find((each) => path === `${kind}/${each.folder}`)?.name ?? folder +} + +/** + * The script a `pnpm` command line runs, and in which package: past its own options. + * @param {string[]} words + */ +function scriptOf(words) { + let from = '' + let every = false + for (let at = 0; at < words.length; at++) { + const [word, joined] = /^(--filter|--dir)=(.*)$/.exec(words[at])?.slice(1) ?? [words[at]] + if (word === '--filter' || word === '-F') from = joined ?? words[++at] ?? '' + else if (word === '-C' || word === '--dir') from = packageIn(joined ?? words[++at] ?? '') + else if (word === '-r' || word === '--recursive') every = true + else if (!word.startsWith('-')) return { from, every, name: word === 'run' ? (words[at + 1] ?? '') : word } + } + return null +} + +function checkCommands() { + const commands = new Set(packages.filter((each) => each.bin).map((each) => each.name)) + for (const doc of docs) { + // A package's own doc runs that package's scripts too, and design/ speaks of any package's. + const [kind, folder] = doc.split('/') + const own = (kind === 'packages' ? packages : kind === 'apps' ? apps : []).find((each) => each.folder === folder)?.scripts ?? {} + for (const { line, at, code } of lines(read(doc))) { + // In a block, the line up to its comment; in prose, only what is written as code. + const written = code ? [line.replace(/\s#.*$/, '')] : [...line.matchAll(/`([^`]+)`/g)].map((span) => span[1]) + for (const text of written) { + for (const [, rest] of text.matchAll(/(?:^|&&|;|\|\||\$\()\s*(?:\$\s+)?(?:[A-Z][A-Z0-9_]*=\S*\s+)*pnpm\s+([^&;|]*)/g)) { + const run = scriptOf(rest.trim().split(/\s+/)) + if (!run || !/^[a-z][\w:-]*$/.test(run.name) || BUILTIN.has(run.name)) continue + // A filter that selects by path or by change names no one package to look in. + if (run.from && !scripts.has(run.from)) { + if (/^[@\w/-]+$/.test(run.from)) miss(doc, at, `runs a script of ${run.from}, and no package has that name`) + continue + } + const anywhere = run.every || (!run.from && doc.startsWith('design/')) + const known = anywhere ? [...scripts.values()].some((each) => run.name in each) : run.name in (scripts.get(run.from) ?? {}) || (!run.from && run.name in own) + if (!known) miss(doc, at, `runs \`pnpm ${run.name}\`, which is no script of ${anywhere ? 'any package' : run.from || 'the root package.json'}`) + } + } + for (const [, name] of line.matchAll(/(@missing-elements\/h5p-[a-z0-9][a-z0-9-]*)/g)) { + if (!scripts.has(name)) miss(doc, at, `names ${name}, and no package has that name`) + } + for (const [, name] of line.matchAll(/\bnpx\s+(?:-\S+\s+)*(@missing-elements\/h5p-[a-z0-9][a-z0-9-]*)/g)) { + if (scripts.has(name) && !commands.has(name)) miss(doc, at, `runs ${name} with npx, which has no command`) + } + if (!line.includes(REPO)) continue + for (const [, name] of line.matchAll(/--skill[ =]([a-z0-9][a-z0-9-]*)/g)) { + if (!exists.has(`skills/${name}/SKILL.md`)) miss(doc, at, `installs the skill ${name}, and skills/ has none by that name`) + } + } + } +} + +// ---- Options: a command's README and its usage text name the same options. + +/** @param {string} text */ +const flags = (text) => new Set([...text.matchAll(/(? found[0])) + +function checkOptions() { + for (const each of packages) { + for (const bin of Object.values(typeof each.bin === 'string' ? { [each.name]: each.bin } : (each.bin ?? {}))) { + const file = posix.join('packages', each.folder, bin) + const readme = `packages/${each.folder}/README.md` + // The usage text is read, not printed: a command may need a build before it runs. + const usage = [...read(file).matchAll(/`(?:[^`\\]|\\.)*`/gs)].map((found) => found[0]).filter((text) => text.includes('Usage:')).join('\n') + if (!usage) miss(file, 0, `has no usage text ${MAP.replace('.json', '.mjs')} can read: bring the script up to date`) + const taken = flags(usage) + const said = flags(read(readme)) + for (const flag of taken) { + if (!EVERYWHERE.has(flag) && !said.has(flag)) miss(readme, 0, `says nothing of ${flag}, which ${file} takes`) + } + for (const { line, at } of lines(read(readme))) { + // A table row's first cell is the option it describes, a short form before it or not. + const cell = /^\|\s*(`-[^|]*)\|/.exec(line)?.[1] ?? '' + for (const flag of usage ? flags(cell) : []) { + if (!taken.has(flag)) miss(readme, at, `lists ${flag}, which ${file} does not take`) + } + } + } + } +} + +// ---- Numbers and names the code states: sizes of the pack, and what the element answers to. + +function checkFacts() { + /** @type {{ size: number, installOnly?: boolean }[]} */ + const parts = json('packages/libraries/parts/index.json').libraries + const megabytes = (/** @type {number} */ bytes) => `${(bytes / 1e6).toFixed(1)} MB` + const sum = (/** @type {{ size: number }[]} */ list) => list.reduce((total, part) => total + part.size, 0) + const facts = [ + { says: megabytes(sum(parts.filter((part) => !part.installOnly))), what: 'the size of the pack a player reads', where: ['docs/libraries.md', 'packages/embed/bin/h5p-embed.mjs'] }, + { says: megabytes(sum(parts.filter((part) => part.installOnly))), what: 'the size of the libraries only an H5P site installs', where: ['docs/libraries.md'] }, + { says: megabytes(statSync(join(root, 'packages/libraries/libraries.h5p')).size), what: 'the size of libraries.h5p', where: ['docs/libraries.md'] } + ] + for (const { says, what, where } of facts) { + for (const file of where) { + // Whole: 1.2 MB is not said by a line that says 11.2 MB. + if (!new RegExp(`(? [each.name, each.version])) + for (const file of files) { + if (!TEXT.test(file)) continue + read(file).split('\n').forEach((line, index) => { + for (const [, name, pinned] of line.matchAll(/(@missing-elements\/h5p-[a-z0-9-]+)@(\d+\.\d+\.\d+)(?![\w.-])/g)) { + const version = versions.get(name) + if (version && pinned !== version) miss(file, index + 1, `pins ${name} at ${pinned}, and its package.json has ${version}`) + } + }) + } + + const element = 'packages/player/src/h5p-offline-player.ts' + const protocol = 'packages/player/src/shared/protocol.ts' + /** The names in a union of strings; a union that has moved is a miss, not a pass. */ + const union = (/** @type {string} */ file, /** @type {RegExp} */ pattern, /** @type {string} */ what) => { + const found = pattern.exec(read(file)) + if (!found) miss(file, 0, `has no ${what} ${MAP.replace('.json', '.mjs')} can read: bring the script up to date`) + return [...(found?.[1] ?? '').matchAll(/'([^']+)'/g)].map((name) => [what, name[1]]) + } + const named = [ + ...[...read(element).matchAll(/(?:get|has)Attribute\('([a-z-]+)'\)/g)].map((found) => ['attribute', found[1]]), + ...union(element, /export type PlayerState =([^\n]+)/, 'state'), + ...union(element, /\bphase: ('[^\n]+)/, 'progress phase'), + ...union(protocol, /export type ErrorCode =((?:\s*\|\s*'[^']+')+)/, 'error code') + ] + const api = read('docs/api.md') + for (const [what, name] of named) { + if (!api.includes(`\`${name}\``)) miss('docs/api.md', 0, `says nothing of the ${what} \`${name}\`, which the element has`) + } +} + +// ---- The map: every guide names the code it describes, and every path in the map is there. + +function checkMap() { + for (const [doc, from] of Object.entries(sources)) { + if (!docs.some(within(doc))) miss(MAP, 0, `names ${doc}, and there is no such doc`) + for (const path of from) { + if (!all.some(within(path))) miss(MAP, 0, `gives ${doc} the source ${path}, and there is none`) + } + } + const mapped = Object.keys(sources).map(within) + for (const doc of docs) { + if (GUIDE.test(doc) && !mapped.some((test) => test(doc))) miss(doc, 0, `has no sources in ${MAP}: name the code it describes`) + } +} + +/** + * Each source changed since `since`, the work not yet committed included, with the command that + * shows its change and the docs that describe it: what a reader goes through. + * @param {string} since + */ +function changedSources(since) { + const added = new Set(git('ls-files', '--others', '--exclude-standard')) + // A test says what the code should do, and the code what it does: only the code calls for a read. + const changed = [...new Set([...git('diff', '--name-only', since), ...added])].filter((file) => !/\.test\.|(^|\/)tests?\//.test(file)) + return changed + .map((file) => ({ + file, + shown: added.has(file) ? 'new file: read it whole' : `git diff ${since} -- ${file}`, + read: docs.filter((doc) => doc !== file && Object.entries(sources).some(([key, from]) => within(key)(doc) && from.some((path) => within(path)(file)))) + })) + .filter((each) => each.read.length > 0) +} + +/** @param {string} message */ +function refuse(message) { + console.error(message) + process.exit(2) +} + +const [flag, ...named] = process.argv.slice(2) +if (flag === '--changed') { + /** @type {string[]} */ + let since = [] + // No origin/main, as in a checkout of one commit: HEAD in its place would leave the commits out unseen. + try { + since = git('merge-base', named[0] ?? 'origin/main', 'HEAD') + } catch { + since = refuse(named[0] ? `No commit is named ${named[0]}.` : 'No origin/main here: name the commit the change starts from, or HEAD for the work not yet committed.') + } + const from = since[0].slice(0, 12) + const reading = changedSources(from) + for (const { file, shown, read } of reading) console.log(`${file}\n its change: ${shown}\n${read.map((doc) => ` - ${doc}`).join('\n')}`) + if (!reading.length) console.log(`No doc's sources changed since ${from}.`) +} else if (flag === '--all') { + // A doc named is its own entry, or every entry below a folder named. + const names = (/** @type {string} */ name) => (/** @type {[string, string[]]} */ [doc]) => doc.startsWith(name) || within(doc)(name) + const unknown = named.filter((name) => !Object.entries(sources).some(names(name))) + if (unknown.length) refuse(`${MAP} has no doc named ${unknown.join(' or ')}.`) + const listed = Object.entries(sources).filter((entry) => !named.length || named.some((name) => names(name)(entry))) + for (const [doc, from] of listed) console.log(`${doc}: ${from.join(', ')}`) +} else if (flag) { + refuse(`Usage: node scripts/docs.mjs [--changed [commit] | --all [doc...]]`) +} else { + for (const check of [checkLinks, checkNames, checkCommands, checkOptions, checkFacts, checkMap]) { + // A file a check reads by name has moved: a miss that names it, not a stack trace. + try { + check() + } catch (error) { + const gone = /** @type {NodeJS.ErrnoException} */ (error) + if (gone.code !== 'ENOENT' || !gone.path) throw error + miss(posix.relative(root, gone.path), 0, `is gone, and ${MAP.replace('.json', '.mjs')} reads it: bring the script up to date`) + } + } + for (const line of misses) console.log(line) + if (misses.length) { + console.error(`${misses.length} ${misses.length === 1 ? 'place' : 'places'} where a doc and the code disagree. The code settles it: change the doc.`) + process.exit(1) + } +} diff --git a/skills/docs-check/SKILL.md b/skills/docs-check/SKILL.md new file mode 100644 index 00000000..953b2954 --- /dev/null +++ b/skills/docs-check/SKILL.md @@ -0,0 +1,104 @@ +--- +name: docs-check +description: Bring this repository's docs back in line with its code. Use after changing source, an option, a script or a package that a README, a docs/ page or a skill describes; before a release; and when asked to scan, review or fix the docs for drift, inconsistency or stale claims. +metadata: + internal: true +--- + +# Hold the docs to the code + +The docs come from the code. Where a doc and the code disagree, change the doc, even when the code +looks like a mistake: name that place in the report, and the person decides about the code. Never +change code, a test or a comment in code. + +Run every command from the repository root. + +## 1. Run the check + +```bash +node scripts/docs.mjs +``` + +- It prints nothing: go to step 2. +- It prints lines: each names a file and what the code has instead. Make that file say what the + code has, then run the check again. +- A line names a file that is code (`.mjs`, `.ts`, `.json`), or says to bring a script up to date: + leave that file, and name the line in the report as code that looks like a mistake. + +Go to step 2 once it prints nothing but such lines. + +## 2. List what changed + +- Asked to scan docs, all or some, not to check a change: follow [scan.md](scan.md) in place of + steps 2 to 5. +- The person named a commit to check from, as in "my last commit": give it. + +```bash +node scripts/docs.mjs --changed HEAD~1 +``` + +- Otherwise run it bare, for what changed since the branch left `origin/main`, the work not yet + committed included: + +```bash +node scripts/docs.mjs --changed +``` + +It prints each source that changed, then the command that shows its change, then the docs that +describe it. If it prints `No doc's sources changed since .`, stop and say so, the commit +included. + +## 3. Go through the sources it printed, one at a time + +First run the command printed under the source. Write one line for each thing in it that a person +using the package could notice: a default, a name, an option, a message, a number, an order, a +file written. + +```text +: was , is +``` + +A rename inside the code, a comment or a moved function is no such thing. A source with no line +written: go on to the next source. + +Only then read each doc printed under that source, whole, one after another. For each line you +wrote, look for every sentence that speaks of it, in whatever words: a doc may write `10` as +"ten seconds". Write each one down as a finding: + +```text +: says | : does +``` + +Where the change added something and the doc says nothing of it, the finding is +` says nothing of | :`. After each doc write `: findings`, +so that no doc printed is passed over. + +## 4. Check each finding again + +Open the source at the line the finding cites, and read the function around it. + +- The code does what the doc says after all: drop the finding. +- Otherwise: keep it. + +A scan here lost 4 of 15 findings at this step, so it is never skipped. + +## 5. Change the docs + +Read *A doc is short, and true to the code* in `design/build.md`, then change each doc a kept +finding names. Then look for copies of each claim, once per finding: + +```bash +git grep -n -i "" -- '*.md' +``` + +- A copy under `design/`: leave it and name it in the report, since there the design may be what + is right. +- A copy anywhere else: change it too. + +Then run the check of step 1 again. + +## 6. Report + +In this order: each doc changed, with its finding; copies under `design/` left as they are; code +that looks like a mistake, by file and line; findings dropped at step 4; docs listed for +reading that were not read whole. diff --git a/skills/docs-check/scan.md b/skills/docs-check/scan.md new file mode 100644 index 00000000..4cb8c0eb --- /dev/null +++ b/skills/docs-check/scan.md @@ -0,0 +1,30 @@ +# Scan docs + +- The person named the docs to scan: list those, each a doc or a folder of them. + +```bash +node scripts/docs.mjs --all docs/resume.md packages/verify/ +``` + +- Otherwise list every doc: + +```bash +node scripts/docs.mjs --all +``` + +Each line is a doc, then the sources that decide what it says. A doc ending in `/` is every doc +below it, a source ending in `/` every file below it, and `*` stands for one name. + +Take the lines one at a time, and finish each before the next: all of them together are more +than can be held at once. + +1. Read the doc whole. For each sentence that says what the code does (a name, a default, a + number, an order, what happens when), open the source that decides it and find the line. + Write a finding, in the form step 3 of [SKILL.md](SKILL.md) gives, only where that line says + otherwise. A sentence about how it was before ("up to 0.9", "no longer") is a finding too: + the rule *A doc is short, and true to the code* in `design/build.md` rules history out. Cite + that rule in place of a source line. +2. Do steps 4 and 5 of SKILL.md for this doc's findings. +3. Write `: findings, kept`, so that no doc listed is passed over. + +After the last line, go on from step 6 of SKILL.md. diff --git a/skills/h5p-author/references/authoring.md b/skills/h5p-author/references/authoring.md index 460f008f..c2806c91 100644 --- a/skills/h5p-author/references/authoring.md +++ b/skills/h5p-author/references/authoring.md @@ -36,8 +36,8 @@ change it: address, the one H5P plays: `youtube.com/watch?v=…` or `youtu.be/…` (a Short's is taken as its video's), `vimeo.com/` and the number, a Panopto viewer's `…/Panopto/Pages/Viewer.aspx?id=…`, Echo360's `echo360.org/media/…/h5p`. -- Pictures: `.png`, `.jpg`, `.gif`, `.bmp`. Video: `.mp4`, `.webm`. Audio: `.mp3`, `.m4a`, - `.wav`, `.ogg`. H5P takes no SVG or WebP. +- Pictures: `.png`, `.jpg`, `.gif`, `.bmp`. Video: `.mp4`, `.webm`, `.ogg`. Audio: `.mp3`, + `.m4a`, `.wav`, `.ogg`, `.webm`. H5P takes no SVG or WebP. - A picture you draw, where one teaches what words alone do not (a cycle, a process, the parts of a thing, a chart of the material's numbers) or where the type needs a picture the user did not give. Only a diagram, a chart or a simple flat illustration: never a photograph or anything diff --git a/skills/h5p-author/references/build/built-here.md b/skills/h5p-author/references/build/built-here.md index a2fa99ed..24dcb88e 100644 --- a/skills/h5p-author/references/build/built-here.md +++ b/skills/h5p-author/references/build/built-here.md @@ -4,7 +4,7 @@ A source with a problem writes nothing: the build lists every problem by its path, so fix them all and run it again under the same name. Once a build has written its file it never writes -over it, so a later build takes a new name (`course-2.h5p`). Copy the one you hand over to the +over it, so give a later build a new name (`course-2.h5p`). Copy the one you hand over to the name the user asked for without writing over a file already there (`cp -n`). If that name is taken, take a new name and say so. Never delete or overwrite a file to free a name. Pass the build's notes on to the user: texts left in English, a slide that holds diff --git a/skills/h5p-author/references/types/H5P.Audio.md b/skills/h5p-author/references/types/H5P.Audio.md index 7d5400c9..24ab59a2 100644 --- a/skills/h5p-author/references/types/H5P.Audio.md +++ b/skills/h5p-author/references/types/H5P.Audio.md @@ -2,7 +2,7 @@ An audio player. On its own it suits a listening task beside other content; in a page, a book or on a card it is a part. -- `files` is the recording: a file beside the source (`.mp3`, `.m4a`, `.wav`, `.ogg`) or a web address of one. +- `files` is the recording: a file beside the source (`.mp3`, `.m4a`, `.wav`, `.ogg`, `.webm`) or a web address of one. - `playerMode` `"full"` shows the full controls, `"minimalistic"` a play button. ## Example diff --git a/skills/h5p-author/references/types/H5P.Image.md b/skills/h5p-author/references/types/H5P.Image.md index f9ef9120..afaf671a 100644 --- a/skills/h5p-author/references/types/H5P.Image.md +++ b/skills/h5p-author/references/types/H5P.Image.md @@ -2,7 +2,7 @@ A picture, a part other content holds: in a page, a book, a slide, a hotspot or an answer. Not a content type on its own. -- `file` is the picture, a file beside the source (`.png`, `.jpg`, `.gif`) or a web address of one; the build reads its size. +- `file` is the picture, a file beside the source (`.png`, `.jpg`, `.gif`, `.bmp`) or a web address of one; the build reads its size. - `alt` is required: what the picture shows, for a learner who cannot see it. A picture that only decorates is `"decorative": true` instead. ## Example diff --git a/skills/h5p-author/references/types/H5P.InteractiveVideo.md b/skills/h5p-author/references/types/H5P.InteractiveVideo.md index aea3037f..d0c8fce6 100644 --- a/skills/h5p-author/references/types/H5P.InteractiveVideo.md +++ b/skills/h5p-author/references/types/H5P.InteractiveVideo.md @@ -2,7 +2,7 @@ A video with questions, text and links appearing over it at set times, a bookmark menu, and a summary task at the end. -- `interactiveVideo.video.files` is the video: a file beside the source (`.mp4` or `.webm`), a web address of one, or the address of a video on YouTube, Vimeo, Panopto or Echo360, which plays from there. +- `interactiveVideo.video.files` is the video: a file beside the source (`.mp4`, `.webm` or `.ogg`), a web address of one, or the address of a video on YouTube, Vimeo, Panopto or Echo360, which plays from there. - Each item of `interactiveVideo.assets.interactions` shows its `action` (sub-content) from `duration.from` to `duration.to`, in seconds. A text over the video is H5P.Text: H5P.AdvancedText is not taken here. `pause: true` stops the video for it; `displayType` `"button"` shows an icon to open it, `"poster"` shows it open over the video. The build places each interaction; give `x` and `y` (percent of the picture) to place one yourself. - The build sizes a poster by what it holds: a question 17 by 16, room for four short answers and its buttons; a text as wide as keeps it short; a picture in its own shape. `width` and `height` size one yourself, in em: the video is 40 wide and 22.5 tall at 16:9. Check posters in the preview; on a phone they show as buttons. - Bookmarks: `interactiveVideo.assets.bookmarks`, `[{ "time": 30, "label": "…" }]`. diff --git a/skills/h5p-author/references/types/H5P.Video.md b/skills/h5p-author/references/types/H5P.Video.md index 8ac0ada2..0776cf28 100644 --- a/skills/h5p-author/references/types/H5P.Video.md +++ b/skills/h5p-author/references/types/H5P.Video.md @@ -2,7 +2,7 @@ A video player, a part other content holds: in a page, a book, a slide or a scenario. Not a content type on its own; Interactive Video is the one with questions over a video. -- `sources` is the video: a file beside the source (`.mp4`, `.webm`), a web address of one, or the address of a video on YouTube, Vimeo, Panopto or Echo360, which plays from there and shares the viewing with that site. +- `sources` is the video: a file beside the source (`.mp4`, `.webm`, `.ogg`), a web address of one, or the address of a video on YouTube, Vimeo, Panopto or Echo360, which plays from there and shares the viewing with that site. - Captions: `a11y`, `[{ "label": "English", "kind": "captions", "srcLang": "en", "track": { "path": "captions.vtt" } }]`. ## Example diff --git a/skills/h5p-normalize/SKILL.md b/skills/h5p-normalize/SKILL.md index c9f53b18..cfa4c658 100644 --- a/skills/h5p-normalize/SKILL.md +++ b/skills/h5p-normalize/SKILL.md @@ -26,10 +26,12 @@ Read the summary at the end. The `media` line is the verdict: media 6 files: 4 inflated to stored, 1 mp4 index moved to front, 1 already as they should be → normalize it -A `notes` line names what it leaves as it is: a fragmented mp4, an encrypted entry, a video it -could not remux. A damaged entry (its bytes not matching their CRC) stops the run with the -entry named. Report both to the user rather than working around them. A URL works in place of -the path. +A file's line in the listing names what it leaves as it is, such as a fragmented mp4 or a video +it could not remux; a `notes` line names a file it dropped or a compression method it could not +read. An encrypted entry stops the run with the entry named, and so does a damaged one (its bytes +not matching their CRC) that the run reads: a dry run reads few, the write every entry it rewrites. +Report these to the user rather than working around them. A URL works in place +of the path. If the dry run finds nothing to do and the video is still slow, the package is not the cause: the host may ignore `Range` requests, so the whole archive downloads before anything plays @@ -59,12 +61,12 @@ files are deflated. The package grows by about 1% and every H5P host still accep ## 4. Hand over Give the user the `revision` line from the summary with the file. It is the build identifier -h5p-offline-player puts in `context.revision` on every xAPI statement from this package, so a -completion record can later be matched to this exact build; it belongs in their release notes -or version record. Tell them to publish the normalized file, keep the original, and that a -host which honours `Range` requests (most static hosts, GitHub Pages included) is what makes -the seeking instant; on one that does not, the boot is early but the video still waits for its -bytes. +h5p-offline-player puts in `context.revision` on the xAPI statements from this package, unless +the content set its own, before `; libraries …` where the site's `libraries` supplied any, so a +completion record can later be matched to this exact build; it belongs in their release notes or +version record. Tell them to publish the normalized file, keep the original, and that a host +which honours `Range` requests (most static hosts, GitHub Pages included) is what makes the +seeking instant; on one that does not, the boot is early but the video still waits for its bytes. ## What it does not do diff --git a/skills/h5p-player-setup/references/options.md b/skills/h5p-player-setup/references/options.md index d27c3177..56f9065c 100644 --- a/skills/h5p-player-setup/references/options.md +++ b/skills/h5p-player-setup/references/options.md @@ -12,8 +12,8 @@ the inside is shadow DOM. Attributes on the element: `frame` (the action bar), `copyright`, `export`, `icon`, `embed` (bare = on), `fullscreen="off"`, `download-url`, `embed-code`, `custom-css`, `custom-js`, `reporting`, `activity-id`; and `user`, the learner H5P names in statements, as a property, never -an attribute. A button stays off when its target is missing: `export` without `download-url`, -`embed` without `embed-code`. `activity-id` defaults to the package's URL. +an attribute. A button stays off when its target is missing: `export` needs `download-url` or a +package URL, `embed` needs `embed-code`. `activity-id` defaults to the package's URL. Language is automatic: H5P's own buttons and dialogs are in the content's language, the one its `h5p.json` names, so a German package shows them in German on any page. `lang`, which the element diff --git a/skills/h5p-verify/SKILL.md b/skills/h5p-verify/SKILL.md index 5b54c795..8aac5250 100644 --- a/skills/h5p-verify/SKILL.md +++ b/skills/h5p-verify/SKILL.md @@ -55,7 +55,7 @@ Exit 2: the check could not run (no browser, no such file). |---|---|---| | `bad-archive` … `played untrusted, so its own copy of does not run` | the package carries a library the pack does not have | ask whether the user made or trusts the package; if so, rerun with `--trusted` | | `bad-archive` … `The library sources do not have , and the package does not carry` | a library neither the pack nor the package has | name a source that has it with `--libraries`, or re-export the package with its libraries and check it with `--trusted` | -| `bad-archive` … `Missing: ` (with `--trusted`) | no library folders, not the versions `content.json` names, or a version one of the package's own libraries asks for in its `library.json` and the package does not carry | add the library folders, or rerun with `--libraries pack` if the destination supplies libraries | +| `bad-archive` … `Missing: `, or `is missing of its libraries: ` (with `--trusted`) | no library folders, not the versions `content.json` names, or a version one of the package's own libraries asks for in its `library.json` and the package does not carry | add the library folders, or rerun with `--libraries pack` if the destination supplies libraries | | `bad-archive` otherwise | no `h5p.json`, bad entry names, not a zip | fix the packaging | | `runtime: …` with `state: error` | the runtime threw before the content came up: a script of a library it needed failed, or `content.json` breaks the content type at start | same fixes as the next row; the message names what threw | | `N uncaught errors while booting: …` | a library script threw as it loaded: a dependency listed that is not a runtime library (`H5PEditor is not defined`), or `content.json` missing a field the content type reads at start | for a manifest problem, list only runtime libraries in `preloadedDependencies`; for a content problem, compare `content.json` with `/semantics.json` inside the package and fill in the fields it expects | @@ -101,9 +101,11 @@ a package that behaves at start-up can still read and send what other packages s that plays it. Run `--trusted` only on packages you would open yourself; by default none of the package's own scripts run. -Give the user the `revision` with the file — it is the build identifier every xAPI statement -from this package will carry. Take it from `report.json` (or `--json`): the summary line shows -only its first characters, ending in `…`. +Give the user the `revision` with the file — it is the build identifier the player puts on the +xAPI statements about this package's activities, unless the content set its own or the load +ended before the package was indexed: up to `;` the package's own, and after it the libraries +this run played with, which a site with other libraries will not repeat. Take it from +`report.json` (or `--json`): the summary line shows only its first characters, ending in `…`. ## Let the user play it