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
refactor([setup-data-import-drift-tables-from-migrations]): sweep prompt drift tables from migration exports
[._.]/ Adam Eivyb48e78233f09
diff --git a/scripts/migrations/007-places-int-ext-time-of-day.js b/scripts/migrations/007-places-int-ext-time-of-day.jsindex d9e143a341..27d670ae0d 100644--- a/scripts/migrations/007-places-int-ext-time-of-day.js+++ b/scripts/migrations/007-places-int-ext-time-of-day.js@@ -18,11 +18,14 @@ const md5 = (str) => {return createHash('md5').update(normalized).digest('hex');};-const OLD_SHIPPED_MD5 = {+// Exported under the standard drift-constant names so setup-data.js's+// `buildPromptDriftTables` sweep picks up this file's hashes from a single+// source of truth instead of re-mirroring them by hand.+export const ACCEPTED_OLD_MD5 = {'writers-room-places.md': '7f1f80eb63d67a21161994cde115045e',};-const NEW_SHIPPED_MD5 = {+export const NEW_SHIPPED_MD5 = {'writers-room-places.md': '24a33628cc94d80fa5ca60831d973daf',};@@ -35,7 +38,7 @@ export default {let alreadyCurrent = 0;let skipped = 0;- for (const filename of Object.keys(OLD_SHIPPED_MD5)) {+ for (const filename of Object.keys(ACCEPTED_OLD_MD5)) {const dataPath = join(stagesDir, filename);const samplePath = join(sampleDir, filename);@@ -56,7 +59,7 @@ export default {continue;}- if (existingMd5 !== OLD_SHIPPED_MD5[filename]) {+ if (existingMd5 !== ACCEPTED_OLD_MD5[filename]) {console.warn(`⚠️ places extraction prompt ${filename} has been customized — skipping auto-update.\n` +` To pick up the new intExt / timeOfDay fields, diff:\n` +diff --git a/scripts/migrations/022-rename-bible-setting-to-place.js b/scripts/migrations/022-rename-bible-setting-to-place.jsindex c0505c5ba6..089f3cf81b 100644--- a/scripts/migrations/022-rename-bible-setting-to-place.js+++ b/scripts/migrations/022-rename-bible-setting-to-place.js@@ -82,10 +82,22 @@ const readDirOrEmpty = async (path) => readdir(path, { withFileTypes: true }).ca// Pre-rename shipped hashes. Auto-update only matches; customized templates// are left for the user to merge manually (setup-data.js will flag the drift).-const OLD_PROMPTS_PLACES_MD5 = '24a33628cc94d80fa5ca60831d973daf';-const NEW_PROMPTS_PLACES_MD5 = 'a7f68e51dd6b4421d20f5bd9d855d9b4';-const OLD_PROMPTS_DEFERENCE_MD5 = '218f0e85643609ed85a12b1ccc7b5a8d';-const NEW_PROMPTS_DEFERENCE_MD5 = 'a4681348c27776e414acf6e0be566a99';+//+// Exported under the standard drift-constant names so setup-data.js's+// `buildPromptDriftTables` sweep reads these from a single source of truth.+// `DRIFT_SUBDIRS` tells the sweep that `bible-deference.md` lives under+// `prompts/_partials/` rather than the default `prompts/stages/`.+export const ACCEPTED_OLD_MD5 = {+ 'writers-room-places.md': '24a33628cc94d80fa5ca60831d973daf',+ 'bible-deference.md': '218f0e85643609ed85a12b1ccc7b5a8d',+};+export const NEW_SHIPPED_MD5 = {+ 'writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4',+ 'bible-deference.md': 'a4681348c27776e414acf6e0be566a99',+};+export const DRIFT_SUBDIRS = {+ 'bible-deference.md': '_partials',+};// Each template has a sample twin at the same relative path under// `data.reference/…`. When an installed copy still hashes to the pre-rename@@ -114,20 +126,18 @@ const RENAME_SUBSTITUTIONS = [[/the setting's baseline description/g, "the place's baseline description"],];-const PROMPT_TEMPLATES = [- {- rel: 'data/prompts/stages/writers-room-places.md',- sampleRel: 'data.reference/prompts/stages/writers-room-places.md',- oldHash: OLD_PROMPTS_PLACES_MD5,- newHash: NEW_PROMPTS_PLACES_MD5,- },- {- rel: 'data/prompts/_partials/bible-deference.md',- sampleRel: 'data.reference/prompts/_partials/bible-deference.md',- oldHash: OLD_PROMPTS_DEFERENCE_MD5,- newHash: NEW_PROMPTS_DEFERENCE_MD5,- },-];+// Derived from the exported drift constants so this migration's own+// auto-update pass and the setup-data.js drift sweep can never disagree on a+// hash. Each template resolves its subdir via DRIFT_SUBDIRS (default stages).+const PROMPT_TEMPLATES = Object.keys(ACCEPTED_OLD_MD5).map((filename) => {+ const subdir = DRIFT_SUBDIRS[filename] || 'stages';+ return {+ rel: `data/prompts/${subdir}/${filename}`,+ sampleRel: `data.reference/prompts/${subdir}/${filename}`,+ oldHash: ACCEPTED_OLD_MD5[filename],+ newHash: NEW_SHIPPED_MD5[filename],+ };+});const migrateUniverseState = async (rootDir) => {const path = join(rootDir, 'data/universe-builder.json');diff --git a/scripts/migrations/_lib.js b/scripts/migrations/_lib.jsindex 7587cb3330..9462d6dc99 100644--- a/scripts/migrations/_lib.js+++ b/scripts/migrations/_lib.js@@ -13,8 +13,9 @@* files so this module is never imported as a migration.*/-import { readFile, writeFile, unlink } from 'fs/promises';+import { readFile, writeFile, unlink, readdir } from 'fs/promises';import { join } from 'path';+import { pathToFileURL } from 'url';import { createHash } from 'crypto';/**@@ -226,3 +227,77 @@ export async function readLayoutsDoc({ rootDir, label }) {export async function writeLayoutsDoc(path, doc) {await writeFile(path, JSON.stringify(doc, null, 2));}++/**+ * Build the per-subdir prompt-drift tables that `scripts/setup-data.js` uses+ * for its "pending migration" warning by sweeping every numbered migration's+ * exported drift constants — instead of hand-mirroring them in setup-data.js+ * (the spot most likely to drift out of sync with the migrations).+ *+ * Each prompt-touching migration exports:+ * - `ACCEPTED_OLD_MD5` — `{ 'file.md': hash | [hash, …] }` (the shipped+ * hashes a still-unmodified installed copy may carry before this migration)+ * - `NEW_SHIPPED_MD5` — `{ 'file.md': hash }` (the hash this migration ships)+ * - `DRIFT_SUBDIRS` — (optional) `{ 'file.md': '_partials' }` for prompt+ * fragments under `data/prompts/_partials/` rather than the default+ * `data/prompts/stages/`.+ *+ * Merge rules across a file's migration lineage. Migrations sort numerically by+ * filename, so the highest-numbered one that ships a file defines its current+ * shape:+ * - current/new hash = the LAST `NEW_SHIPPED_MD5` entry for the file.+ * - accepted-old set = union of every `ACCEPTED_OLD_MD5` entry PLUS every+ * intermediate `NEW_SHIPPED_MD5` (each earlier shipped hash is itself+ * auto-updatable to the latest), minus the current hash.+ *+ * Only migration files whose source text mentions the export names are+ * imported — this skips the heavier split/seed migrations (which pull in+ * server-side modules) and keeps the sweep a cheap, side-effect-free read.+ * `_`-prefixed files (this module) are excluded by the numeric-prefix filter.+ *+ * Returns `{ [subdir]: { oldMap, newMap, files } }` keyed by `'stages'` /+ * `'_partials'`, matching the shape `collectDrift` in setup-data.js consumes.+ */+export async function buildPromptDriftTables(migrationsDir) {+ const candidates = (await readdir(migrationsDir))+ .filter((f) => /^\d.*\.js$/.test(f) && !f.endsWith('.test.js'))+ .sort();++ // key = `${subdir}/${filename}` so stages + _partials never collide.+ const merged = new Map();+ for (const file of candidates) {+ const filePath = join(migrationsDir, file);+ const source = await readFile(filePath, 'utf-8');+ if (!source.includes('ACCEPTED_OLD_MD5') && !source.includes('NEW_SHIPPED_MD5')) continue;+ const mod = await import(pathToFileURL(filePath).href);+ const oldMap = mod.ACCEPTED_OLD_MD5 || {};+ const newMap = mod.NEW_SHIPPED_MD5 || {};+ const subdirs = mod.DRIFT_SUBDIRS || {};+ const names = new Set([...Object.keys(oldMap), ...Object.keys(newMap)]);+ for (const name of names) {+ const subdir = subdirs[name] || 'stages';+ const key = `${subdir}/${name}`;+ const entry = merged.get(key) || { subdir, name, old: new Set(), newSeq: [] };+ const ov = oldMap[name];+ if (ov != null) (Array.isArray(ov) ? ov : [ov]).forEach((h) => entry.old.add(h));+ if (newMap[name]) entry.newSeq.push(newMap[name]);+ merged.set(key, entry);+ }+ }++ const tables = {};+ for (const { subdir, name, old, newSeq } of merged.values()) {+ // A file with only accepted-old hashes and no shipped current has nothing+ // to update *to* — skip it rather than emit a half table.+ if (newSeq.length === 0) continue;+ const current = newSeq[newSeq.length - 1];+ const olds = new Set(old);+ for (const intermediate of newSeq.slice(0, -1)) olds.add(intermediate);+ olds.delete(current);+ const table = (tables[subdir] ||= { oldMap: {}, newMap: {}, files: [] });+ table.oldMap[name] = [...olds];+ table.newMap[name] = current;+ table.files.push(name);+ }+ return tables;+}diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.jsnew file mode 100644index 0000000000..37d00bb1e1--- /dev/null+++ b/scripts/setup-data-drift.test.js@@ -0,0 +1,89 @@+/**+ * Contract test for the prompt-drift sweep that scripts/setup-data.js uses to+ * warn about pending migrations. Before this, setup-data.js hand-mirrored every+ * migration's ACCEPTED_OLD_MD5 / NEW_SHIPPED_MD5 hashes — the spot most likely+ * to drift out of sync. `buildPromptDriftTables` now sweeps those constants+ * straight from the migration files, so this test pins the swept result against+ * the known-good baseline: if a migration ships a new prompt hash without+ * exporting it (or exports a wrong one), the baseline assertion fails loudly.+ */+import { describe, it, expect } from 'vitest';+import { dirname, join } from 'path';+import { fileURLToPath } from 'url';++import { buildPromptDriftTables } from './migrations/_lib.js';++const migrationsDir = join(dirname(fileURLToPath(import.meta.url)), 'migrations');++// The current shipped baseline for every migration-managed prompt. This is the+// single source of truth the sweep must reproduce — keep it in lockstep with+// the latest NEW_SHIPPED_MD5 a migration exports for each file.+const EXPECTED_STAGE_NEW = {+ 'pipeline-idea-expansion.md': '49a208628290543ba2607a5ed48fdc8c',+ 'pipeline-prose.md': '84523d531eeafa60959c65c553b2563f',+ 'pipeline-comic-script.md': 'dea7d497d1cb38e7574f236f4ff8e644',+ 'pipeline-teleplay.md': 'afa4215330bf856429d70d7e2f856605',+ 'pipeline-season-episodes.md': '50c68a29c3ebc275db3095d06bd87100',+ 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0',+ 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c',+ 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',+ 'pipeline-arc-resolve.md': '5b340885c6e8f8afc63424d6b5bc7eb7',+ 'pipeline-extract-scenes.md': 'c51fb208568d0d903eb43b437478b0ba',+ 'writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4',+ 'cos-agent-briefing.md': 'dccb392a43cbd3dac900fee12c31619a',+ 'universe-character-expand.md': '67b6e73ed47f318451a730088b4cff14',+ 'story-builder-idea-expand.md': 'c12d76fefaaded2838023065bfc94bb0',+ 'pipeline-editorial-analysis.md': 'daeb02bd54b0c099b21af659c6298cfe',+ 'pipeline-manuscript-completeness.md': '1ee5ac936fbf1d365e0eaea99bcf1e77',+ 'pipeline-manuscript-fix.md': 'c88a56304eb5e290ae0de9dadd20b310',+};++describe('buildPromptDriftTables', () => {+ it('sweeps the current shipped hash for every migration-managed stage prompt', async () => {+ const { stages } = await buildPromptDriftTables(migrationsDir);+ for (const [file, hash] of Object.entries(EXPECTED_STAGE_NEW)) {+ expect(stages.newMap[file], `${file} current hash`).toBe(hash);+ }+ });++ it('keys partial fragments under the _partials subdir, not stages', async () => {+ const tables = await buildPromptDriftTables(migrationsDir);+ // bible-deference.md is a _partials fragment (migration 022 declares it via+ // DRIFT_SUBDIRS) — it must land in the partial table, never the stage table.+ expect(tables._partials.newMap['bible-deference.md']).toBe('a4681348c27776e414acf6e0be566a99');+ expect(tables._partials.oldMap['bible-deference.md']).toEqual(['218f0e85643609ed85a12b1ccc7b5a8d']);+ expect(tables.stages.newMap['bible-deference.md']).toBeUndefined();+ });++ it('unions the accepted-old hashes across a multi-migration lineage', async () => {+ const { stages } = await buildPromptDriftTables(migrationsDir);+ // pipeline-idea-expansion.md evolved through 003 → 004 → 025 → 054(+fence).+ // Every intermediate shipped hash must be auto-updatable to the latest.+ expect(stages.oldMap['pipeline-idea-expansion.md'].sort()).toEqual([+ '1ee44cf95851ff8debf18729ebcd40b4',+ '1f3c5d077a5ef9a4b610335d5e3edd9c',+ '41facefbc0c0549d456bef9111f95ab9',+ 'aee25112b2c596f643b17c559b772c22',+ 'b5c47c94ffc74637983c95761ab0c66c',+ ]);+ });++ it('covers a prompt whose lineage spans two custom-export migrations', async () => {+ const { stages } = await buildPromptDriftTables(migrationsDir);+ // writers-room-places.md's hashes come from migrations 007 + 022 — both of+ // which export the standard constants only because this feature required it.+ expect(stages.oldMap['writers-room-places.md'].sort()).toEqual([+ '24a33628cc94d80fa5ca60831d973daf',+ '7f1f80eb63d67a21161994cde115045e',+ ]);+ });++ it('never lists the current hash among its own accepted-old set', async () => {+ const tables = await buildPromptDriftTables(migrationsDir);+ for (const table of [tables.stages, tables._partials]) {+ for (const file of table.files) {+ expect(table.oldMap[file]).not.toContain(table.newMap[file]);+ }+ }+ });+});diff --git a/scripts/setup-data.js b/scripts/setup-data.jsindex ff5abe474c..97a8a98229 100644--- a/scripts/setup-data.js+++ b/scripts/setup-data.js@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, cpSync, readdirSync, statSync, readFileSync, wriimport { dirname, join } from 'path';import { fileURLToPath } from 'url';-import { md5 } from './migrations/_lib.js';+import { md5, buildPromptDriftTables } from './migrations/_lib.js';const __dirname = dirname(fileURLToPath(import.meta.url));const rootDir = join(__dirname, '..');@@ -123,122 +123,25 @@ for (const { relPath, mergeKey } of JSON_MERGE_TARGETS) {mergeJsonStarter(relPath, mergeKey);}-// Drift detection — warn when a data.reference/prompts/stages/*.md differs from-// the installed data/prompts/stages/*.md copy. Only fires on existing installs-// (fresh installs already got a full copy above). Prompt templates drift when-// a PortOS update adds new template variables (e.g. {{lengthTargets.*}}) that-// existing installs won't pick up because setup-data.js only copies *missing*-// files.+// Drift detection — warn when a data.reference/prompts/{stages,_partials}/*.md+// differs from the installed copy. Only fires on existing installs (fresh+// installs already got a full copy above). Prompt templates drift when a PortOS+// update adds new template variables (e.g. {{lengthTargets.*}}) that existing+// installs won't pick up because setup-data.js only copies *missing* files.//-// NOTE: only the files managed by scripts/migrations/003+ are checked here —-// scanning all stage prompts would produce misleading warnings for prompts-// that have no migration counterpart (e.g. cd-evaluate.md, writers-room prompts).-//-// Mirror scripts/migrations/003+ NEW/OLD hashes. Array values let the check-// recognize multi-migration lineages (file evolved through 003 → 004 → 005);-// a user at any intermediate hash still gets the "run migrations" prompt.-const SHIPPED_PROMPT_OLD_MD5 = {- // idea-expansion: aee… (pre-003), 41fa… (post-003, pre-004), and- // 1ee44c… (post-004, pre-025) all auto-updatable to the post-025- // (role/physicalDescription/personality/background plumbing) hash.- // post-054 ({{#sourceMaterials}} source-agnostic block) appends the prior- // post-025/post-027 hashes to each chain. post-054-fence adds tilde fences +- // injection-guard sentence to the sourceMaterials blocks (review fix).- 'pipeline-idea-expansion.md': ['aee25112b2c596f643b17c559b772c22', '41facefbc0c0549d456bef9111f95ab9', '1ee44cf95851ff8debf18729ebcd40b4', '1f3c5d077a5ef9a4b610335d5e3edd9c', 'b5c47c94ffc74637983c95761ab0c66c'],- // prose: bfea5a… (pre-003) and 30ac30… (post-003, pre-027) both auto-- // updatable to the post-054-fence (source-agnostic + tilde-fence) hash.- 'pipeline-prose.md': ['bfea5aeeb471aae9749baee765b473a7', '30ac30ec2b9d3e2a9eb869c181732cc6', 'd1f8e3f1d214725b5aa67f309a81cd7d', 'bef1bc2767b78f585f2bd89f3d615130'],- // comic-script: 40e5fd… (pre-003), beab03… (post-003, pre-011), and 1e0af3…- // (post-011, pre-027) all auto-updatable to the post-054-fence hash.- 'pipeline-comic-script.md': ['40e5fdc1a1e68a7419b7dad936366c1a', 'beab031951859ca13579cdb9c4dbe769', '1e0af305c27d0c80c4b482d2ebcb4a0d', '133d200d069c2e8173b7c129eea58f53', 'e530fc76b89cedaef848ad7ec99c934c'],- // teleplay: 3f6fec… (pre-027) auto-updatable to the post-054-fence hash.- 'pipeline-teleplay.md': ['3f6fecc25573ed054b47db392250034a', '376f779f4687b598f1c92ca4e770fd5a', '1280ef6b1ad68fa44070ca7478ec2a5f', '2568e14beaa574d43f8018a5def51d04'],- // season-episodes: 6e349a… (pre-003) and c4928e… (post-003, pre-005) both- // auto-updatable to the post-005 (shape-aware) hash.- 'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb', 'c4928e2a5f833358116b29d2d669888d'],- // arc-overview: 6a3eca… (pre-005) and d34d72… (post-005, pre-019) both- // auto-updatable to the post-019 (worldCanonText) hash.- 'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c'],- // arc-verify: 52e31a… (pre-005) and ff56d8… (post-005, pre-019) both- // auto-updatable to the post-019 (worldCanonText) hash.- 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6'],- // volume-verify: c6ea28… (pre-005) and 03f3c8… (post-005, pre-019) both- // auto-updatable to the post-019 (worldCanonText) hash.- 'pipeline-volume-verify.md': ['c6ea28e972ad6e229bafb2d602b4dda3', '03f3c874cb80e1c98abcf03168fa7a92'],- // arc-resolve: 87bc5c… (pre-005), a8677b… (post-005, pre-019), and- // 8e348f… (post-019, pre-023) all auto-updatable to the post-023- // (per-episode-synopsis anchor) hash.- 'pipeline-arc-resolve.md': ['87bc5c01f1a8a97b681727a38b05edc6', 'a8677bbe1eb38f871fb152a5b0fec7c6', '8e348f3d1894382889f9f0ee7d5c6792'],- // Shot decomposition additions (migration 006).- 'pipeline-extract-scenes.md': '59fa5ee305ce53d91eb15224d8b546d3',- // setting→place rename, migration 022. Two known auto-updatable hashes:- // pre-019 (`7f1f80…`, INT/EXT addition) and pre-022 (`24a336…`, the- // hash that was the NEW shipped before this rename). Both can be- // auto-bumped to the post-rename shape.- 'writers-room-places.md': ['7f1f80eb63d67a21161994cde115045e', '24a33628cc94d80fa5ca60831d973daf'],- // universe-character-expand: pre-027 shipped, auto-updatable to the post-027- // (`speechPattern` field added alongside `speechAccent`) hash.- 'universe-character-expand.md': ['ef109eb8e12ddb664c11c790271b5139'],- // story-builder-idea-expand: pre-055 (seed-only) and post-055-pre-fence- // ({{sourceMaterial}} block, no guard) auto-updatable to the post-055-fence- // ({{sourceMaterial}} block + injection-guard sentence) hash.- 'story-builder-idea-expand.md': ['a23939626a226f7420cebfb45d47950c', '778c86e2caa120856c36e4d5a4da3355'],- // editorial-analysis: pre-042 (pipe-separated arcDirection enum + ≤160- // excerpt) auto-updatable to the post-042 (single-value example, ≤200) hash.- 'pipeline-editorial-analysis.md': ['14d9879697c66d51830cc798040d5369'],- // manuscript-completeness: pre-056 (location-only findings) auto-updatable to- // the post-056 (issueNumber + anchorQuote anchored findings) hash; and- // pre-057 (five categories) auto-updatable to the post-057 (comic-structure) hash.- 'pipeline-manuscript-completeness.md': ['e6858c74ab2cead752d388e3f428406c', '4f2b95778aed85f5fc461d71eb461b79'],- // manuscript-fix: pre-060 single `{ find, replace }` contract auto-updatable- // to the post-060 `{ edits: [{ issueNumber, find, replace }] }` contract.- 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee'],- // CoS agent prompt: drop obsolete "# Chief of Staff Agent Briefing" header- // and "You are an autonomous agent…" preamble (migration 009). Every- // historical shipped hash is auto-updatable to the new sample.- 'cos-agent-briefing.md': [- '699d053875472df455258724a0162bd5',- '181b26838e526427173e4dccfc884d01',- '3e1ca7f7b14b799f89a193c568003624',- 'af73fd50d6f29d561772474c12346e53',- '9bcd3a0167dd4aed7cfff7f404494dfb',- 'd761133753da290a0c02eca1c87709e4',- ],-};-const SHIPPED_PROMPT_NEW_MD5 = {- 'pipeline-idea-expansion.md': '49a208628290543ba2607a5ed48fdc8c',- 'pipeline-prose.md': '84523d531eeafa60959c65c553b2563f',- 'pipeline-comic-script.md': 'dea7d497d1cb38e7574f236f4ff8e644',- 'pipeline-teleplay.md': 'afa4215330bf856429d70d7e2f856605',- 'pipeline-season-episodes.md':'50c68a29c3ebc275db3095d06bd87100',- 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0',- 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c',- 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',- 'pipeline-arc-resolve.md': '5b340885c6e8f8afc63424d6b5bc7eb7',- 'pipeline-extract-scenes.md': 'c51fb208568d0d903eb43b437478b0ba',- 'writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4',- 'cos-agent-briefing.md': 'dccb392a43cbd3dac900fee12c31619a',- 'universe-character-expand.md':'67b6e73ed47f318451a730088b4cff14',- 'story-builder-idea-expand.md':'c12d76fefaaded2838023065bfc94bb0',- 'pipeline-editorial-analysis.md':'daeb02bd54b0c099b21af659c6298cfe',- 'pipeline-manuscript-completeness.md':'1ee5ac936fbf1d365e0eaea99bcf1e77',- 'pipeline-manuscript-fix.md':'c88a56304eb5e290ae0de9dadd20b310',-};-const SHIPPED_PROMPT_FILES = Object.keys(SHIPPED_PROMPT_OLD_MD5);--// Shared `_partials/*.md` fragments are mustache-rendered into multiple-// stage prompts (e.g. `bible-deference.md` is included by every stage-// that references both character + place bibles). They get their own-// drift table so the loop below scans them in parallel with stage-// prompts and warns the user when a migration's pending.-const SHIPPED_PARTIAL_OLD_MD5 = {- // setting→place rename, migration 022.- 'bible-deference.md': '218f0e85643609ed85a12b1ccc7b5a8d',-};-const SHIPPED_PARTIAL_NEW_MD5 = {- 'bible-deference.md': 'a4681348c27776e414acf6e0be566a99',-};-const SHIPPED_PARTIAL_FILES = Object.keys(SHIPPED_PARTIAL_OLD_MD5);+// The drift tables are NOT hand-mirrored here — they are swept from each+// migration's exported `ACCEPTED_OLD_MD5` / `NEW_SHIPPED_MD5` (+ optional+// `DRIFT_SUBDIRS`) constants, so the migration that actually performs the+// auto-update is the single source of truth. `buildPromptDriftTables` merges+// each file's lineage (union of accepted-old + intermediate-new hashes; the+// highest-numbered migration's new hash is the current shipped baseline) and+// returns per-subdir `{ oldMap, newMap, files }` tables. Only the files+// managed by a migration are checked, so prompts with no migration counterpart+// (e.g. cd-evaluate.md) never produce misleading warnings.+const driftTables = await buildPromptDriftTables(join(__dirname, 'migrations'));+const EMPTY_DRIFT_TABLE = { oldMap: {}, newMap: {}, files: [] };+const stageTable = driftTables.stages || EMPTY_DRIFT_TABLE;+const partialTable = driftTables._partials || EMPTY_DRIFT_TABLE;// Walk one directory's worth of shipped prompt files against a hash table// and partition them into auto-updatable (still on a known old hash) vs.@@ -254,6 +157,10 @@ const collectDrift = ({ sampleSubdir, dataSubdir, files, oldMap, newMap }) => {const customized = [];for (const f of files) {const dataPath = join(dataSubpath, f);+ // No data.reference twin → the prompt was renamed/retired upstream (e.g.+ // pipeline-tv-script.md → pipeline-teleplay.md); there's nothing to+ // auto-update *to*, so skip rather than warn about a phantom drift.+ if (!existsSync(join(sampleSubpath, f))) continue;if (!existsSync(dataPath)) continue;const dataMd5 = md5(readFileSync(dataPath, 'utf8'));if (dataMd5 === newMap[f]) continue;@@ -271,16 +178,16 @@ const collectDrift = ({ sampleSubdir, dataSubdir, files, oldMap, newMap }) => {const stageDrift = collectDrift({sampleSubdir: ['prompts', 'stages'],dataSubdir: ['prompts', 'stages'],- files: SHIPPED_PROMPT_FILES,- oldMap: SHIPPED_PROMPT_OLD_MD5,- newMap: SHIPPED_PROMPT_NEW_MD5,+ files: stageTable.files,+ oldMap: stageTable.oldMap,+ newMap: stageTable.newMap,});const partialDrift = collectDrift({sampleSubdir: ['prompts', '_partials'],dataSubdir: ['prompts', '_partials'],- files: SHIPPED_PARTIAL_FILES,- oldMap: SHIPPED_PARTIAL_OLD_MD5,- newMap: SHIPPED_PARTIAL_NEW_MD5,+ files: partialTable.files,+ oldMap: partialTable.oldMap,+ newMap: partialTable.newMap,});const autoUpdatable = [