[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
+46
View File
@@ -0,0 +1,46 @@
/**
* The core of `pnpm lint:copy` (CLAUDE.md §5.6, §7): what a player could read in
* a file, and what is wrong with it. The script walks files; this decides.
*/
import { findForbidden } from './forbidden.js';
export interface CopyProblem {
readonly line: number;
readonly message: string;
}
/**
* Removes comments, keeping line numbers. Comments are where the rules are
* explained, and a rule must be nameable in the file that enforces it.
* `//` after a `:` is a URL, not a comment.
*/
export function stripComments(source: string): string {
const blank = (m: string): string => m.replace(/[^\n]/g, ' ');
return source
.replace(/<!--[\s\S]*?-->/g, blank)
.replace(/\/\*[\s\S]*?\*\//g, blank)
.replace(/(?<![:\\])\/\/[^\n]*/g, blank);
}
// *Domi* is the ecosystem's word and never stands alone (CLAUDE.md preamble).
const DOMI_ALONE = /(?<!(?:Rosea|Panda|Amicitia)[\s\u00a0])\bDomi\b/g;
/** Problems in one file's player-visible text. */
export function lintCopy(source: string): CopyProblem[] {
const text = stripComments(source);
const lineOf = (index: number): number => text.slice(0, index).split('\n').length;
const problems: CopyProblem[] = [];
for (const hit of findForbidden(text)) {
problems.push({ line: lineOf(hit.index), message: `'${hit.term}' (${hit.category}): ${hit.why}` });
}
for (const m of text.matchAll(DOMI_ALONE)) {
problems.push({
line: lineOf(m.index),
message: "'Domi' on its own: the product is always Rosea Domi, and Domi never appears alone"
});
}
return problems.sort((a, b) => a.line - b.line);
}
+81
View File
@@ -0,0 +1,81 @@
/**
* The one list of words and names that never reach a player (CLAUDE.md §5.6
* rules 3 and 4). `lint:copy` and the library validator both read it, so the two
* can never disagree.
*
* Matching is whole-word and case-insensitive, with inflections spelled out.
* A stem match (`heal*`) would also catch *health*, and a rose can be healthy.
*
* `treat` is banned outright, including the fox's food: he eats *berries*.
* `patient` is banned too. Patience is the cure Gandalf's spirit offers, so the
* product may say *patience* and *patiently* but never *patient*.
*/
export type ForbiddenCategory = 'medical' | 'unnamed-state' | 'little-prince' | 'tolkien';
export interface ForbiddenTerm {
readonly term: string;
readonly category: ForbiddenCategory;
readonly why: string;
}
const MEDICAL =
'A medical claim pulls the product toward EU medical-device rules (CLAUDE.md §5.6 rule 3). Rosea comforts; it does not treat.';
const UNNAMED =
'The game never names the state for the player (CLAUDE.md §5.6 rule 4). It lets them feel seen instead.';
const PRINCE = 'Nothing from The Little Prince by name or quote: one idea is borrowed, never its text (CLAUDE.md §5.6 rule 3).';
const TOLKIEN = "Gandalf's spirit, never a name or a quote from Tolkien's works (CLAUDE.md §5.6 rule 3).";
const terms = (category: ForbiddenCategory, why: string, list: readonly string[]): ForbiddenTerm[] =>
list.map((term) => ({ term, category, why }));
export const FORBIDDEN: readonly ForbiddenTerm[] = [
...terms('medical', MEDICAL, [
'therapy', 'therapies', 'therapist', 'therapists', 'therapeutic', 'therapeutically',
'treat', 'treats', 'treated', 'treating', 'treatment', 'treatments',
'heal', 'heals', 'healed', 'healing', 'healer', 'healers',
'cure', 'cures', 'cured', 'curing', 'curative',
'diagnose', 'diagnoses', 'diagnosed', 'diagnosing', 'diagnosis', 'diagnostic',
'symptom', 'symptoms', 'symptomatic',
'patient', 'patients',
'disorder', 'disorders'
]),
...terms('unnamed-state', UNNAMED, ['lonely', 'lonelier', 'loneliest', 'loneliness']),
...terms('little-prince', PRINCE, [
'Little Prince', 'Petit Prince', 'Malý princ', 'Saint-Exupéry', 'Saint-Exupery', 'Exupéry', 'Exupery', 'B-612', 'B612'
]),
...terms('tolkien', TOLKIEN, [
'Tolkien', 'Gandalf', 'Mithrandir', 'Frodo', 'Bilbo', 'Samwise', 'Aragorn', 'Galadriel', 'Sauron',
'Mordor', 'Rivendell', 'Middle-earth', 'Middle earth', 'hobbit', 'hobbits', 'Lothlórien', 'Lothlorien'
])
];
export interface ForbiddenHit {
readonly term: string;
readonly category: ForbiddenCategory;
readonly why: string;
/** Index into the scanned text. */
readonly index: number;
}
const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/[\s-]+/g, '[\\s\\u00a0-]+');
// Letters and digits on either side mean it is part of a longer word: *treaty*
// does not contain *treat*. Hyphens and apostrophes are boundaries, so
// *self-healing* is caught.
const PATTERNS = FORBIDDEN.map((entry) => ({
entry,
regex: new RegExp(`(?<![\\p{L}\\p{N}])${escape(entry.term)}(?![\\p{L}\\p{N}])`, 'giu')
}));
/** Every forbidden term in `text`, in order of appearance. */
export function findForbidden(text: string): ForbiddenHit[] {
const hits: ForbiddenHit[] = [];
for (const { entry, regex } of PATTERNS) {
regex.lastIndex = 0;
for (let m = regex.exec(text); m !== null; m = regex.exec(text)) {
hits.push({ ...entry, index: m.index });
}
}
return hits.sort((a, b) => a.index - b.index);
}
+2
View File
@@ -0,0 +1,2 @@
export { lintCopy, stripComments, type CopyProblem } from './copy-lint.js';
export { FORBIDDEN, findForbidden, type ForbiddenCategory, type ForbiddenHit, type ForbiddenTerm } from './forbidden.js';
+148
View File
@@ -0,0 +1,148 @@
/**
* The hope-library validator (CLAUDE.md §5.5, §5.6 rule 2, §6.1).
*
* The schema says what shape an entry has. This says whether it may be shown
* to a person: sourced, public domain or the author's own, short enough to
* read at sunset, free of forbidden words, and not promising anything.
*
* Its negative fixtures in `content/fixtures/` ARE the validator: a rule here
* without a fixture proving it fires is a review blocker.
*/
import type { HopeSentence } from '@rosea/schema';
import { validateHopeSentence } from '@rosea/schema/validate';
import { findForbidden } from './forbidden.js';
export type Rule =
| 'schema'
| 'no-source'
| 'not-public-domain'
| 'translation-under-copyright'
| 'too-long'
| 'promises-outcome'
| 'forbidden-word'
| 'no-tradition'
| 'duplicate-id';
export interface Problem {
readonly id: string;
readonly rule: Rule;
readonly message: string;
}
/** Characters per language. A sentence opened at sunset is read on a phone, once. */
export const LENGTH_CAP = 240;
/**
* The tradition tag for a line the author wrote for Rosea. Those are not public
* domain, and need not be: the author owns them (CLAUDE.md §5.6 rule 2).
*/
export const AUTHOR_TRADITION = 'rosea';
/**
* Translations known to be in the public domain. Anything else is assumed to
* be under copyright until someone checks and adds it here, with the source of
* that check in the commit.
*/
export const PUBLIC_DOMAIN_TRANSLATIONS: ReadonlySet<string> = new Set([
'KJV', // King James Version, 1611/1769
'Bible kralická', // 1579–1613
'ASV', // American Standard Version, 1901
'Douay-Rheims', // 1582–1610, Challoner revision 1752
'YLT', // Young's Literal Translation, 1862
'WEB' // World English Bible, dedicated to the public domain
]);
/**
* Phrasings that promise an outcome. A heuristic, so a hit means "a human must
* read this", and the entry fails until one does. An honest `promisesOutcome:
* true` fails the same way.
*/
const OUTCOME_PHRASES: readonly RegExp[] = [
/\beverything will be\b/i,
/\b(it|you|things) will (all )?(be|get) (better|fine|okay|ok|alright|all right|well)\b/i,
/\byou will (find|never|always|soon)\b/i,
/\bi promise\b/i,
/\bguarantee/i
];
const idOf = (input: unknown): string =>
typeof input === 'object' && input !== null && typeof (input as { id?: unknown }).id === 'string'
? (input as { id: string }).id
: '(no id)';
/** Every reason `input` may not be shown to a player. Empty means it may. */
export function validateEntry(input: unknown): Problem[] {
const id = idOf(input);
const problem = (rule: Rule, message: string): Problem => ({ id, rule, message });
const problems: Problem[] = [];
const schema = validateHopeSentence(input);
if (!schema.ok) {
for (const error of schema.errors) {
if (/^\(root\) .*'source'/.test(error)) {
problems.push(problem('no-source', 'has no source: every sentence names where it comes from'));
} else if (/^\/source .*'tradition'|^\/source\/tradition /.test(error)) {
problems.push(problem('no-tradition', 'has no tradition tag: the library stays mixed, so each line says which one it is from'));
} else {
problems.push(problem('schema', error));
}
}
return problems;
}
const entry: HopeSentence = schema.value;
const { source } = entry;
if (!source.publicDomain && source.tradition !== AUTHOR_TRADITION) {
problems.push(
problem('not-public-domain', `source '${source.work}' is not verified public domain, and the author did not write it for Rosea`)
);
}
if (source.translation !== null && !PUBLIC_DOMAIN_TRANSLATIONS.has(source.translation)) {
problems.push(
problem(
'translation-under-copyright',
`translation '${source.translation}' is not on the public-domain list; a modern translation is usually still under copyright`
)
);
}
for (const [lang, text] of Object.entries(entry.text)) {
if (text === undefined) continue;
const length = [...text].length;
if (length > LENGTH_CAP) {
problems.push(problem('too-long', `${lang} text is ${length} characters, over the length cap of ${LENGTH_CAP}`));
}
for (const hit of findForbidden(text)) {
problems.push(problem('forbidden-word', `${lang} text contains '${hit.term}' (${hit.category}): ${hit.why}`));
}
const phrase = OUTCOME_PHRASES.find((p) => p.test(text));
if (phrase !== undefined) {
problems.push(problem('promises-outcome', `${lang} text may promise an outcome (${phrase.source}): needs human review`));
}
}
if (entry.promisesOutcome) {
problems.push(problem('promises-outcome', 'is marked promisesOutcome: comfort never promises what will happen'));
}
return problems;
}
/** Validates a whole library: every entry, plus ids unique across all of them. */
export function validateLibrary(entries: readonly unknown[]): Problem[] {
const problems = entries.flatMap(validateEntry);
const seen = new Set<string>();
for (const entry of entries) {
const id = idOf(entry);
if (seen.has(id)) {
problems.push({ id, rule: 'duplicate-id', message: `id '${id}' is used more than once; a message between players would be ambiguous` });
}
seen.add(id);
}
return problems;
}