Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 2 additions & 93 deletions .github/workflows/build-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ name: Build Modules API
# - On every push to main that can change the API, `verify` checks that the committed api/*.json
# (including the per-file sha256 values) matches the files. PRs already have to commit the
# regenerated API (checks.yml runs build_api.py --check), so main never needs a bot commit.
# - Discussion reaction counts are cosmetic. `refresh-reactions` runs only on manual dispatch: it
# rebuilds the API, refreshes the counts and pushes a branch `bot/api-refresh-<run id>`; open a PR
# from it and merge it like any other change.
# - There is no reaction-count refresh: Discussions are disabled on this repository, so the count was
# always 0. `githubReactions` stays in the API (the extension reads it) and is not refreshed.
on:
push:
branches: [main]
Expand All @@ -16,11 +15,9 @@ on:
- 'shared/**'
- 'api/**'
- 'scripts/build_api.py'
workflow_dispatch:

jobs:
verify:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -30,91 +27,3 @@ jobs:
fetch-depth: 0 # updatedAt comes from the last git commit touching each module
- name: Committed API matches the files (hashes included)
run: python3 scripts/build_api.py --check

refresh-reactions:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write # pushes a bot/ branch only; main is protected by the repository ruleset
discussions: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build api/modules.json and api/courses.json
run: python3 scripts/build_api.py
- name: Scrape GitHub Discussion reactions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 - <<'EOF'
import json, subprocess, os

api_path = "api/modules.json"
if not os.path.exists(api_path):
print("No api/modules.json found, skipping reaction scrape")
exit(0)

with open(api_path) as f:
items = json.load(f)

repo = "AI-Hydro/Modules"
updated = False

for item in items:
module_id = item["moduleId"]
title = item.get("title", module_id)

search_result = subprocess.run(
["gh", "api", f"repos/{repo}/discussions",
"--jq", f'[.[] | select(.title == "Module: {title}")] | first'],
capture_output=True, text=True
)
discussion = None
if search_result.returncode == 0 and search_result.stdout.strip() not in ("", "null"):
try:
discussion = json.loads(search_result.stdout.strip())
except Exception:
pass

if discussion:
reactions_result = subprocess.run(
["gh", "api", f"repos/{repo}/discussions/{discussion['number']}/reactions",
"--jq", "length"],
capture_output=True, text=True
)
if reactions_result.returncode == 0:
try:
count = int(reactions_result.stdout.strip())
if item.get("githubReactions") != count:
item["githubReactions"] = count
updated = True
except ValueError:
pass
new_url = discussion.get("html_url", "")
if new_url and item.get("discussionUrl") != new_url:
item["discussionUrl"] = new_url
updated = True

if updated:
with open(api_path, "w") as f:
json.dump(items, f, indent=2)
f.write("\n")
print("Updated reaction counts in api/modules.json")
else:
print("No reaction count changes")
EOF
- name: Push a refresh branch (open a PR from it)
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add api/modules.json api/courses.json
if git diff --staged --quiet; then
echo "No changes to the API files"
else
branch="bot/api-refresh-${{ github.run_id }}"
git switch -c "$branch"
git commit -m "ci: refresh API reaction counts"
git push origin "$branch"
echo "Open a PR: https://github.com/${{ github.repository }}/compare/main...$branch"
fi
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- name: README module table and course page are generated from the manifests
run: python scripts/gen_docs.py --check

- name: CONTRIBUTORS.md is generated from the manifests
run: python scripts/gen_contributors.py --check

- name: Manifests, embedded manifests and course.json are valid and agree
run: python scripts/validate_manifests.py

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to the learning modules. Versions are per module (`manifest.json` and the manifest embedded in `module.html` carry the same number).

## 2026-11-30 — Contribution-ready (licences, standalone lessons, credit)

No lesson content changed; module versions are unchanged. Owner approval: "go ahead with the fixes" (2026-11-30), covering CC BY 4.0 for lesson content and MIT for code.
- `LICENSE` (CC BY 4.0, lesson content) and `LICENSE-CODE` (MIT, 2026, "AI-Hydro contributors"; scripts, tests, shared and tools code, and the code inside lessons). README and CONTRIBUTING gain a Licence section; bundled data keeps its source licences (`PROVENANCE.json`). Every manifest and the course already say `CC-BY-4.0`: no conflict.
- A lesson may be standalone: `tests/test_repo.py` no longer requires every module to be in the flagship course. Kept: valid manifest, unique `moduleId`, course members exist with matching `courseId`/`courseOrder`. `validate_manifests.py` now also rejects a `courseId`/`courseOrder` on a module no course lists.
- `tests/test_wave2_repo.py`: the total page-growth budget (1.5 MB over the Wave 1 baseline, 1.13 MB already used) is removed so new lessons can be added; the 250,000-byte cap per page stays.
- CONTRIBUTING: complete checklist against the actual checks (CHANGELOG heading, theme-ratchet baseline, quiz shape, DOI gate, page cap, generated files), a Licence and a Credit section; optional manifest `contributors`.
- `CITATION.cff`, `CONTRIBUTORS.md` generated by `scripts/gen_contributors.py` (`--check` runs in `checks.yml`). Humans only; an entry naming an AI tool goes to an "AI assistance" note.
- Reaction counts: the `refresh-reactions` job and the manual dispatch are removed from `build-api.yml` (Discussions are disabled on this repository, so every count was 0). `githubReactions` stays in the API because the extension reads it; it is documented as not refreshed.

## 2026-11-30 — Trust anchor (ADR-010 Amendment 1, step 1)

No lesson content changed; module versions are unchanged.
Expand Down
20 changes: 20 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cff-version: 1.2.0
message: "If you use these lessons or code, please cite them as below (no DOI has been issued yet)."
title: "AI-Hydro Learning Modules"
type: dataset
authors:
- family-names: Galib
given-names: Mohammad
affiliation: "Purdue University"
repository-code: "https://github.com/AI-Hydro/Modules"
url: "https://github.com/AI-Hydro/Modules"
license: CC-BY-4.0
abstract: >-
Interactive hydrology lessons and courses for AI-Hydro: self-contained HTML modules with
executable Python cells, a static catalogue API, and the scripts that build and check them.
Lesson content is CC BY 4.0; code is MIT (see LICENSE and LICENSE-CODE).
keywords:
- hydrology
- education
- interactive learning
- AI-Hydro
55 changes: 45 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,48 @@

## Quick checklist

- [ ] `modules/<your-id>/module.html` — the self-contained module
- [ ] `modules/<your-id>/manifest.json` — metadata (required fields below)
- [ ] `modules/<your-id>/README.md` — description, learning objectives, prerequisites
- [ ] `modules/<your-id>/thumbnail.png` — 640×360 screenshot (optional but recommended)
- [ ] Module renders correctly in a plain browser with no AI-Hydro bridge (standalone rule below)
- [ ] Module opens without CSP errors in AI-Hydro HTML Preview (`python scripts/check_csp.py` is clean)
- [ ] At least one interactive element (slider, quiz, map, chart)
- [ ] A checkpoint built with the shared quiz engine, with at least one numeric or interpretive item whose answer is computed from the lesson
- [ ] Provenance footer with data sources and citations
- [ ] `python scripts/build_modules.py`, `python scripts/gen_docs.py` and the tests pass (see "Checks")
A lesson can stand alone or belong to a course. **Course membership is not required**: a standalone lesson has no `courseId` or `courseOrder`, and no `course.json` lists it. Items with a bracket are enforced by CI (`.github/workflows/checks.yml`) through the named check; items marked **human review** are not machine-checked and are what the reviewer reads for.

Files
- [ ] `modules/<your-id>/module.html`: the self-contained lesson, under 250,000 bytes [`test_wave2_repo`]. The directory name is the `moduleId` (lowercase, hyphens)
- [ ] `modules/<your-id>/manifest.json`: metadata (fields below) [`validate_manifests.py`]
- [ ] `modules/<your-id>/README.md`: description, learning objectives, prerequisites (its presence is checked) [`validate_manifests.py`]
- [ ] `modules/<your-id>/thumbnail.png`: 640x360 screenshot (optional but recommended)
- [ ] `modules/<your-id>/data/` and `static/` if the lesson bundles data or pre-rendered outputs (see below)
- [ ] An entry in `CHANGELOG.md`, with a heading of the form `### <your-id> … → <version>` (for example `### <your-id> new → 0.1.0`; the id, an arrow and the manifest version are matched) [`tests/test_repo.py::test_changelog_records_each_version`]
- [ ] A baseline entry for the theme ratchet: run `python tests/test_theme_ratchet.py --write` once the page is final; it records your count of hard-coded colours in `tests/theme_hex_baseline.json`, and the count may only go down afterwards [`tests/test_theme_ratchet.py::test_every_module_has_a_baseline_and_none_is_over_it`]
- [ ] Every DOI the lesson cites passes the cite-verify gate and has a `| <doi> | PASS |` row in `CITATIONS.verified.md` [`tests/test_repo.py::test_every_doi_in_the_modules_passed_the_gate`]

Lesson
- [ ] Renders in a plain browser with no AI-Hydro bridge (standalone rule below); every executable cell has a pre-rendered output, with alt text for each figure [`test_wave2_repo`]
- [ ] Opens without CSP errors: `python scripts/check_csp.py` is clean (no external scripts; Google Fonts is the only external host, at most two font links)
- [ ] **Human review:** every control that works by dragging also works from the keyboard (see Accessibility rules). CI only checks the structural hygiene: no inline `onclick`/`oninput`/`onchange`/`onkeydown`, no `contenteditable`, no `postMessage` to `'*'`, nothing "locked" [`tests/test_wave2_repo.py::test_hygiene`]
- [ ] The checkpoint uses the shared quiz engine and has **at least 4 items, at least 3 of type `choice`, and at least 1 `numeric` item whose answer is a function computed from the lesson** (not a typed number). Every item has an `explain`, and each choice's `correct` index is in range [`tests/test_quiz_answers.py`]. The course certificate is the only lesson without a checkpoint
- [ ] **Human review:** data sources and citations in a Sources & Further Reading section; real data come from `scripts/extract_camels.py` with `data/PROVENANCE.json`; anything else is labelled SYNTHETIC (see "Data and citations"). Only the existing lessons' SYNTHETIC labels are tested; a new lesson's label is read by the reviewer
- [ ] **Human review:** Python cells have been read for risky calls: `python scripts/lint_cell_risk.py` (see "Security review")

Generated files (regenerate, do not edit)
- [ ] `python scripts/build_modules.py` (inlines shared code, data, manifest and static outputs)
- [ ] `python scripts/render_static_outputs.py`
- [ ] `python scripts/gen_docs.py` (README module table; course page)
- [ ] `python scripts/gen_contributors.py` (CONTRIBUTORS.md)
- [ ] `python scripts/build_api.py` (api/*.json with the per-file sha256)
- [ ] Every command in "Checks" below passes locally

## Licence of what you contribute

By opening a pull request you agree to license your contribution as follows (full texts: `LICENSE`, `LICENSE-CODE`):

- **Lesson content** (the text, figures, diagrams and course materials in `module.html`, `README.md` and `courses/`) is **CC BY 4.0**. The manifest `license` field is the **content** licence and `tests/test_wave2_repo.py` requires exactly `CC-BY-4.0`. Code copied out of a lesson is MIT (see `LICENSE-CODE`).
- **Code** (`scripts/`, `tests/`, `shared/`, `tools/`, and the Python and JavaScript in lessons) is **MIT**.
- **Data files** may carry their own source licences (CAMELS-US and USGS NWIS, Daymet, Copernicus and others). Keep the notice in `data/PROVENANCE.json` (`licence_note`), cite the source, and do not bundle data whose licence forbids redistribution.
- Only submit work you have the right to license. Say in the pull-request description if AI tools helped; they are not listed as authors.

Attribution expected from reuse of a lesson: the author(s) named in its `manifest.json` (`CONTRIBUTORS.md` lists everyone), the lesson title, the repository URL and the licence (see `CITATION.cff`).

## Credit

`author` is a person, written `"Name, Institution"`. People who helped but are not the lead author go in the optional `contributors` list of the same strings. `CONTRIBUTORS.md` is generated from these fields by `python scripts/gen_contributors.py`; CI fails if it is stale. AI tools are not authors: an entry that names one is moved to the "AI assistance" note of that file.

## Required manifest fields

Expand All @@ -35,6 +67,8 @@
}
```

Optional: `"contributors": ["Name, Institution"]`, `createdAt`. `courseId` and `courseOrder` are set only by a lesson that a `courses/<dir>/course.json` lists, and must then match it; a standalone lesson has neither. `moduleId` equals the directory name, `version` is `major.minor.patch` and the page footer shows `v<version>`.

**Valid levels:** `intro`, `intermediate`, `advanced`. **Suggested topics:** `terrain-analysis`, `streamflow`, `hydrograph`, `water-quality`, `modelling`, `remote-sensing`, `data-access`.
`updatedAt` is not kept in the manifest: the API takes it from the last git commit that touched the module. `createdAt` is optional (otherwise the first commit date is used).

Expand Down Expand Up @@ -128,6 +162,7 @@ These run on every pull request (`.github/workflows/checks.yml`) and are the sam
python scripts/build_modules.py --check # shared code, data, manifests and static outputs are inlined
python scripts/render_static_outputs.py --check # a cell's pre-rendered output matches its current source
python scripts/gen_docs.py --check # README table and course page match the manifests
python scripts/gen_contributors.py --check # CONTRIBUTORS.md matches the manifests
python scripts/validate_manifests.py # manifests valid; embedded block agrees; course graph valid
python scripts/check_csp.py # no external hosts except Google Fonts, no eval/fetch/WebSocket
python scripts/build_api.py --check # api/*.json are current (including the per-file sha256)
Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributors

Generated by `python scripts/gen_contributors.py` from the `author` and `contributors` fields of `modules/*/manifest.json` and `courses/*/course.json`. Do not edit by hand: change the manifest, run the script and commit both. `--check` runs in CI.

People are credited for authoring or contributing to a lesson or course. Lesson content is licensed [CC BY 4.0](LICENSE) (attribute the authors named in the manifest and the Sources section of the lesson); code is [MIT](LICENSE-CODE).

| Name | Affiliation | Roles | Work |
|---|---|---|---|
| Mohammad Galib | Purdue University | author, maintainer | module `baseflow-separation`; module `capstone-basin-story`; module `course-certificate`; module `dem-to-twi`; module `evapotranspiration-budyko`; module `precipitation-point-to-basin`; module `reading-a-hydrograph`; module `real-streamflow-data`; module `runoff-generation`; module `water-cycle-in-motion`; module `watershed-runoff`; course `intro-hydro-2026` |

## AI assistance

AI tools can assist with drafting and code in this repository. They are not authors and are not credited in the table above: a person is responsible for each lesson, and the pull-request review is the control (see the Security review in [CONTRIBUTING.md](CONTRIBUTING.md)). Disclose AI assistance in the pull-request description; add a line to `README.md` of the lesson if it matters for readers.
Loading
Loading