fix: write shared files before codegen so typecheck resolves imports
Root cause: the typecheck-retry loop couldn't resolve ../../db.js
because shared files were written by scaffold AFTER code generation.
The LLM would "fix" the import error by creating its own Database.
Now: shared files + package.json + npm install happen BEFORE codegen.
Also added mandatory import block at top of user prompt and multi-
resource code example with JOINs, filtering, cascade protection.
Imports now correct (db from ../../db.js). Score 32% on hard spec —
remaining failures are logic issues (JOINs, stats, filtering), not
import issues. Ready for autoresearch prompt optimization.