Skip to content

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

fix: heal cd-treatment.md installs stranded by #1808 anchor migration (#2042)

Adam Eivyabd347dbad7a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
new file mode 100644
index 0000000000..2d1f5af95c
--- /dev/null
+++ b/.changelog/NEXT.md
@@ -0,0 +1,5 @@
+# Unreleased Changes
+
+## Internal
+
+- Migration 155 heals `data/prompts/stages/cd-treatment.md` installs that #1808's anchor-based migration 148 left stranded (#2042). Installs seeded before the `imageStrength` scene knob (older pre-#1808 template) got the `## Cast & ingredients` list but missed the per-scene `"cast": [{ "ingredientId": … }]` field, so the Creative Director cast-threading regression test stayed red on the runtime template and migration 148 (already applied) never re-ran. The new hash-driven prompt-replace upgrades those copies (and both pristine pre-#1808 shipped versions) to the current shipped reference, leaving hand-customized copies untouched. Also folds `cd-treatment.md` into `buildPromptDriftTables` so setup-data.js's drift warning classifies a stranded copy correctly.
diff --git a/scripts/migrations/155-heal-cd-treatment-cast-strand.js b/scripts/migrations/155-heal-cd-treatment-cast-strand.js
new file mode 100644
index 0000000000..f271791080
--- /dev/null
+++ b/scripts/migrations/155-heal-cd-treatment-cast-strand.js
@@ -0,0 +1,68 @@
+/**
+ * Heal cd-treatment.md installs that #1808's migration 148 left stranded (#2042).
+ *
+ * Migration 148 backfilled the catalog-cast surfacing into
+ * `data/prompts/stages/cd-treatment.md` with two ANCHOR-based surgical inserts:
+ * 1. the `## Cast & ingredients` list section (anchored on the style-spec →
+ * user-story bracket), and
+ * 2. the per-scene `"cast": [{ "ingredientId": … }]` JSON field (anchored on
+ * the scene example's `"imageStrength": null` line).
+ *
+ * An install seeded BEFORE the `imageStrength` scene knob shipped (the older
+ * pre-#1808 template, md5 `2ffa482e…`) carries a scene example that lacks that
+ * anchor, so 148 applied insertion 1 (the file gained the cast list) but silently
+ * skipped insertion 2 — leaving the file at md5 `95b76856…`: it has the Cast
+ * section but is missing the per-scene `cast` field that
+ * `data.reference/prompts/stages/cd-treatment.md` ships. Because 148 is already
+ * recorded in `data/migrations.applied.json` on those installs, it never re-runs,
+ * so the `creativeDirectorPrompts.test.js` cast-threading regression stays red on
+ * the runtime template forever.
+ *
+ * This migration finishes the job with the canonical hash-driven prompt-replace
+ * (`./_lib.js`): when the installed copy still matches a KNOWN machine-produced
+ * shape (either pristine pre-#1808 shipped version, or the 148-partial strand) it
+ * is replaced wholesale with the current shipped reference. A hand-customized
+ * copy (hash matches neither old nor new) is left untouched with a warning — same
+ * safety contract as every other prompt-replace migration. Idempotent.
+ *
+ * Exporting ACCEPTED_OLD_MD5 / NEW_SHIPPED_MD5 also folds cd-treatment.md into
+ * `buildPromptDriftTables`, so setup-data.js's drift warning classifies a
+ * stranded copy as auto-updatable (was previously invisible to the sweep because
+ * 148 tracked the file via anchors, not hashes).
+ */
+
+import { makePromptReplaceMigration } from './_lib.js';
+
+export const ACCEPTED_OLD_MD5 = {
+ 'cd-treatment.md': [
+ '2ffa482e7bfb6fe8b7224505fedbf712', // pre-#1808 shipped, pre-imageStrength-knob (447d2b5e3 / 22a0aced0)
+ '16d0ef6a7fd2533719a846019122ebee', // pre-#1808 shipped, post-imageStrength-knob (c68f38d09 / f04e3955c)
+ '95b7685690ecfee4f682b0293b790277', // migration-148 partial: cast list inserted, per-scene cast field missed (the #2042 strand)
+ ],
+};
+
+export const NEW_SHIPPED_MD5 = {
+ 'cd-treatment.md': 'd940eadfb406ce584f0e244032f33382', // #1808 shipped reference (cast list + per-scene cast field)
+};
+
+const { applyMigration, up } = makePromptReplaceMigration({
+ accepted: ACCEPTED_OLD_MD5,
+ current: NEW_SHIPPED_MD5,
+ label: 'cd-treatment catalog-cast strand',
+ customizedHint: (filename) =>
+ ` To apply the per-scene cast field manually, diff:\n` +
+ ` data.reference/prompts/stages/${filename}\n` +
+ ` against your current:\n` +
+ ` data/prompts/stages/${filename}\n` +
+ ` and add the gated "cast": [{ "ingredientId": … }] field after the\n` +
+ ` scene example's "imageStrength" line.`,
+ skipFooter: (count) =>
+ `⚠️ ${count} cd-treatment prompt(s) could not be auto-updated because\n` +
+ ` they were customized. Creative Director treatments still generate, but\n` +
+ ` per-scene cast threading may stay underspecified until you merge the\n` +
+ ` prompt change manually.\n` +
+ ` See data.reference/prompts/stages/cd-treatment.md.`,
+});
+
+export { applyMigration };
+export default { up };
diff --git a/scripts/migrations/155-heal-cd-treatment-cast-strand.test.js b/scripts/migrations/155-heal-cd-treatment-cast-strand.test.js
new file mode 100644
index 0000000000..b39d8ddc2f
--- /dev/null
+++ b/scripts/migrations/155-heal-cd-treatment-cast-strand.test.js
@@ -0,0 +1,27 @@
+import { describe, it, expect } from 'vitest';
+
+import { runPromptMigrationTests } from './_testHelpers.js';
+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './155-heal-cd-treatment-cast-strand.js';
+
+describe('migration 155 - heal cd-treatment catalog-cast strand', () => {
+ runPromptMigrationTests({
+ migration,
+ applyMigration,
+ ACCEPTED_OLD_MD5,
+ NEW_SHIPPED_MD5,
+ prefix: 'migration-155-',
+ });
+
+ it('tracks the exact #2042 strand hash (148-partial) as auto-updatable', () => {
+ // md5 `95b76856…` is the deterministic output of migration 148 applied to
+ // the older pre-#1808 shipped template (`2ffa482e…`, pre-imageStrength-knob):
+ // insertion 1 lands the Cast list, insertion 2's scene anchor misses. That
+ // stranded shape must be in the accepted-old set or the fix is a no-op.
+ expect(ACCEPTED_OLD_MD5['cd-treatment.md']).toContain('95b7685690ecfee4f682b0293b790277');
+ // Both pristine pre-#1808 shipped versions upgrade too.
+ expect(ACCEPTED_OLD_MD5['cd-treatment.md']).toContain('2ffa482e7bfb6fe8b7224505fedbf712');
+ expect(ACCEPTED_OLD_MD5['cd-treatment.md']).toContain('16d0ef6a7fd2533719a846019122ebee');
+ // Current shipped hash must never appear in its own accepted-old set.
+ expect(ACCEPTED_OLD_MD5['cd-treatment.md']).not.toContain(NEW_SHIPPED_MD5['cd-treatment.md']);
+ });
+});
diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.js
index 8014087190..c8a1e8948d 100644
--- a/scripts/setup-data-drift.test.js
+++ b/scripts/setup-data-drift.test.js
@@ -46,6 +46,7 @@ const EXPECTED_STAGE_OLD = {
'pipeline-editorial-chekhov.md': ['bfacbf343ba2b9a3f6037bb45b94e1bb'],
'pipeline-editorial-on-the-nose.md': ['48182b49149e6b5829fbed71b3ffc242'],
'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],
+ 'cd-treatment.md': ['2ffa482e7bfb6fe8b7224505fedbf712', '16d0ef6a7fd2533719a846019122ebee', '95b7685690ecfee4f682b0293b790277'],
};
const EXPECTED_STAGE_NEW = {
'pipeline-idea-expansion.md': 'd6fa86a435f978336661dcabca67258f',
@@ -70,6 +71,7 @@ const EXPECTED_STAGE_NEW = {
'pipeline-editorial-chekhov.md': '1f8a1696b5e4f476051dc5b2e5737db9',
'pipeline-editorial-on-the-nose.md': 'e5786fb019e5bf19c7aa6ed0c8b35cda',
'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',
+ 'cd-treatment.md': 'd940eadfb406ce584f0e244032f33382',
};
const EXPECTED_PARTIAL_OLD = {
'bible-deference.md': ['218f0e85643609ed85a12b1ccc7b5a8d'],