[repo] Workspace: Scaffold Phase 0 with schema, engine, content, ui and the PWA shell

pnpm + turbo workspace with the commands from CLAUDE.md §3. The contracts
from §6 as JSON Schemas with generated types; localDay as the one place a
day is computed; the forbidden-word list shared by lint:copy and the
library validator, with 13 negative fixtures; a Svelte 5 PWA shell built
under /Rosea/ with a meta CSP. E2E and offline suites run against the
built bundle; the offline one closes the server rather than emulating.

Analysis: .agents/features/phase0-workspace.md
This commit is contained in:
2026-11-01 00:27:33 +01:00
parent 1e4c5a06b6
commit 49c8def037
78 changed files with 9015 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
# Phase 0 — the workspace
Status: **built on `feature/phase0-workspace`**, not yet merged.
Gates closed and still open: [`GAP_ANALYSIS.md`](../GAP_ANALYSIS.md).
`docs/ROADMAP.md` does not exist yet, so this document defines Phase 0 itself. It
covers what CLAUDE.md §2 calls "confirmed when Phase 0 scaffolds it" and what §3
calls "proposed until Phase 0 scaffolds them", and nothing more. **No game code.**
`docs/GAMEPLAY.md` must be read before any, and it has not been written.
---
## 1. Why and what, in the player's terms
The player gets nothing they can see. This is deliberate. When they open the link,
they get a quiet page with the rose's name, and it still opens with the network off.
What Phase 0 buys is the ground everything else stands on. It proves four things
before anything exists that could hurt a person:
- **The app opens with no network at all.** It is served from a sub-path, as
GitHub Pages will serve it, and checked against the built bundle.
- **Nothing leaves the device.** No third-party request, no cookie, no
`localStorage`, enforced by a CSP in a `<meta>` tag.
- **No word can reach a player that the rules forbid.** `lint:copy` and
`validate:library` run, and they are proved to fire.
- **The engine cannot read a clock or a die.** A lint rule refuses it, and a
test proves the rule refuses it.
## 2. Technical architecture
```mermaid
flowchart LR
subgraph apps
app["apps/rosea<br/>@rosea/app<br/>Svelte 5 + Vite + PWA"]
end
subgraph packages
ui["packages/ui<br/>@rosea/ui<br/>copy/ + shell components"]
content["packages/content<br/>@rosea/content<br/>library validator, forbidden words"]
engine["packages/engine<br/>@rosea/engine<br/>time/localDay.ts"]
schema["packages/schema<br/>@rosea/schema<br/>JSON Schemas, generated types, constants"]
end
lib[("content/library/*.json<br/>content/fixtures/*.json")]
scripts["scripts/<br/>lint-copy, validate-library,<br/>git hooks"]
e2e["e2e/<br/>Playwright: built bundle,<br/>server killed for offline"]
app --> ui --> engine --> schema
app --> content --> schema
content --> engine
app --> schema
scripts --> content
content -. reads .-> lib
e2e -. serves .-> app
```
### Decisions
| # | Decision | Why |
|:--|:--|:--|
| D1 | Create `schema`, `engine`, `content`, `ui` and `apps/rosea` now. **Defer** `storage`, `identity`, `sync`, `services/lucerna` and `tools/art-prep` to their first feature. | An empty package has a test suite that runs nothing and exits 0. That is the `pnpm test` trap (§3) built into the layout on purpose. Each package arrives with the feature that gives it a test. |
| D2 | The build's base path is `/Rosea/` by default and `ROSEA_BASE` overrides it. The test server serves `dist/` **under that prefix**, never at `/`. | GitHub Pages serves a project at `/<repo>/` (§8, predicted). If Vite `base`, the manifest `scope`/`start_url` and the service-worker scope disagree, the installed app opens a 404. Testing at `/` would never see it. |
| D3 | Engine purity is an **ESLint rule** scoped to `packages/engine/src`, plus a test that lints a deliberately impure snippet and asserts each ban fires. | CLAUDE.md §7 says "lint rule". Ludus said the same and shipped a source-scanning test instead. Here it really is a lint rule, and the test is what keeps it honest. The ban includes `Intl.DateTimeFormat().resolvedOptions()`: it reads the device's time zone, which must be a parameter. |
| D4 | `content/library/` ships **empty**. The validator prints its counts and passes on zero entries, but it fails if any fixture passes. | Every sentence needs `verifiedBy` from the author (§6.1). An agent writing "verified" entries would be inventing a fact. The 365-sunset-sentence requirement is a release gate, not a Phase 0 gate. |
| D5 | The event schema defines only the `care` kind, with `act: water \| shade \| weed \| petals`. | §6.2 contradicted itself: the example listed `wind \| light` and the comment listed `weed \| petals`. §1 describes weeds and fallen petals, so the comment wins, and CLAUDE.md is corrected in the same branch. The other kinds (`sunset`, `fox`, `harvest`…) wait for `docs/GAMEPLAY.md`, because their fields are game design. |
| D6 | One forbidden-word list, in `packages/content/src/forbidden.ts`, used by **both** `lint:copy` and the library validator. Whole-word, case-insensitive. `treat` is banned outright. | Two lists drift. Banning `treat` means the fox's food is always *berries*, never *treats*. That is a little inconvenient and much cheaper than a medical-claim review. |
| D7 | The CSP lives in a `<meta>` tag: `default-src 'self'`, no inline script. The service worker is registered from an emitted file, not an inline snippet. | GitHub Pages cannot set headers (§8, predicted). An inline registration script would need `'unsafe-inline'` and quietly widen the policy for everything. |
| D8 | No deploy workflow yet. | There is no GitHub remote. A workflow for a host that does not exist is configuration nobody can test. |
| D9 | `localDay(epochMs, timeZone)` is the only day computation. It formats with `Intl.DateTimeFormat` for an explicit IANA zone. | §7: one module computes a day. The zone is always passed in. A city the player chooses maps to a zone, and so does the device fallback, which the app reads and the engine never does. |
## 3. Risk analysis
Here "risk" means a person feeling worse, a person's location, or a person being
reachable who did not ask to be.
| Risk | Where it could enter in Phase 0 | Defence |
|:--|:--|:--|
| A forbidden or medical word reaches a player | Shell copy, manifest description, `index.html` | `lint:copy` scans `packages/ui/src/copy/`, `apps/rosea/index.html`, the manifest fields in `vite.config.ts` and `store/`. Fixtures prove it fires. |
| *Lonely* / *loneliness* appears in the product | Same | On the forbidden list (§5.6 rule 4). Allowed only in `.agents/` and `docs/`, which `lint:copy` does not scan. |
| A byte leaves the device | Fonts, icons or a CDN pulled in by a dependency | CSP `default-src 'self'`. The e2e suite records every request and fails on any origin other than the test server's. |
| Storage outside IndexedDB | A library writing `localStorage` | The e2e suite asserts `localStorage.length === 0` and `document.cookie === ''` after load. |
| A day computed in UTC | The engine, later | D9, a purity-lint ban on `toISOString().slice`, and DST golden tests for `localDay`. |
| The empty shell feels like a broken app | The placeholder page | One calm line from `copy/`, no spinner, no "coming soon". It says what is true and asks nothing. |
Looked for and not found in Phase 0: guilt, comparison, rejection, dependence. There
is no mechanic yet that could carry any of them.
## 4. Gap analysis and the designed solution
| Gap | Solution in this branch |
|:--|:--|
| No workspace, no commands | `pnpm-workspace.yaml`, `turbo.json` and root scripts for every command in §3 that has something to run. |
| `pnpm test` can exit 0 having run nothing | `test` is not cached (`cache: false`). Every package has at least one real test. Counts are quoted in the review. |
| No proof the PWA works offline under a sub-path | `e2e/offline.spec.ts` starts a real static server at `/Rosea/`, waits for the worker to control the page, **kills the server**, reloads, and asserts the shell rendered. Ludus learned that `context.setOffline` acts before the service worker and tests the harness, not the cache. |
| No guard on commits | `scripts/pre-commit` (5 MB) and `scripts/commit-msg` (AI attribution), installed by `pnpm install`. |
| CRLF churn on Windows (`core.autocrlf=true` on this machine) | `.gitattributes` with `* text=auto eol=lf`. |
## 5. Verification matrix
| Case | Kind | Where |
|:--|:--|:--|
| Hope-sentence schema accepts a valid entry | unit | `packages/schema/test/schemas.test.ts` |
| Care event rejects an unknown `act`, a missing `localDay`, free text in `messageId` | unit | same |
| Trace rejects a timestamp finer than a day and extra properties | unit | same |
| `localDay` in Prague on both 2026 DST days, Sydney, Anchorage, UTC±14 | unit (golden) | `packages/engine/test/localDay.test.ts` |
| Monday 23:30 in Prague is Monday, not Tuesday | unit | same |
| `localDay` is the same for every ms within one local day (property) | property | same, fast-check |
| Each purity ban fires on an impure snippet; clean code passes | unit | `packages/engine/test/purity-lint.test.ts` |
| Every fixture in `content/fixtures/` fails with its named message | unit | `packages/content/test/validator.test.ts` |
| Forbidden words: whole-word, case-insensitive; no false hit on *treaty* or *cured meat*… | unit | `packages/content/test/forbidden.test.ts` |
| Shell copy passes `lint:copy` | unit + script | `packages/ui/test/copy.test.ts`, `pnpm lint:copy` |
| Built app renders its name at `/Rosea/` | e2e | `e2e/shell.spec.ts` |
| No request to any other origin; no cookie; no `localStorage` | e2e | same |
| Manifest `scope`/`start_url` and service-worker scope equal the base | e2e | same |
| CSP meta present; no inline script in the built `index.html` | e2e | same |
| No axe violations on the shell | e2e | same |
| Shell loads with the server gone | offline | `e2e/offline.spec.ts` |
| **Manual**: install from Chrome on a phone; open in airplane mode | manual | not done — needs a hosted build (D8) |