[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
+25
View File
@@ -0,0 +1,25 @@
{
"name": "@rosea/content",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "The hope library and planets' scripts as data, the library validator, and the one list of forbidden words.",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./validate": "./src/validator.ts"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json",
"test": "vitest run --reporter=verbose"
},
"dependencies": {
"@rosea/schema": "workspace:*"
},
"devDependencies": {
"typescript": "5.9.3",
"vitest": "3.2.7"
}
}
+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;
}
+41
View File
@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest';
import { lintCopy, stripComments } from '../src/copy-lint.js';
describe('lint:copy core', () => {
it('reports a forbidden word in a string, with its line', () => {
const problems = lintCopy("export const a = 'ok';\nexport const b = 'A gentle therapy';\n");
expect(problems).toHaveLength(1);
expect(problems[0]?.line).toBe(2);
expect(problems[0]?.message).toContain('therapy');
});
it('reports a forbidden word in Svelte markup', () => {
expect(lintCopy('<p>For the lonely.</p>')).toHaveLength(1);
});
it('ignores comments, where rules are explained', () => {
expect(lintCopy('// never say therapy\n/* nor lonely */\n<!-- nor Gandalf -->\nconst ok = 1;')).toEqual([]);
});
it('keeps line numbers when it strips a multi-line comment', () => {
const problems = lintCopy("/*\n\n*/\nconst s = 'cure';");
expect(problems[0]?.line).toBe(4);
});
it('does not mistake a URL for a comment', () => {
expect(stripComments("'https://example.invalid/cure'")).toContain('cure');
});
it("reports 'Domi' standing alone", () => {
expect(lintCopy("const title = 'Domi';")).toHaveLength(1);
expect(lintCopy("const title = 'Welcome to Domi';")).toHaveLength(1);
});
it("accepts 'Domi' after its first word", () => {
expect(lintCopy("'Rosea Domi', 'Panda Domi', 'Amicitia Domi'")).toEqual([]);
});
it('accepts clean shell copy', () => {
expect(lintCopy("preparing: 'The garden is being prepared.'")).toEqual([]);
});
});
+44
View File
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { FORBIDDEN, findForbidden } from '../src/forbidden.js';
const terms = (text: string): string[] => findForbidden(text).map((h) => h.term);
describe('forbidden words — what is caught', () => {
it('catches every listed term on its own', () => {
const missed = FORBIDDEN.filter(({ term }) => !terms(`before ${term} after`).includes(term)).map((t) => t.term);
expect(missed).toEqual([]);
});
it.each([
['A soft THERAPY for the soul', 'therapy'],
['self-healing petals', 'healing'],
["the rose's lonely planet", 'lonely'],
['Loneliness.', 'loneliness'],
['a treat for the fox', 'treat'],
['be patient with yourself', 'patient'],
['Middle-earth', 'Middle-earth'],
['Middle earth', 'Middle-earth'],
['Malý princ', 'Malý princ'],
['Saint-Exupéry wrote', 'Saint-Exupéry']
])('"%s" contains %s', (text, term) => {
expect(terms(text)).toContain(term);
});
it('reports hits in reading order', () => {
expect(terms('cure first, then therapy')).toEqual(['cure', 'therapy']);
});
});
describe('forbidden words — what is NOT caught', () => {
it.each([
'a treaty between two roses',
'a healthy rose',
'patience, and patiently waiting',
'the lamplighter on his planet',
'the king, the vain man, the businessman',
'a fox among the berries',
'Rosea Domi'
])('"%s" is clean', (text) => {
expect(terms(text)).toEqual([]);
});
});
+85
View File
@@ -0,0 +1,85 @@
import { readFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import { LENGTH_CAP, validateEntry, validateLibrary, type Rule } from '../src/validator.js';
const fixturesDir = fileURLToPath(new URL('../../../content/fixtures', import.meta.url));
interface Fixture {
readonly expect: Rule;
readonly why: string;
readonly entry?: unknown;
readonly entries?: readonly unknown[];
}
const fixtures = readdirSync(fixturesDir)
.filter((f) => f.endsWith('.json'))
.sort()
.map((file) => ({ file, fixture: JSON.parse(readFileSync(join(fixturesDir, file), 'utf8')) as Fixture }));
const valid = {
id: 'valid-entry',
text: { en: 'Fixture text, not a real sentence.', cs: 'Testovací text.' },
source: {
work: 'Fixture',
author: null,
tradition: 'biblical',
translation: 'KJV',
publicDomain: true,
verifiedBy: 'Fixture',
verifiedAt: '2026-11-01'
},
use: ['sunset', 'comfort'],
tone: 'gentle',
promisesOutcome: false
};
describe('library validator — negative fixtures', () => {
it('finds the fixtures', () => {
// A glob matching nothing would pass every case below.
expect(fixtures.length).toBeGreaterThanOrEqual(13);
});
it.each(fixtures)('$file fails with its named rule', ({ fixture }) => {
const problems = fixture.entries !== undefined ? validateLibrary(fixture.entries) : validateEntry(fixture.entry);
expect(problems.map((p) => p.rule), fixture.why).toContain(fixture.expect);
for (const p of problems) expect(p.message.length, 'each problem says what is wrong').toBeGreaterThan(10);
});
it('every rule the validator has is proved by at least one fixture', () => {
const proved = new Set(fixtures.map(({ fixture }) => fixture.expect));
const RULES: readonly Rule[] = [
'schema',
'no-source',
'not-public-domain',
'translation-under-copyright',
'too-long',
'promises-outcome',
'forbidden-word',
'no-tradition',
'duplicate-id'
];
expect(RULES.filter((r) => !proved.has(r))).toEqual([]);
});
});
describe('library validator — what passes', () => {
it('accepts a sourced, public-domain, short, gentle entry', () => {
expect(validateEntry(valid)).toEqual([]);
});
it('accepts a line the author wrote for Rosea, though it is not public domain', () => {
const own = { ...valid, source: { ...valid.source, tradition: 'rosea', translation: null, publicDomain: false } };
expect(validateEntry(own)).toEqual([]);
});
it('accepts text exactly at the length cap, counting characters and not UTF-16 units', () => {
const atCap = { ...valid, text: { en: 'ř'.repeat(LENGTH_CAP) } };
expect(validateEntry(atCap)).toEqual([]);
});
it('accepts an empty library, and says nothing about it', () => {
expect(validateLibrary([])).toEqual([]);
});
});
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["src/**/*.ts", "test/**/*.ts"]
}