**Phase 01 final verification pass — all criteria green**
- Verified (nothing left to implement; all 4 task files already in `complete/`): toolchain lock, typed `Settings`+`.env.example`, debugpy bootstrap, app factory, CLI (`--host/--port/--reload/--levels-dir`, `python -m undercooked`), static shell + `/static`, security headers, no-CDN/doc guards, `validate.sh`.
- `uv sync --extra dev` → exit 0; `uv.lock` present (untracked → harness commits it with the phase).
- `uv run undercooked --host 127.0.0.1 --port 8000` → `curl /healthz` = 200 `{"status":"ok","version":"0.1.0","rooms":0}` (superset of the criterion's body — now documented in README); `curl /` = 200 shell HTML; static css/js 200; CSP/nosniff/no-referrer/DENY on 200, 404 and 405 too.
- `DEBUGPY=1`: port 5678 is held on this machine by the user's own podman dev-container debugpy adapter — **no live change made/killed**; verified via `DEBUGPY=1 DEBUGPY_PORT=5679` → listener opens, `/healthz` still 200; the occupied-port case degraded gracefully as designed (warning, server serves). Bad config → one line + exit 2 ✓.
- `bash .agents/validate.sh` (root **and** `.agents/`) → exit 0: `ruff check .` 0 errors, `pyright` 0 errors, levels-CLI notice-skip (matches README prose), **284 passed** full suite incl. 10 Playwright e2e, coverage **100.00%** (floor 90), repo hygiene clean. `uv run pytest -m e2e` → 10 passed.
- Docs fixed: README Status → phase 01 complete + next pending 02 (was pointing at `todo/01…`), documented real `/healthz` body, precedence now "CLI flags > env > .env > default", added the PLAN §13-promised **How to play** section (honest about shell-only today), Layout rows marked what exists vs phases 02/07. AGENTS.md: recorded the `data:`-URL exemption in the no-CDN rule (test allows it) and matched the session-token rule to the browser's WebCrypto/base64url implementation. Also corrected a stale "session-wide chromium" docstring in `tests/e2e/conftest.py` (fixtures are function-scoped).
- Deviations: no container build run (needs an image pull; not a phase criterion — `Containerfile`/`compose.yaml` reviewed and consistent with `docs/DEPLOYMENT.md`); `HEAD /` is 405 (routes are GET-only by design; health checks use GET). No git index/history commands run.
- Next pending phase: `02_level_content_and_validation`.
11 KiB
11 KiB
AGENTS.md — operating rules for this repository
1. Read this order, every time
.agents/PLAN.md— master design. Its Architectural Anchors table holds the LOCKED DECISIONS, which are binding on every task and phase.- This file.
.agents/phases/todo/<phase>/00_phase.md, then the task file you are executing.- The user story referenced by the phase (
.agents/user_stories/US-XX_*.md). .agents/phases/complete/*/00_phase.mdfor what already exists (do not re-build it).
2. The phased protocol
- Phase state lives in files, not chat. Pending work:
.agents/phases/todo/NN_name/(00_phase.md+NN_task.md). Finished work:.agents/phases/complete/. - Execution is owned by the
phased-executionskill (run-task.sh,run-phase.sh,auto-phase.sh). Each task runs in a fresh subprocess and must pass.agents/validate.shbefore it moves tocomplete/. That gate fails fast in this order:ruff check .→pyright→undercooked-levels validate(skipped with a notice until phase 02 creates the loader) → the fullpytestsuite with the coverage floor → repo-hygiene checks. It runs from the repo root or from.agents/. - New work is authored by the
phase-authoringskill as a phase directory — not implemented straight from chat. - Never modify
.agents/PLAN.mdor anything under.agents/phases/complete/. - Ask the user before editing an existing file in
.agents/phases/todo/. - Do not renumber or reuse phase/task numbers.
3. LOCKED DECISIONS (summary — the table in PLAN.md is authoritative)
- Python 3.12+ / uv / FastAPI / native WebSockets (
uvicorn[standard]). No Socket.IO, no SSE, no WebRTC, no REST for live game traffic. - Server-authoritative fixed-tick simulation (20 Hz) with client interpolation.
The browser never decides anything true.
src/undercooked/sim/is pure: no FastAPI, no asyncio, no I/O, no wall-clock, norandomwithout the round RNG. - No database, no ORM, no Alembic. Live state lives in the room supervisor; results/scoreboards live in memory and die with the process. User-approved deviation from the default FastAPI stack.
- Data-driven content. Levels/recipes/hazards come from YAML in
levels/loaded through validated Pydantic models. No hard-coded level or recipe lists in Python. - Client: Canvas 2D + vanilla ES modules + this repo's own SVG art. No bundler, no framework, no CDN, no analytics, no external fonts.
- Tests: pytest + Playwright. One Playwright suite per user story; multi-player stories use two browser contexts against one room.
- Quality gate: ruff + pyright + full pytest, >90% coverage on new/modified code, entire suite 100% passing before a phase may complete or commit.
4. Definition of done (every task)
- Task's own work exists at the named paths and is importable/runnable.
- Tests written for the task's logic (unit for pure logic, integration for rooms/protocol, e2e for user-visible flows) and passing.
- Full project suite passes (
uv run pytest), coverage gate met — including failures the task did not cause: fix them, do not skip, xfail, or delete tests. uv run ruff check .anduv run pyrightreport zero errors.uv run undercooked-levels validatepasses if any level/content file changed.README.mdandAGENTS.mdupdated when the change is user-visible (setup, commands, config, protocol, features, conventions). Every phase's final pass re-reviews both in full, project-wide and fixes inconsistencies, including pre-existing ones.- App still launches:
uv run undercookedserveshttp://127.0.0.1:8000/healthzwith200and the client at/. - No behavior regression in any completed phase.
5. Hard rules
- Configuration is read once, in
config.py.src/undercooked/config.pyis the only module that touchesos.environ. To add a knob: add aSettingsfield +ENV_KEYSentry + a line in.env.example+ a row in the README table (a test fails when those disagree), and read it fromget_settings(). Values are validated at startup: an impossible one raisesConfigErrorrather than half-configuring the server (undercookedprints one line and exits2). Precedence is CLI flag > environment > built-in default:__main__.pyresolves it purely, then hands the flags toconfig.apply_cli_overrides(), which is the only writer ofos.environ(so a uvicorn--reloadchild re-reads the same values).DEBUGPY=1binds a debugger listener on0.0.0.0— dev-only, never on a public host. - No external CDNs or remote assets.
tests/unit/test_no_external_assets.pyfails the build onhttp:///https://///hostreferences,@import url(,srcset, an absolute-URLfetch()/import, an absolute-URLWebSocket, orEventSourceanywhere inapp/static/**(html/css/js/svg), and requires every<script src>/<link href>/<img src>inindex.htmlto be a same-origin/static/...path. It scans the sameSTATIC_DIRserver/app.pymounts, so it cannot pass by scanning the wrong folder; the exemptions are XMLxmlnsURIs, which are identifiers the browser never fetches, and adata:URL in anindex.htmlelement attribute where the CSP already allows it (img-src 'self' data:) — the app's own bytes either way. The US-01 e2e suite additionally fails if loading the page ever issues an off-origin request. CSP isdefault-src 'self'(plusws:/wss:same-origin) and is applied byserver/headers.pyto every response, including errors. FastAPI's/docs,/redocand/openapi.jsonstay disabled because their bundled HTML pulls Swagger assets fromcdn.jsdelivr.net; the wire contract lives indocs/PROTOCOL.md(written by phase 06) instead. - Docs are guarded like code.
tests/unit/test_docs_commands.pyrequires every command line in abashfence ofREADME.md/docs/*.mdto start with a known-safe prefix (uv,podman,curl,cd,bash .agents/validate.sh,#, or a documentedVAR=valuelead) and to launch only a program declared inpyproject.toml, and keeps theUNDERCOOKED_*/DEBUGPY*names in the docs and the ones inconfig.py/.env.exampleequal in both directions. So: never document a command that does not run yet — describe it in prose until the phase that ships it.tests/unit/test_docs_index.pykeeps PLAN §13's documentation index and thedocs/tree identical (no missing doc for a shipped phase, no doc nothing promises), anddocs/TESTING.mdis the reference for test layout, markers and artifact policy. - No new technology (dependency, framework, service) without explicit written
user permission recorded in the phase's
00_phase.mdand signed off into PLAN.md. - The simulation is the single source of truth. Client-side values are guesses.
Never trust inbound coordinates, scores, timers, or level ids — validate every
inbound field against the room's state (
server/protocol.py). - Anonymous by design. No accounts, no emails, no cookies with personal data.
Identity = 24 random bytes per browser tab (
secrets.token_urlsafe(24)when the server mints one,crypto.getRandomValues+ base64url inapp/static/js/app.js, which is the same entropy and the only option in a browser) held insessionStorage. Names are sanitized, length-capped, non-authoritative. - Frame and rate limits are enforced, not suggested:
max_message_bytes,max_inputs_per_s, room caps, and message-type whitelists per room state. - Protocol changes need a version bump: editing a wire message means editing
src/undercooked/server/protocol.py,docs/PROTOCOL.md, and the client in the same task, and bumpingPROTOCOL_VERSION(PLAN §11). - Determinism is a contract.
sim/step.pymust produce identical state given the same seed and input script — the replay tests intests/sim/are the guard. - ntfy is outbound-only. Never use it to ask questions or wait for approval. If a task is ambiguous, make the best judgment consistent with PLAN.md, or stop and let the user rewrite the task.
- Commits are made by the pipeline harness (
PHASE_COMMIT=1), one atomic commit per completed phase,--no-gpg-sign, subjectphase: <NN_name>. Child executors never rungit add/commit/mv/rm/stash. When a human asks for a commit, use thegit-commitskill (--no-gpg-sign,LLM-Generated: truetrailer). - Do not commit
.env, logs, coverage output,.agents/phase-sessions/,.agents/pipeline.log, or.agents/reports/(all gitignored).
6. Where things go
| Change | Location |
|---|---|
Configuration (env vars → typed Settings), debugpy bootstrap |
src/undercooked/config.py, .env.example, src/undercooked/debug.py |
| Pure game rules (movement, stations, orders, scoring, hazards) | src/undercooked/sim/ |
| Level/recipe content | levels/*.yaml |
| Rooms, lobby lifecycle, session records | src/undercooked/server/rooms.py, room.py |
| Wire messages + validation | src/undercooked/server/protocol.py, docs/PROTOCOL.md |
HTTP app (/, /healthz, /static), lifespan |
src/undercooked/server/app.py |
Security headers (CSP default-src 'self', no-sniff, frame-ancestors) |
src/undercooked/server/headers.py |
CLI entry point (undercooked): flags → --help → serve |
src/undercooked/__main__.py |
| Renderer, HUD, input, interpolation | app/static/js/, app/static/assets/ |
| Documentation (design / testing / deployment; per-phase docs) | docs/*.md, indexed by PLAN §13 and guarded by tests/unit/test_docs_index.py |
| The pipeline gate itself | .agents/validate.sh |
| User-visible flow contract | .agents/user_stories/US-XX_*.md |
Tests mirror that: tests/unit/ (pure, no-I/O logic incl. HTTP-route unit tests),
tests/integration/ (in-process app boot, live uvicorn + WebSocket clients), tests/sim/
(headless determinism and replays), tests/e2e/ (Playwright, named test_usNN_*.py,
marked e2e). tests/ is not a package; shared fixtures live in tests/conftest.py.
- The browser suites use the
playwrightsync API directly with fixtures written intests/e2e/conftest.py—pytest-playwrightis deliberately not a dependency, so adding it needs the usual permission. Thosebrowser/context/pagefixtures are function-scoped on purpose: a long-lived sync driver keeps an asyncio loop flagged as running in the main thread and breaks every laterasync deftest. live_server(session-scoped,tests/conftest.py) is the only fixture that binds a socket: an ephemeral127.0.0.1port, never a routable interface.