[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:
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Rosea commit-msg hook — CLAUDE.md §5.2: NO AI ATTRIBUTION IN COMMITS, EVER.
|
||||
# Imported from Ludus; NoAlgoTube needed a history rewrite to remove 18 of these.
|
||||
|
||||
msg_file="$1"
|
||||
|
||||
if grep -qiE '^(Co-Authored-By:.*(Claude|Anthropic|GPT|Copilot|Codex))|Claude-Session:|Generated with \[Claude Code\]|🤖 Generated with' "$msg_file"; then
|
||||
echo "BLOCKED: commit message contains an AI attribution trailer." >&2
|
||||
echo " Strip the trailer and commit again (CLAUDE.md §5.2)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,35 @@
|
||||
// Installs the git hooks CLAUDE.md §5.2 relies on. Runs from `pnpm install` via
|
||||
// the root `prepare` script, so a fresh clone is guarded before its first commit.
|
||||
// Adapted from Ludus, including its worktree fix: in a worktree `.git` is a FILE
|
||||
// pointing at the real gitdir, and hooks resolve per worktree.
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, statSync } from 'node:fs';
|
||||
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const gitPath = join(root, '.git');
|
||||
|
||||
if (!existsSync(gitPath)) {
|
||||
console.log('[hooks] no .git — skipping hook install.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function resolveGitDir(path) {
|
||||
if (statSync(path).isDirectory()) return path;
|
||||
const target = /^gitdir:\s*(.+)$/.exec(readFileSync(path, 'utf8').trim())?.[1]?.trim();
|
||||
if (target === undefined) {
|
||||
console.log(`[hooks] ${path} is a file but not a gitdir pointer — skipping hook install.`);
|
||||
process.exit(0);
|
||||
}
|
||||
return isAbsolute(target) ? target : resolve(root, target);
|
||||
}
|
||||
|
||||
const hooksDir = join(resolveGitDir(gitPath), 'hooks');
|
||||
mkdirSync(hooksDir, { recursive: true });
|
||||
|
||||
for (const hook of ['pre-commit', 'commit-msg']) {
|
||||
const dest = join(hooksDir, hook);
|
||||
copyFileSync(join(root, 'scripts', hook), dest);
|
||||
chmodSync(dest, 0o755);
|
||||
console.log(`[hooks] installed ${hook}`);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* `pnpm lint:copy` — every file a player could read text from, checked for
|
||||
* forbidden words and names (CLAUDE.md §5.6). The rules live in
|
||||
* @rosea/content (copy-lint.ts, forbidden.ts) and are tested there.
|
||||
*
|
||||
* Not scanned: .agents/ and docs/, where the forbidden words may appear because
|
||||
* they are being discussed (§5.6 rule 4).
|
||||
*/
|
||||
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
||||
import { extname, join, relative } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { lintCopy } from '@rosea/content';
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||
|
||||
/** Directories walked, and the extensions read in them. */
|
||||
const TARGETS: readonly { dir: string; ext: readonly string[] }[] = [
|
||||
{ dir: 'packages/ui/src', ext: ['.ts', '.svelte', '.css'] },
|
||||
{ dir: 'apps/rosea/src', ext: ['.ts', '.svelte', '.css'] },
|
||||
// Store listings, once they exist, live here and are player-facing too (§8).
|
||||
{ dir: 'store', ext: ['.md', '.txt', '.json'] }
|
||||
];
|
||||
|
||||
/** Single files: the page shell and the config that builds the web manifest. */
|
||||
const FILES: readonly string[] = ['apps/rosea/index.html', 'apps/rosea/vite.config.ts'];
|
||||
|
||||
function walk(dir: string, ext: readonly string[]): string[] {
|
||||
if (!existsSync(dir)) return [];
|
||||
return readdirSync(dir).flatMap((entry) => {
|
||||
const full = join(dir, entry);
|
||||
if (statSync(full).isDirectory()) return walk(full, ext);
|
||||
return ext.includes(extname(entry)) ? [full] : [];
|
||||
});
|
||||
}
|
||||
|
||||
const files = [
|
||||
...TARGETS.flatMap(({ dir, ext }) => walk(join(root, dir), ext)),
|
||||
...FILES.map((f) => join(root, f)).filter((f) => existsSync(f))
|
||||
];
|
||||
|
||||
if (files.length === 0) {
|
||||
console.error('lint:copy found no files to check. A check that reads nothing is not a pass.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let problems = 0;
|
||||
for (const file of files) {
|
||||
for (const p of lintCopy(readFileSync(file, 'utf8'))) {
|
||||
problems += 1;
|
||||
console.error(`${relative(root, file).replace(/\\/g, '/')}:${p.line} ${p.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`lint:copy: ${files.length} files checked, ${problems} problem${problems === 1 ? '' : 's'}`);
|
||||
process.exit(problems === 0 ? 0 : 1);
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
# Rosea pre-commit hook — CLAUDE.md §5.2.
|
||||
# .gitignore is a reminder; this is the enforcement. Rejects any staged blob over
|
||||
# 5 MB, because a raw image export cannot be removed without a history rewrite.
|
||||
|
||||
LIMIT=5242880
|
||||
report=$(mktemp)
|
||||
trap 'rm -f "$report"' EXIT
|
||||
|
||||
git diff --cached --name-only --diff-filter=ACM -z |
|
||||
while IFS= read -r -d '' path; do
|
||||
blob=$(git rev-parse ":$path" 2>/dev/null) || continue
|
||||
size=$(git cat-file -s "$blob" 2>/dev/null || echo 0)
|
||||
if [ "$size" -gt "$LIMIT" ]; then
|
||||
awk "BEGIN{printf \" %s — %.1f MB\n\", \"$path\", $size/1048576}" >> "$report"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -s "$report" ]; then
|
||||
echo "BLOCKED: staged files exceed the 5 MB limit:" >&2
|
||||
cat "$report" >&2
|
||||
echo "" >&2
|
||||
echo "Build output and raw image exports are never committed (CLAUDE.md §5.2)." >&2
|
||||
echo "Final art goes in art/final/ as optimised WebP/AVIF." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* `pnpm validate:library` — every hope sentence in content/library/, and every
|
||||
* negative fixture in content/fixtures/ (CLAUDE.md §5.5).
|
||||
*
|
||||
* Passes when the library has no problems AND every fixture fails with the rule
|
||||
* it names. A fixture that passes means a rule has stopped firing: that fails
|
||||
* the run, the same as a bad sentence.
|
||||
*/
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { validateEntry, validateLibrary, type Rule } from '@rosea/content/validate';
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||
const libraryDir = join(root, 'content', 'library');
|
||||
const fixturesDir = join(root, 'content', 'fixtures');
|
||||
|
||||
const jsonIn = (dir: string): string[] =>
|
||||
readdirSync(dir)
|
||||
.filter((f) => f.endsWith('.json'))
|
||||
.sort();
|
||||
|
||||
let failed = false;
|
||||
|
||||
// ── the library ────────────────────────────────────────────────────────────
|
||||
const entries: unknown[] = [];
|
||||
for (const file of jsonIn(libraryDir)) {
|
||||
const data: unknown = JSON.parse(readFileSync(join(libraryDir, file), 'utf8'));
|
||||
if (!Array.isArray(data)) {
|
||||
console.error(`content/library/${file}: must be an array of entries`);
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
entries.push(...data);
|
||||
}
|
||||
|
||||
for (const p of validateLibrary(entries)) {
|
||||
console.error(`library ${p.id} [${p.rule}] ${p.message}`);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
const sunset = entries.filter(
|
||||
(e) => typeof e === 'object' && e !== null && Array.isArray((e as { use?: unknown }).use) && (e as { use: unknown[] }).use.includes('sunset')
|
||||
).length;
|
||||
|
||||
console.log(
|
||||
`library: ${entries.length} entr${entries.length === 1 ? 'y' : 'ies'} in ${jsonIn(libraryDir).length} files, ${sunset} sunset (release needs 365)`
|
||||
);
|
||||
|
||||
// ── the fixtures: each must FAIL, with its named rule ───────────────────────
|
||||
interface Fixture {
|
||||
expect: Rule;
|
||||
entry?: unknown;
|
||||
entries?: unknown[];
|
||||
}
|
||||
|
||||
const fixtureFiles = jsonIn(fixturesDir);
|
||||
let fixtureOk = 0;
|
||||
for (const file of fixtureFiles) {
|
||||
const fixture = JSON.parse(readFileSync(join(fixturesDir, file), 'utf8')) as Fixture;
|
||||
const problems = fixture.entries !== undefined ? validateLibrary(fixture.entries) : validateEntry(fixture.entry);
|
||||
if (problems.some((p) => p.rule === fixture.expect)) {
|
||||
fixtureOk += 1;
|
||||
} else {
|
||||
console.error(
|
||||
`fixture ${file} expected [${fixture.expect}], got ${problems.length === 0 ? 'a PASS' : problems.map((p) => `[${p.rule}]`).join(' ')}`
|
||||
);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`fixtures: ${fixtureOk} of ${fixtureFiles.length} rejected as expected`);
|
||||
|
||||
if (fixtureFiles.length === 0) {
|
||||
console.error('fixtures: none found. The negative fixtures ARE the validator (CLAUDE.md §5.5).');
|
||||
failed = true;
|
||||
}
|
||||
|
||||
process.exit(failed ? 1 : 0);
|
||||
Reference in New Issue
Block a user