diff --git a/.claude/skills/github-pages/SKILL.md b/.claude/skills/github-pages/SKILL.md index 69d4a49..205db5b 100644 --- a/.claude/skills/github-pages/SKILL.md +++ b/.claude/skills/github-pages/SKILL.md @@ -47,7 +47,9 @@ added, checks them with `scripts/weekly-puzzle.js --check`, and deploys it in th Players get no update banner (the version does not change). Every release build also copies all weekly files from `main`, so a release never drops a published week, and regenerates (in the build, deterministically) any week not over yet that the release's prices no longer fit. Weekly files are plain JSON the game fetches only when the -Puzzles list opens and never trusts; the service worker serves them network-first. See `docs/ARCHITECTURE.md`. +Puzzles list opens and never trusts; the service worker serves them network-first. The weekly scenario rides along in +the same run: `scripts/weekly-scenario.js` writes `site/scenarios/weekly/.json` (fetched when the Scenarios list +opens), committed and deployed with the puzzle, never by a second workflow. See `docs/ARCHITECTURE.md`. ## Before you hand back a change that touches the build, deploy or loading diff --git a/.claude/skills/release/SKILL.md b/.claude/skills/release/SKILL.md index 99f8b4d..509d3fb 100644 --- a/.claude/skills/release/SKILL.md +++ b/.claude/skills/release/SKILL.md @@ -21,12 +21,16 @@ version for a weekly puzzle. To publish or fix one by hand: `node scripts/weekly `gh workflow run release.yml --ref -f tag= -f weekly=true`). A release includes every weekly file on `main` when it builds. +The weekly scenario (`site/scenarios/weekly/`, `scripts/weekly-scenario.js`) ships in the same run and the same way: +`--key`, `--force` and `--check` work alike. Its `--check` replays each week not over yet with the reference plan in +the file; a new par is just written, a week the reference no longer wins is regenerated with `rev` + 1. + **Prices change, weeks follow.** `--check` re-solves every week not over yet with the game it runs; a week whose budget no longer verifies is regenerated deterministically (the same puzzle with a new budget if that works, else a fresh one for the same key) with `rev` + 1, which resets players' stars for that week only. Past weeks are left alone unless the game rejects them. `release.yml` runs it before the tests on every deploy and fails only if a week cannot be regenerated. A change to prices, cables or cities fails `npm test` until you run `node scripts/weekly-puzzle.js --check` -and commit the regenerated files with it. +and commit the regenerated files with it (and `node scripts/weekly-scenario.js --check` for the scenarios). ## Only release when Frederic says so diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe2070b..0d1ad7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,15 +70,17 @@ jobs: fi # Weekly puzzles are published on main between releases (weekly-puzzle.yml). Every deploy ships all of them, # so neither a release nor a weekly redeploy ever drops a week that is already out. - - name: Weekly puzzles from main + - name: Weekly puzzles and scenarios from main run: | set -euo pipefail git fetch --no-tags --depth=1 origin main - if git cat-file -e FETCH_HEAD:site/puzzles/weekly 2>/dev/null; then - rm -rf site/puzzles/weekly - git checkout FETCH_HEAD -- site/puzzles/weekly - echo "Weekly puzzles: $(ls site/puzzles/weekly | grep -c '^[0-9].*\.json$')" - fi + for d in site/puzzles/weekly site/scenarios/weekly; do + if git cat-file -e "FETCH_HEAD:$d" 2>/dev/null; then + rm -rf "$d" + git checkout FETCH_HEAD -- "$d" + echo "$d: $(ls "$d" | grep -c '^[0-9].*\.json$')" + fi + done - run: npm ci # This release's prices may no longer fit a week already published: --check regenerates every week not over # yet whose budget no longer verifies (deterministically, so main's next weekly run commits the same files), @@ -89,11 +91,12 @@ jobs: # A release from before the weekly puzzles ships the files without reading them: nothing to check. if [ ! -f scripts/weekly-puzzle.js ]; then echo "This release does not read weekly puzzles yet."; exit 0; fi node scripts/weekly-puzzle.js --check + if [ -f scripts/weekly-scenario.js ]; then node scripts/weekly-scenario.js --check; fi - run: npm test if: ${{ !inputs.weekly }} - name: Test the weekly puzzles against this release if: ${{ inputs.weekly && hashFiles('scripts/weekly-puzzle.js') != '' }} - run: npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js + run: npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js $(ls tests/weekly-scenario.test.js 2>/dev/null) - name: Build site run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build - uses: actions/upload-pages-artifact@v5 diff --git a/.github/workflows/weekly-puzzle.yml b/.github/workflows/weekly-puzzle.yml index 0629330..9ac5cfa 100644 --- a/.github/workflows/weekly-puzzle.yml +++ b/.github/workflows/weekly-puzzle.yml @@ -1,8 +1,8 @@ name: Weekly puzzle -# Every Sunday morning: make this week's puzzle (scripts/weekly-puzzle.js), commit it to main as a data-only -# change, and redeploy the live release with it. Puzzle weeks start Sunday 06:00 Berlin time; 03:37 UTC is -# 04:37 in winter and 05:37 in summer, so the file is live before the week starts either way. +# Every Sunday morning: make this week's puzzle (scripts/weekly-puzzle.js) and scenario (scripts/weekly-scenario.js), +# commit them to main as a data-only change, and redeploy the live release with them, once. Weeks start Sunday +# 06:00 Berlin time; 03:37 UTC is 04:37 in winter and 05:37 in summer, so the files are live before the week starts. # # No version bump, so no release: auto-release.yml only runs when package.json changes (and pushes made with # the workflow token start no workflows at all). The deploy itself is release.yml, still the only workflow @@ -47,27 +47,29 @@ jobs: - run: npm ci # Weeks already out that main's prices no longer fit are regenerated first, so the new week's history is current. - name: Fit the published weeks to main - run: node scripts/weekly-puzzle.js --check - - name: Make the puzzle + run: node scripts/weekly-puzzle.js --check && node scripts/weekly-scenario.js --check + - name: Make the puzzle and the scenario run: | set -euo pipefail if [ -n "$KEY" ]; then [[ "$KEY" =~ ^[0-9]{4}-W[0-9]{2}$ ]] || { echo "::error::$KEY is not a week key"; exit 1; } node scripts/weekly-puzzle.js --key "$KEY" + node scripts/weekly-scenario.js --key "$KEY" else node scripts/weekly-puzzle.js + node scripts/weekly-scenario.js fi - name: Check every weekly puzzle - run: node scripts/weekly-puzzle.js --check && npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js + run: node scripts/weekly-puzzle.js --check && node scripts/weekly-scenario.js --check && npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js tests/weekly-scenario.test.js - name: Commit it to main run: | set -euo pipefail - git add site/puzzles/weekly + git add site/puzzles/weekly site/scenarios/weekly # Data only: anything else changed means something is wrong. - if git status --porcelain | grep -v ' site/puzzles/weekly/' | grep -q .; then git status --porcelain; echo "::error::unexpected changes"; exit 1; fi + if git status --porcelain | grep -v -e ' site/puzzles/weekly/' -e ' site/scenarios/weekly/' | grep -q .; then git status --porcelain; echo "::error::unexpected changes"; exit 1; fi if git diff --cached --quiet; then echo "Nothing new to commit."; exit 0; fi git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ - commit -m "Weekly puzzle $(git diff --cached --name-only | grep -o '[0-9]\{4\}-W[0-9]\{2\}' | sort -u | paste -sd ' ')" + commit -m "Weekly puzzle and scenario $(git diff --cached --name-only | grep -o '[0-9]\{4\}-W[0-9]\{2\}' | sort -u | paste -sd ' ')" git push origin HEAD:main - name: Redeploy the live release with it if: github.event_name == 'schedule' || inputs.deploy diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ecdacda..7af5613 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -74,6 +74,7 @@ Development runs on `npm run dev` (assembles on every request, reloads on save); | `.github/workflows/release.yml` | Builds and deploys to GitHub Pages, the only workflow that can | | `.github/workflows/weekly-puzzle.yml` | Sunday 03:37 UTC: makes the week's puzzle, commits it to `main` (data only, no release) and starts `release.yml` for the live release tag with `weekly=true` | | `scripts/weekly-puzzle.js`, `site/puzzles/weekly/` | The weekly puzzle generator and its output, one `.json` per week plus `index.json` (see below) | +| `scripts/weekly-scenario.js`, `scripts/lib/scenario-bot.js`, `site/scenarios/weekly/` | The weekly scenario generator, its reference player and its output (see below) | | `docs/adr/` | Decisions: GitHub Pages only (0001), one page assembled at build (0002), translations by label (0003) | ## Globals @@ -177,6 +178,16 @@ so `auto-release.yml` stays quiet) and starts `release.yml` from the live releas rebuilds that exact release with every weekly file from `main` and deploys it. Every release build takes the weekly files from `main` too, so no deploy ever drops a published week. +The weekly scenario is its twin, in the same weeks and the same workflow run: `scripts/weekly-scenario.js` writes +`site/scenarios/weekly/.json`. A template (plain data in the script) picks a theme, a home city, rules from the +scenario vocabulary (`scnRule` keys, `WEEK_MODS`) and a goal type with parameters; each goal type (`WS_GOALS` in +`src/game/60-features/94-scenarios-weekly.js`) is implemented once in the game, with its progress card. A reference +player (`scripts/lib/scenario-bot.js`) plays it through `ACT`, seeded with the scenario's seed; the goal's number is +calibrated from that run, the scenario must not be won on day 0, the reference must win with a tenth of the days to +spare, and its finishing day is the par. The file keeps the reference plan (`ref`), which `--check` replays. The game +fetches the file when the Scenarios list opens, checks it with `wsValid()` (again in `sanitize()` on load), and falls +back to the in-browser `weekly()`. + ## Saves, imports and migration - `save()` writes `S` to localStorage every few seconds and after actions, into this window's slot diff --git a/site/sw.js b/site/sw.js index 6c895f6..2e0924c 100644 --- a/site/sw.js +++ b/site/sw.js @@ -25,8 +25,8 @@ self.addEventListener('fetch', (e) => { } const local = url.origin === location.origin, fonts = /fonts\.(googleapis|gstatic)\.com$/.test(url.hostname); if (!local && !fonts) return; - // Weekly puzzles are published between releases: ask the network first, and keep a copy for playing offline. - if (local && url.pathname.startsWith('/puzzles/weekly/')) { + // Weekly puzzles and scenarios are published between releases: ask the network first, and keep a copy for offline. + if (local && (url.pathname.startsWith('/puzzles/weekly/') || url.pathname.startsWith('/scenarios/weekly/'))) { e.respondWith(fetch(req).then((r) => { if (r.ok) { const copy = r.clone(); caches.open(CACHE).then((c) => c.put(req, copy)); } return r; }) .catch(() => caches.match(req).then((r) => r || Response.error()))); return;