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
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Every change to this repository needs review by the owner. Studio runs the Python in modules/ on a
# learner's machine, so what is merged here is the safety control for that code (ADR-010, CONTRIBUTING
# "Security review"). This takes effect once the required-review rule of the `main` ruleset is enabled (pending).
* @galib9690
48 changes: 31 additions & 17 deletions .github/workflows/build-api.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
name: Build Modules API

# Regenerates api/modules.json and api/courses.json with scripts/build_api.py (the same code a local
# run uses). Triggered by anything that can change what the API says: module sources and manifests,
# course definitions and the shared code that is inlined into modules. The daily run only refreshes
# GitHub reaction counts.
# ADR-010 trust anchor: nothing commits to main without review.
# - 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.
on:
push:
branches: [main]
paths:
- 'modules/**'
- 'courses/**'
- 'shared/**'
schedule:
# Refresh reaction counts daily at 06:00 UTC
- cron: '0 6 * * *'
- 'api/**'
- 'scripts/build_api.py'
workflow_dispatch:

permissions:
contents: write
discussions: read

jobs:
build:
verify:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
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 }}
Expand Down Expand Up @@ -92,15 +104,17 @@ jobs:
else:
print("No reaction count changes")
EOF

- name: Commit updated API
- 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
git commit -m "ci: rebuild api/modules.json and api/courses.json [skip ci]"
git push
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
6 changes: 5 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ jobs:
- name: CSP and external-host check (only the Google Fonts hosts are allowed)
run: python scripts/check_csp.py

- name: API files are current
- name: API files are current (includes the per-file sha256 of every module and course)
run: python scripts/build_api.py --check

- name: Python tests
run: python -m pytest tests -q

- name: Node tests
run: node --test tests/js/*.test.js

- name: Risky-call lint of lesson cells (warnings for the reviewer, not a sandbox)
continue-on-error: true
run: python scripts/lint_cell_risk.py
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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 — Trust anchor (ADR-010 Amendment 1, step 1)

No lesson content changed; module versions are unchanged.
- `api/modules.json` and `api/courses.json`: every entry carries `files` (path + sha256 of each file Studio downloads: `module.html`; for a course `course.json` plus each member's `module.html`) and `content_sha256`. Schema in `api/README.md`. Generated by `scripts/build_api.py`; `tests/test_trust_anchor.py` checks the committed hashes equal the files.
- `scripts/lint_cell_risk.py`: reviewer aid listing risky calls in cell code (warnings, not a sandbox). Non-blocking PR step. Today: 1 finding (the optional NWIS cell of real-streamflow-data imports `dataretrieval`, as documented in the lesson).
- `.github/workflows/build-api.yml` no longer commits to `main`: on push it only verifies the committed API (`build_api.py --check`); the cosmetic reaction-count refresh runs on manual dispatch and pushes a `bot/api-refresh-*` branch for a reviewed PR. This lets `main` require review with no bot bypass (deploy keys are disabled for the organisation and GitHub refused a GitHub Actions bypass).
- `.github/CODEOWNERS` (`@galib9690`) and a "Security review" section in CONTRIBUTING.md, including that `trustLevel` is a publisher label, not a scientific review.

## 2026-11-24 — Light theme fast-track (shared theme tokens, two pilot lessons)

Owner approved the fast-track of docs/vision-2040/findings/module-theme-study-2026-11-24.md. Text, numbers and claims are unchanged; only colours and styles moved.
Expand Down
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ python scripts/render_static_outputs.py --check # a cell's pre-rendered output
python scripts/gen_docs.py --check # README table and course page match 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
python scripts/build_api.py --check # api/*.json are current (including the per-file sha256)
python scripts/lint_cell_risk.py # reviewer aid: risky calls in cell code (warnings; not a sandbox)
python -m pytest tests -q # use /opt/miniconda3/bin/python -s -E locally in the AI-Hydro workspace
node --test tests/js/*.test.js
```
Expand All @@ -140,3 +141,20 @@ Regenerate instead of editing by hand: `build_modules.py`, `render_static_output
## PR review

Automated: the checks above. Human review checks branding compliance, accuracy of the hydrology, and originality. The API's `certification.metadata_complete` only says the manifest is complete; `certification.scientific_review` stays `null` until a reviewer records a review.

## Security review

A module is Python that AI-Hydro Studio runs **on the learner's computer, with the learner's permissions**. Merging a pull request here is therefore the safety control for that code; there is no sandbox behind it. `.github/CODEOWNERS` names the owner who must review every change.

Reviewers, in addition to branding, hydrology and originality:

1. **Read what each Python cell does**, not only what the prose says it does. Run `python scripts/lint_cell_risk.py` (the PR check runs it too and shows warnings). It flags `subprocess`, `os.system`, `socket`, `requests`/`urllib`/`http.client`, `shutil.rmtree`, `eval`/`exec`, environment reads, and writes to absolute, `~` or `..` paths. It lints only the Python cells (page JavaScript is covered by `check_csp.py`) and does not detect reads of absolute paths. It is a pointer for human reading: it misses obfuscated code and flags harmless code, so a clean run is not approval.
2. **No network, no subprocess, no file writes outside the working directory** unless the lesson has a stated teaching reason, written in the PR description and in the cell's own description line. Today the one flagged cell is the optional NWIS request in `real-streamflow-data`, which says it needs the internet. A cell may read its own bundled `data/` and compute.
3. **Check the diff of `module.html`, not the sources alone.** Studio downloads the built `module.html`, so review that file (the `build_modules.py --check` gate keeps it equal to the sources).
4. **Regenerate the API in the same PR** (`python scripts/build_api.py`). The index carries a sha256 of every file Studio downloads for each module and course (see `api/README.md`); the PR check fails if they do not match the files.

What Studio is designed to do with this: verify the published sha256 of what it downloads before running it and ask the learner again when a module's content changes (ADR-010 Amendment 1, step 2). That is **not released yet: today nothing verifies the hash**, so review here is the only control.

The owner is asked to review every change through `.github/CODEOWNERS`, which takes effect once the required-review rule of the `main` ruleset is enabled (pending).

**`trustLevel` is a publisher label, not a scientific review.** A course marked `official` was published by the AI-Hydro maintainers; it does not mean the hydrology was independently reviewed. Studio shows such content as "Draft — AI-assisted review only" unless `certification.scientific_review` records a human review.
6 changes: 6 additions & 0 deletions PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ Not done: rendering the three new lessons inside the installed AI-Hydro build; o
Branch `feat/light-theme-fasttrack`. Shared `theme.css`/`theme.js`; reading-a-hydrograph 0.5.0 and watershed-runoff 0.5.0 on the tokens; evapotranspiration-budyko 0.1.1 axis contrast fix; course 0.4.2; catalog regenerated. Tests: T1 (tokens), T2 (ratchet), T3 (HydroTheme) added; the existing suites pass (see the PR for the commands and counts).
Not done: the other eight lessons; the extension side that sets `data-aihydro-theme` (separate PR); a check in the installed AI-Hydro build (owner's T5); a light stage for the Fish River scene.

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

Added per-file sha256 and `content_sha256` to the generated API, the risky-call lint, CODEOWNERS and the CONTRIBUTING security-review section (see CHANGELOG.md).
Verification: `/opt/miniconda3/bin/python -s -E -m pytest tests`, `node --test tests/js/*.test.js` and the scripts of the PR workflow.
Not done: the ruleset's required-review rule (owner setting; blocked by the `build-api.yml` push to `main`), and Studio-side verification of the hashes (step 2, extension repository).

17 changes: 17 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ An array, one entry per `modules/<id>/manifest.json`, sorted by module id. Every
| `updatedAt` | **author date of the last git commit that touched `modules/<id>/`** (not the build date; without history it keeps the previous value) |
| `downloadCount`, `githubReactions`, `discussionUrl` | kept from the previous file; reactions are refreshed from GitHub Discussions by the workflow |
| `certification` | see below |
| `files`, `content_sha256` | the trust anchor, see below |

### `certification`

Expand All @@ -31,6 +32,22 @@ An array, one entry per `modules/<id>/manifest.json`, sorted by module id. Every

The old `certified` / `certified_at` fields are gone: a "certified" badge implied a scientific validity the check never established.

### `files` and `content_sha256` (trust anchor)

```json
"files": [{"path": "modules/dem-to-twi/module.html", "sha256": "<64 hex>"}],
"content_sha256": "<64 hex>"
```

- `files` lists every file Studio downloads and runs for the module, sorted by `path`. Today that is one file: `module.html` (shared code, data and static outputs are inlined into it by `build_modules.py`; `installModule` fetches only `downloadUrl`). `path` is relative to the repository root, so the file is served at `https://raw.githubusercontent.com/AI-Hydro/Modules/main/<path>`.
- `sha256` is the SHA-256 of the file's exact bytes (the repository bytes; raw.githubusercontent.com does not transform them).
- `content_sha256` is the SHA-256 of the text made of one line `"<sha256> <path>\n"` per file, in `files` order (the `sha256sum` format). From the repository root: `sha256sum <the paths> | sha256sum`.
- A client that verifies the download compares the bytes it received with `sha256`; a change of `content_sha256` between two reads of the index means the module's content changed.
- This index is itself a file on `main` (and GitHub Pages), so the hashes protect against a changed file with an unchanged index, not against a compromised `main`. Review of what is merged (CONTRIBUTING "Security review") is the control for that.
- Nothing regenerates the hashes on `main` automatically: every PR must commit the regenerated API (`build_api.py --check` in `checks.yml`), and the `Build Modules API` workflow only verifies `main` after a push. The hashes therefore attest that the index and the files agree; the required review on `main` (repository ruleset) is the real control.

## `courses.json`

An array, one entry per `courses/<dir>/course.json`. Fields: `courseId`, `title`, `abstract`, `version`, `license`, `estimatedHours`, `topic`, `tags`, `trustLevel`, `citation`, `citationUrl`, `isFeatured` and the author fields come from `course.json`; `contributors` is its `authors`; `modules` lists `{moduleId, title, estimatedMinutes, prerequisites?}` in course order; `level` is the common level of the course's modules (`mixed` if they differ); `manifestUrl` and `githubUrl` are derived from the course directory; `updatedAt` is the last git commit touching the course directory.

Every course entry also has `files` and `content_sha256` in the same shape: `course.json` (the `manifestUrl`) plus the `module.html` of each member module (the files `installCourse` fetches).
51 changes: 51 additions & 0 deletions api/courses.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,57 @@
"isFeatured": true,
"manifestUrl": "https://raw.githubusercontent.com/AI-Hydro/Modules/main/courses/intro-to-hydrology/course.json",
"githubUrl": "https://github.com/AI-Hydro/Modules/tree/main/courses/intro-to-hydrology",
"files": [
{
"path": "courses/intro-to-hydrology/course.json",
"sha256": "1aea2b433cf037c151546e252451448000485713788bc9b2ca81df9bc3ba699e"
},
{
"path": "modules/baseflow-separation/module.html",
"sha256": "e703349a2d579a12052ac820e865df2cbe2e8c44b10b11cbe6e782d1adf408a0"
},
{
"path": "modules/capstone-basin-story/module.html",
"sha256": "09e159bf1118efb9d11b480529d811e433fa33378ecdd7ef79faf3ed7c1627eb"
},
{
"path": "modules/course-certificate/module.html",
"sha256": "76e846f47823ce82d4fb456c91faa18b950eded38f3c59cde32beb2e2772d375"
},
{
"path": "modules/dem-to-twi/module.html",
"sha256": "8c01bf4c4f67057422ff192074049b92070bce402bf1c60c155eb8fae9fa2544"
},
{
"path": "modules/evapotranspiration-budyko/module.html",
"sha256": "202b78b1a4e3ad7c773943659f5b486102279d5bf26c508dc25d12882dace274"
},
{
"path": "modules/precipitation-point-to-basin/module.html",
"sha256": "c3a6ae247ec0e0be7ff9455052c7c6571139f22980d631ef91dfd1ad47c78638"
},
{
"path": "modules/reading-a-hydrograph/module.html",
"sha256": "46a8eb909f0a4b6bd5ca064f62a0a8f773920935cc74c6d12590564dfb1e5159"
},
{
"path": "modules/real-streamflow-data/module.html",
"sha256": "f45b28a9ccbf5d9681a66201b00e116905e742a53d4d873ec6d922ffc7dfc5ad"
},
{
"path": "modules/runoff-generation/module.html",
"sha256": "e234bc866545daa37aba39439afd1dc4a7f86a05df6b9c119b867047df8890ad"
},
{
"path": "modules/water-cycle-in-motion/module.html",
"sha256": "9040e72d333dfc2bc58ecc77bc3f176b4ee6c9a8c66033cb5027d96b0b207589"
},
{
"path": "modules/watershed-runoff/module.html",
"sha256": "7aa0db1fce57748df698be6e5383cd0e1b7c19d8fbad28e28bf69f713b198a3a"
}
],
"content_sha256": "8dda0cb91e8b594daee23dc997f2a12056c0c96d83804b2dafe315599dc89698",
"updatedAt": "2026-11-24"
}
]
Loading
Loading