[ui] DaySentence: Her folded petal, the words and their source; the library bundled after validation

This commit is contained in:
2026-11-02 08:55:06 +01:00
parent 5934523e45
commit 03dc69702a
16 changed files with 525 additions and 19 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
"description": "The PWA. Renders what the engine returns; contains no growth, taming or sky logic.",
"scripts": {
"dev": "vite --host 127.0.0.1 --port 5173 --strictPort",
"build": "vite build",
"build": "tsx ../../scripts/validate-library.ts && vite build",
"typecheck": "svelte-check --threshold error --output human"
},
"dependencies": {
+5
View File
@@ -7,6 +7,8 @@
import { version } from '../package.json';
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
import letter from '../../../docs/LETTER.md?raw';
// The verified hope library, bundled after validate:library passed (day-sentence.md P5).
import sentences from 'virtual:rosea-library';
// The device's own zone, read here and nowhere else: the engine never asks the
// device anything (CLAUDE.md §2). Only the zone's name; never GPS, never a lookup.
@@ -92,6 +94,9 @@
await storage.appendCare(event);
keepAfterCare();
},
sentences,
loadOpened: () => storage.loadOpened(),
appendOpened: (event) => storage.appendOpened(event),
clientVersion: version,
deviceZone,
now: () => Date.now(),
+7
View File
@@ -1,3 +1,10 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
/// <reference types="vite-plugin-pwa/client" />
declare module 'virtual:rosea-library' {
import type { HopeSentence } from '@rosea/schema';
/** The verified hope library, bundled at build time after validate:library passed (day-sentence.md P5). */
const library: readonly HopeSentence[];
export default library;
}
+34
View File
@@ -1,4 +1,7 @@
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { readdirSync, readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig, type Plugin } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
// A relative path, not '@rosea/schema', on purpose. Vite bundles a config's
@@ -55,12 +58,43 @@ function contentSecurityPolicy(): Plugin {
};
}
/**
* The hope library, bundled at build time as `virtual:rosea-library`
* (day-sentence.md P5). The build script runs `validate:library` first and stops if
* it fails, so the app holds exactly what passed and never validates in the browser
* (GAP_ANALYSIS G0.12: Ajv needs `new Function`, which the CSP forbids).
* `ROSEA_LIBRARY_DIR` swaps the folder, for the e2e build only.
*/
const LIBRARY_DIR = resolve(fileURLToPath(new URL('../..', import.meta.url)), process.env['ROSEA_LIBRARY_DIR'] ?? 'content/library');
function hopeLibrary(): Plugin {
const id = 'virtual:rosea-library';
const resolved = `\0${id}`;
return {
name: 'rosea-library',
resolveId: (source) => (source === id ? resolved : undefined),
load(source) {
if (source !== resolved) return undefined;
const entries: unknown[] = [];
for (const file of readdirSync(LIBRARY_DIR).filter((f) => f.endsWith('.json')).sort()) {
const path = join(LIBRARY_DIR, file);
this.addWatchFile(path);
const data: unknown = JSON.parse(readFileSync(path, 'utf8'));
if (!Array.isArray(data)) throw new Error(`${path}: must be an array of entries`);
entries.push(...data);
}
return `export default ${JSON.stringify(entries)};`;
}
};
}
// Nothing binds to anything but 127.0.0.1 (CLAUDE.md §5.7).
export default defineConfig({
base: BASE,
plugins: [
svelte(),
contentSecurityPolicy(),
hopeLibrary(),
VitePWA({
strategies: 'generateSW',
// Never swap a running app silently. A new worker waits until the player