Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(setup-data): merge missing keys into known structured JSON seeds on upgrade
Adam Eivy69132ca320e0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3482a63c63..f7bb5b1ba4 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -24,6 +24,7 @@## Fixed+- **`scripts/setup-data.js` now merges missing keys into known structured JSON seeds.** File-level copy-if-missing didn't help when the destination JSON already existed but was missing newly-added entries — so adding a new prompt stage to `data.sample/prompts/stage-config.json` never reached existing installs (their `data/prompts/stage-config.json` already existed, got skipped, agent task threw "Stage X not found" at runtime). The setup script now also walks two known structured JSONs (`prompts/stage-config.json` under `stages`, `prompts/variables.json` under `variables`) and merges any missing top-level entries from `data.sample/` into the user's copy without overwriting customizations. Caveat: if a user deliberately deleted a starter entry it'll come back on the next run — accepted trade-off vs. silent drift on upgrade. Future structured seeds opt in by adding an entry to `JSON_MERGE_TARGETS`.- **Creative Director smoke-test fixture is ~2× faster.** Drops scene `durationSeconds` from 3s → 2s and switches `aspectRatio` from `1:1` (512×512) to a new hidden `1:1-small` preset (384×384, ~44% fewer pixels) — total compute budget goes from `3 × 3s × 512²` to `3 × 2s × 384²`, roughly a 63% pixel-frame reduction. The smaller preset is registered in `ASPECT_PRESETS` only (not `ASPECT_RATIOS`), so the user-facing dropdown and route validation surface stay unchanged; the smoke route bypasses validation by constructing the project internally. `targetDurationSeconds` updated to 6 to match (3 × 2s). Lets the post-pipeline-change health check finish in render time only without waiting on full-resolution clips.- **Creative Director agent prompts moved into the Prompts Manager.** `buildTreatmentPrompt` and `buildEvaluatePrompt` (in `server/lib/creativeDirectorPrompts.js`) now compute a flat view object and delegate to `buildPrompt('cd-treatment', view)` / `buildPrompt('cd-evaluate', view)`. The actual prompt text lives in `data/prompts/stages/cd-treatment.md` and `cd-evaluate.md` — editable from the Prompts Manager UI without code changes. The view object precomputes everything the template engine can't (aspect dims, render params, multi-frame list with timeline-position labels, scene strategy line, retry budget delta), so authors can rearrange wording and sections freely. `agentBridge.js` updated to await the now-async builders. The two new stages ship as starters under `data.sample/prompts/stages/cd-{treatment,evaluate}.md` plus `cd-*` entries in `data.sample/prompts/stage-config.json` — `npm run setup` / `npm run setup:data` copies them into `data/prompts/` on fresh installs (and fills in any missing files on existing installs without overwriting user customizations).- **Prompt template engine upgraded to support dot notation.** `server/lib/promptTemplate.js` ships an enhanced Mustache-flavored renderer that handles `{{a.b.c}}` lookups, object section scopes (`{{#user}}{{first}}{{/user}}`), array iteration with parent-scope fall-through (so `{{project.id}}` still resolves inside `{{#frames}}`), `{{.}}` for primitive iteration items, inverted sections (`{{^x}}`), and triple-mustache (`{{{x}}}`). Routed through `server/services/promptService.js#buildPrompt` so every PortOS template (including legacy ones like `cos-evaluate.md` that were silently leaving `{{metadata.context}}` literals in the output because the upstream toolkit's `\w+`-only regex doesn't match dots) now renders correctly. Storage stays in the toolkit (`stage-config.json`, `variables.json`, `.md` files); only the templating step is local. 17 engine tests + 12 CD prompt-rendering tests cover the surface.diff --git a/scripts/setup-data.js b/scripts/setup-data.jsindex 025a86ee22..745a077eba 100644--- a/scripts/setup-data.js+++ b/scripts/setup-data.js@@ -53,6 +53,55 @@ if (!existsSync(dataDir)) {console.log('✅ Data directory already exists, ensured subdirectories and files');}+// Merge new top-level entries from data.sample's structured JSON files into+// the user's existing copies, leaving customized entries untouched. Without+// this, only file-level "missing → copy" propagation runs above, so a new+// prompt stage or shared variable added to data.sample/prompts/ never+// reaches an existing install whose stage-config.json or variables.json+// already exists. Each merge target points at one top-level dict-shaped key+// (`stages` for stage-config.json, `variables` for variables.json) and the+// merger adds entries the user is missing without overwriting anything they+// have. Caveat: if a user deliberately deleted a starter entry it WILL come+// back on the next run — that's the documented trade-off vs. silent drift.+const JSON_MERGE_TARGETS = [+ { relPath: 'prompts/stage-config.json', mergeKey: 'stages' },+ { relPath: 'prompts/variables.json', mergeKey: 'variables' },+];++const mergeJsonStarter = (relPath, mergeKey) => {+ const samplePath = join(sampleDir, relPath);+ const dataPath = join(dataDir, relPath);+ if (!existsSync(samplePath) || !existsSync(dataPath)) return;+ let sample, data;+ try {+ sample = JSON.parse(readFileSync(samplePath, 'utf8'));+ data = JSON.parse(readFileSync(dataPath, 'utf8'));+ } catch (err) {+ console.log(`⚠️ Skipping JSON merge for ${relPath}: ${err.message}`);+ return;+ }+ const sampleEntries = sample?.[mergeKey];+ if (!sampleEntries || typeof sampleEntries !== 'object' || Array.isArray(sampleEntries)) return;+ if (!data[mergeKey] || typeof data[mergeKey] !== 'object' || Array.isArray(data[mergeKey])) {+ data[mergeKey] = {};+ }+ const added = [];+ for (const [key, value] of Object.entries(sampleEntries)) {+ if (!(key in data[mergeKey])) {+ data[mergeKey][key] = value;+ added.push(key);+ }+ }+ if (added.length > 0) {+ writeFileSync(dataPath, JSON.stringify(data, null, 2) + '\n');+ console.log(`📝 ${relPath}: merged ${added.length} new ${mergeKey} ${added.length === 1 ? 'entry' : 'entries'} (${added.join(', ')})`);+ }+};++for (const { relPath, mergeKey } of JSON_MERGE_TARGETS) {+ mergeJsonStarter(relPath, mergeKey);+}+// Ensure migrations directory exists (not in data.sample, needed for both fresh and existing installs)const migrationsDir = join(dataDir, 'migrations');if (!existsSync(migrationsDir)) {