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

refactor: extract makeSeedMigration helper for copy-paste stage-seed migrations (#1838)

[._.]/ Adam Eivy8476431d5279
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index c75a9c7669..82ed5531db 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -26,6 +26,7 @@
## Internal
+- **Extracted a shared helper for the copy-paste stage-seed migrations** — ~45 first-shipment "seed a new pipeline stage" migrations under `scripts/migrations/` (e.g. `130-editorial-character-consistency-stage.js`) were near-identical: only `FILENAME`/`STAGE_KEY` differed while ~70 lines of read-reference → no-clobber-copy → merge-stage-config were verbatim copies, each with its own copy-paste test. They now collapse to a 3-line `export default makeSeedMigration(stageKey, filename)` call from a new `scripts/migrations/_seedStageHelpers.js` (companion to the existing `_lib.js`/`_testHelpers.js`; the runner skips `_`-prefixed files). The helper reproduces the canonical behavior byte-for-byte — fresh-seed, idempotent no-clobber of a customized `.md`/config, and missing-reference no-throw — with an optional `logPrefix` so the handful of files that logged a shortened label keep identical console output; no `down()` is emitted because the runner (`run-migrations.js`) only ever calls `up()` and tracks applied migrations by filename. 41 single-stage migrations refactored (net −2,259 lines), all 757 `scripts/` tests pass unchanged, and the new `_seedStageHelpers.test.js` covers the helper directly. (#1838)
- **Replaced aiToolkit runner monkey-patching with declared extension points** — `server/index.js` previously reached into the toolkit runner's private surface, overwriting `executeCliRun`/`executeTuiRun` and re-wrapping `stopRun`/`isRunActive`/`deleteRun` to consult an ad-hoc `_portosActiveRuns` map, plus inlining a 34-line update-marker IIFE in bootstrap. The toolkit runner (`server/lib/aiToolkit/runner.js`) now exposes `setCliRunner()`/`setTuiRunner()` and an external-run registry (`registerExternalRun`/`unregisterExternalRun`/`hasExternalRun`) that its own `stopRun`/`isRunActive`/`deleteRun` consult first — so the host registers its CLI/TUI runners through a documented contract instead of mutating private props, and adding a new lifecycle method no longer requires a matching monkey-patch. `server/services/runner.js` tracks its child processes via the registry, and the update-marker read/validate/record/cleanup lifecycle moved into a unit-tested `processUpdateMarker()` in `server/services/updateChecker.js`. Behavior-preserving; the aiToolkit override contract (`server/lib/aiToolkit/CLAUDE.md`) is updated to match. (#1834)
- **Decomposed two remaining large files: `server/routes/meatspace.js` + `server/services/videoGen/local.js`** — the 1,069-line `meatspace.js` router (14 health sub-domains, each backed by its own service import) is split one concern per file (`meatspaceCoreRoutes.js` overview/config/birth-date/death-clock/LEV, `meatspaceAlcoholRoutes.js`, `meatspaceNicotineRoutes.js`, `meatspaceHealthRoutes.js` blood/body/BP/workouts/epigenetic/eyes, `meatspacePostRoutes.js` POST drills + training + memory builder, `meatspaceCalendarRoutes.js` life calendar/activities/events, `meatspaceExportRoutes.js` MortalLoom export), assembled by a thin `meatspace.js` barrel that mounts each under `/api/meatspace` — the same pattern `routes/cos.js`/`routes/brain.js` use; the split is wiring-only (the 70-route surface is byte-identical, verified). The 1,805-line `videoGen/local.js` had its BYOV runtime management (venv/helper-script path constants, `BYOV_RUNTIME_INFO`, install/ready/fingerprint probes) extracted to `videoGen/runtimes.js` and its render-history I/O (`loadHistory`/`saveHistory`) to `videoGen/history.js`; `local.js` keeps generation + post-processing and re-exports the extracted surface so every existing deep import (`from '../videoGen/local.js'`) keeps resolving unchanged (all 30 prior exports preserved, verified). (#1833)
- **Decomposed `server/routes/brain.js` (1,149-line router covering 13 sub-domains)** — the monolithic Brain router that mixed capture/inbox, four entity CRUD collections + memories, digest/review, settings/summary, links + buckets, graph, federation sync, and the daily log is now split one concern per file (`brainCapture.js`, `brainCrud.js`, `brainDigest.js`, `brainSettings.js`, `brainLinks.js`, `brainGraph.js`, `brainSync.js`, `brainDailyLog.js`), assembled by a thin `brain.js` barrel that mounts each sub-router under `/api/brain` — the same pattern `routes/cos.js` already uses. The split is wiring-only: route paths, ordering (literal-before-`:id` routes stay within their owning sub-router), validation, and the barrel's default export are unchanged, so `server/index.js` and the existing `brain.test.js` (105 tests) pass without edits. (#1832)
diff --git a/scripts/migrations/017-volume-cover-concepts-stage.js b/scripts/migrations/017-volume-cover-concepts-stage.js
index e7976c2ed2..932386505a 100644
--- a/scripts/migrations/017-volume-cover-concepts-stage.js
+++ b/scripts/migrations/017-volume-cover-concepts-stage.js
@@ -19,66 +19,6 @@
* idempotent pattern as `015-importer-stage-prompts.js`.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-volume-cover-concepts.md';
-const STAGE_KEY = 'pipeline-volume-cover-concepts';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 volume-cover-concepts prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ volume-cover-concepts: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ volume-cover-concepts: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ volume-cover-concepts: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 volume-cover-concepts stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ volume-cover-concepts: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 volume-cover-concepts stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ volume-cover-concepts: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-volume-cover-concepts', 'pipeline-volume-cover-concepts.md', { logPrefix: 'volume-cover-concepts' });
diff --git a/scripts/migrations/020-comic-cover-concepts-stage.js b/scripts/migrations/020-comic-cover-concepts-stage.js
index ecb1e27c1c..3f4d42e4e4 100644
--- a/scripts/migrations/020-comic-cover-concepts-stage.js
+++ b/scripts/migrations/020-comic-cover-concepts-stage.js
@@ -7,66 +7,6 @@
* `setup-data.js` still get the new per-issue cover-concept LLM step.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-comic-cover-concepts.md';
-const STAGE_KEY = 'pipeline-comic-cover-concepts';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 comic-cover-concepts prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ comic-cover-concepts: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ comic-cover-concepts: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ comic-cover-concepts: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 comic-cover-concepts stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ comic-cover-concepts: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 comic-cover-concepts stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ comic-cover-concepts: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-comic-cover-concepts', 'pipeline-comic-cover-concepts.md', { logPrefix: 'comic-cover-concepts' });
diff --git a/scripts/migrations/041-editorial-analysis-stage.js b/scripts/migrations/041-editorial-analysis-stage.js
index 6f56cce0eb..47cf3b7045 100644
--- a/scripts/migrations/041-editorial-analysis-stage.js
+++ b/scripts/migrations/041-editorial-analysis-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time a user runs the analysis.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-analysis.md';
-const STAGE_KEY = 'pipeline-editorial-analysis';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 editorial-analysis prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ editorial-analysis: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ editorial-analysis: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ editorial-analysis: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 editorial-analysis stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ editorial-analysis: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 editorial-analysis stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ editorial-analysis: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-analysis', 'pipeline-editorial-analysis.md', { logPrefix: 'editorial-analysis' });
diff --git a/scripts/migrations/087-manuscript-reformat-stage.js b/scripts/migrations/087-manuscript-reformat-stage.js
index 426831dc6b..39b5cd9add 100644
--- a/scripts/migrations/087-manuscript-reformat-stage.js
+++ b/scripts/migrations/087-manuscript-reformat-stage.js
@@ -10,66 +10,6 @@
* not found" the first time a user clicks Reformat (AI).
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'manuscript-reformat.md';
-const STAGE_KEY = 'manuscript-reformat';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 manuscript-reformat prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ manuscript-reformat: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ manuscript-reformat: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ manuscript-reformat: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 manuscript-reformat stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ manuscript-reformat: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 manuscript-reformat stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ manuscript-reformat: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('manuscript-reformat', 'manuscript-reformat.md');
diff --git a/scripts/migrations/088-series-generate-stage.js b/scripts/migrations/088-series-generate-stage.js
index 798b92b2a6..bfdbd896fc 100644
--- a/scripts/migrations/088-series-generate-stage.js
+++ b/scripts/migrations/088-series-generate-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time a user clicks Generate with AI.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-series-generate.md';
-const STAGE_KEY = 'pipeline-series-generate';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-series-generate prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-series-generate: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-series-generate: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-series-generate: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-series-generate stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-series-generate: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-series-generate stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-series-generate: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-series-generate', 'pipeline-series-generate.md');
diff --git a/scripts/migrations/089-canon-describe-from-prose-stage.js b/scripts/migrations/089-canon-describe-from-prose-stage.js
index 5d25e91464..cb34da6c43 100644
--- a/scripts/migrations/089-canon-describe-from-prose-stage.js
+++ b/scripts/migrations/089-canon-describe-from-prose-stage.js
@@ -15,66 +15,6 @@
* (normalize line endings, ship OLD + NEW shipped hashes) instead.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-canon-describe-from-prose.md';
-const STAGE_KEY = 'pipeline-canon-describe-from-prose';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log('📝 pipeline-canon-describe-from-prose prompt: already present');
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-canon-describe-from-prose: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-canon-describe-from-prose: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-canon-describe-from-prose: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log('📝 pipeline-canon-describe-from-prose stage-config: already present');
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-canon-describe-from-prose: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-canon-describe-from-prose stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-canon-describe-from-prose: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-canon-describe-from-prose', 'pipeline-canon-describe-from-prose.md');
diff --git a/scripts/migrations/090-script-verify-stage.js b/scripts/migrations/090-script-verify-stage.js
index c502b97ef0..90aaa6b92e 100644
--- a/scripts/migrations/090-script-verify-stage.js
+++ b/scripts/migrations/090-script-verify-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time the script gate runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-script-verify.md';
-const STAGE_KEY = 'pipeline-script-verify';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-script-verify prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-script-verify: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-script-verify: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-script-verify: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-script-verify stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-script-verify: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-script-verify stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-script-verify: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-script-verify', 'pipeline-script-verify.md');
diff --git a/scripts/migrations/092-editorial-info-dumping-stage.js b/scripts/migrations/092-editorial-info-dumping-stage.js
index e7f2a4adf9..d6f147b9ab 100644
--- a/scripts/migrations/092-editorial-info-dumping-stage.js
+++ b/scripts/migrations/092-editorial-info-dumping-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-info-dumping.md';
-const STAGE_KEY = 'pipeline-editorial-info-dumping';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-info-dumping prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-info-dumping: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-info-dumping: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-info-dumping: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-info-dumping stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-info-dumping: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-info-dumping stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-info-dumping: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-info-dumping', 'pipeline-editorial-info-dumping.md');
diff --git a/scripts/migrations/093-reverse-outline-stage.js b/scripts/migrations/093-reverse-outline-stage.js
index d9059092bf..28a313ca2d 100644
--- a/scripts/migrations/093-reverse-outline-stage.js
+++ b/scripts/migrations/093-reverse-outline-stage.js
@@ -10,66 +10,6 @@
* found" the first time a user generates a reverse outline.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-reverse-outline.md';
-const STAGE_KEY = 'pipeline-reverse-outline';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-reverse-outline prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-reverse-outline: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-reverse-outline: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-reverse-outline: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-reverse-outline stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-reverse-outline: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-reverse-outline stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-reverse-outline: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-reverse-outline', 'pipeline-reverse-outline.md');
diff --git a/scripts/migrations/096-editorial-style-conformance-stage.js b/scripts/migrations/096-editorial-style-conformance-stage.js
index affaf2a6d5..fdbb18167a 100644
--- a/scripts/migrations/096-editorial-style-conformance-stage.js
+++ b/scripts/migrations/096-editorial-style-conformance-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-style-conformance.md';
-const STAGE_KEY = 'pipeline-editorial-style-conformance';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-style-conformance prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-style-conformance: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-style-conformance: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-style-conformance: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-style-conformance stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-style-conformance: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-style-conformance stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-style-conformance: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-style-conformance', 'pipeline-editorial-style-conformance.md');
diff --git a/scripts/migrations/097-continuity-bible-stage.js b/scripts/migrations/097-continuity-bible-stage.js
index c9b59142f6..080f598662 100644
--- a/scripts/migrations/097-continuity-bible-stage.js
+++ b/scripts/migrations/097-continuity-bible-stage.js
@@ -10,66 +10,6 @@
* found" the first time a user generates a continuity bible.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-continuity-bible.md';
-const STAGE_KEY = 'pipeline-continuity-bible';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-continuity-bible prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-continuity-bible: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-continuity-bible: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-continuity-bible: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-continuity-bible stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-continuity-bible: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-continuity-bible stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-continuity-bible: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-continuity-bible', 'pipeline-continuity-bible.md');
diff --git a/scripts/migrations/099-editorial-interiority-stage.js b/scripts/migrations/099-editorial-interiority-stage.js
index 0d4da6eab9..7eda8299fb 100644
--- a/scripts/migrations/099-editorial-interiority-stage.js
+++ b/scripts/migrations/099-editorial-interiority-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-interiority.md';
-const STAGE_KEY = 'pipeline-editorial-interiority';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-interiority prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-interiority: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-interiority: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-interiority: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-interiority stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-interiority: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-interiority stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-interiority: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-interiority', 'pipeline-editorial-interiority.md');
diff --git a/scripts/migrations/100-editorial-chekhov-stage.js b/scripts/migrations/100-editorial-chekhov-stage.js
index bf50c617c0..078c5604b2 100644
--- a/scripts/migrations/100-editorial-chekhov-stage.js
+++ b/scripts/migrations/100-editorial-chekhov-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-chekhov.md';
-const STAGE_KEY = 'pipeline-editorial-chekhov';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-chekhov prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-chekhov: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-chekhov: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-chekhov: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-chekhov stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-chekhov: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-chekhov stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-chekhov: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-chekhov', 'pipeline-editorial-chekhov.md');
diff --git a/scripts/migrations/101-editorial-dead-metaphor-stage.js b/scripts/migrations/101-editorial-dead-metaphor-stage.js
index 917c6041de..550bf301fe 100644
--- a/scripts/migrations/101-editorial-dead-metaphor-stage.js
+++ b/scripts/migrations/101-editorial-dead-metaphor-stage.js
@@ -10,66 +10,6 @@
* first time it runs. (The deterministic siblings need no stage.)
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-dead-metaphor.md';
-const STAGE_KEY = 'pipeline-editorial-dead-metaphor';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-dead-metaphor prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-dead-metaphor: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-dead-metaphor: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-dead-metaphor: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-dead-metaphor stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-dead-metaphor: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-dead-metaphor stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-dead-metaphor: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-dead-metaphor', 'pipeline-editorial-dead-metaphor.md');
diff --git a/scripts/migrations/102-editorial-endings-cliffhanger-stage.js b/scripts/migrations/102-editorial-endings-cliffhanger-stage.js
index 0db6b926fa..466ef3612c 100644
--- a/scripts/migrations/102-editorial-endings-cliffhanger-stage.js
+++ b/scripts/migrations/102-editorial-endings-cliffhanger-stage.js
@@ -14,66 +14,6 @@
* `setup-data.js#buildPromptDriftTables` can auto-upgrade other installs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-endings-cliffhanger.md';
-const STAGE_KEY = 'pipeline-editorial-endings-cliffhanger';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-endings-cliffhanger prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-endings-cliffhanger: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-endings-cliffhanger: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-endings-cliffhanger: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-endings-cliffhanger stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-endings-cliffhanger: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-endings-cliffhanger stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-endings-cliffhanger: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-endings-cliffhanger', 'pipeline-editorial-endings-cliffhanger.md');
diff --git a/scripts/migrations/103-editorial-opening-start-stage.js b/scripts/migrations/103-editorial-opening-start-stage.js
index 1561f8dd12..08d327b4e1 100644
--- a/scripts/migrations/103-editorial-opening-start-stage.js
+++ b/scripts/migrations/103-editorial-opening-start-stage.js
@@ -11,66 +11,6 @@
* stage.)
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-opening-start.md';
-const STAGE_KEY = 'pipeline-editorial-opening-start';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 ${STAGE_KEY} prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ ${STAGE_KEY}: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn(`⚠️ ${STAGE_KEY}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 ${STAGE_KEY} stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ ${STAGE_KEY}: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 ${STAGE_KEY} stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-opening-start', 'pipeline-editorial-opening-start.md');
diff --git a/scripts/migrations/104-editorial-mirror-description-stage.js b/scripts/migrations/104-editorial-mirror-description-stage.js
index ed4b1f9ccd..9c82170900 100644
--- a/scripts/migrations/104-editorial-mirror-description-stage.js
+++ b/scripts/migrations/104-editorial-mirror-description-stage.js
@@ -10,66 +10,6 @@
* not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-mirror-description.md';
-const STAGE_KEY = 'pipeline-editorial-mirror-description';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 ${STAGE_KEY} prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ ${STAGE_KEY}: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn(`⚠️ ${STAGE_KEY}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 ${STAGE_KEY} stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ ${STAGE_KEY}: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 ${STAGE_KEY} stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-mirror-description', 'pipeline-editorial-mirror-description.md');
diff --git a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js
index 22ac012c0d..48ec5bfef5 100644
--- a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js
+++ b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js
@@ -10,66 +10,6 @@
* found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-dialogue-pleasantries.md';
-const STAGE_KEY = 'pipeline-editorial-dialogue-pleasantries';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 ${STAGE_KEY} prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ ${STAGE_KEY}: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn(`⚠️ ${STAGE_KEY}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 ${STAGE_KEY} stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ ${STAGE_KEY}: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 ${STAGE_KEY} stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-dialogue-pleasantries', 'pipeline-editorial-dialogue-pleasantries.md');
diff --git a/scripts/migrations/106-editorial-kill-your-darlings-stage.js b/scripts/migrations/106-editorial-kill-your-darlings-stage.js
index 4bb04e200d..9fc8273f44 100644
--- a/scripts/migrations/106-editorial-kill-your-darlings-stage.js
+++ b/scripts/migrations/106-editorial-kill-your-darlings-stage.js
@@ -10,66 +10,6 @@
* not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-kill-your-darlings.md';
-const STAGE_KEY = 'pipeline-editorial-kill-your-darlings';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 ${STAGE_KEY} prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ ${STAGE_KEY}: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn(`⚠️ ${STAGE_KEY}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 ${STAGE_KEY} stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ ${STAGE_KEY}: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 ${STAGE_KEY} stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ ${STAGE_KEY}: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-kill-your-darlings', 'pipeline-editorial-kill-your-darlings.md');
diff --git a/scripts/migrations/109-editorial-arc-transitions-stage.js b/scripts/migrations/109-editorial-arc-transitions-stage.js
index afa8edb59a..d85f338f1f 100644
--- a/scripts/migrations/109-editorial-arc-transitions-stage.js
+++ b/scripts/migrations/109-editorial-arc-transitions-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-arc-transitions.md';
-const STAGE_KEY = 'pipeline-editorial-arc-transitions';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-arc-transitions prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-arc-transitions: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-arc-transitions: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-arc-transitions: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-arc-transitions stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-arc-transitions: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-arc-transitions stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-arc-transitions: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-arc-transitions', 'pipeline-editorial-arc-transitions.md');
diff --git a/scripts/migrations/110-editorial-telling-emotion-stage.js b/scripts/migrations/110-editorial-telling-emotion-stage.js
index 3d0169f0eb..bf0fbeff4d 100644
--- a/scripts/migrations/110-editorial-telling-emotion-stage.js
+++ b/scripts/migrations/110-editorial-telling-emotion-stage.js
@@ -12,66 +12,6 @@
* prose.repeated-gestures, prose.word-echoes, prose.sentence-rhythm) need no stage.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-telling-emotion.md';
-const STAGE_KEY = 'pipeline-editorial-telling-emotion';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-telling-emotion prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-telling-emotion: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-telling-emotion: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-telling-emotion: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-telling-emotion stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-telling-emotion: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-telling-emotion stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-telling-emotion: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-telling-emotion', 'pipeline-editorial-telling-emotion.md');
diff --git a/scripts/migrations/111-editorial-plot-structure-stage.js b/scripts/migrations/111-editorial-plot-structure-stage.js
index 9270619791..0578d0715a 100644
--- a/scripts/migrations/111-editorial-plot-structure-stage.js
+++ b/scripts/migrations/111-editorial-plot-structure-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-plot-structure.md';
-const STAGE_KEY = 'pipeline-editorial-plot-structure';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-plot-structure prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-plot-structure: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-plot-structure: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-plot-structure: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-plot-structure stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-plot-structure: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-plot-structure stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-plot-structure: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-plot-structure', 'pipeline-editorial-plot-structure.md');
diff --git a/scripts/migrations/112-editorial-on-the-nose-stage.js b/scripts/migrations/112-editorial-on-the-nose-stage.js
index 483b526421..a1798bed5e 100644
--- a/scripts/migrations/112-editorial-on-the-nose-stage.js
+++ b/scripts/migrations/112-editorial-on-the-nose-stage.js
@@ -11,66 +11,6 @@
* (dialogue.said-bookisms, dialogue.attribution-clarity) need no stage.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-on-the-nose.md';
-const STAGE_KEY = 'pipeline-editorial-on-the-nose';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-on-the-nose prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-on-the-nose: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-on-the-nose: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-on-the-nose: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-on-the-nose stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-on-the-nose: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-on-the-nose stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-on-the-nose: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-on-the-nose', 'pipeline-editorial-on-the-nose.md');
diff --git a/scripts/migrations/113-editorial-voice-distinctiveness-stage.js b/scripts/migrations/113-editorial-voice-distinctiveness-stage.js
index 15016723d3..1790b304f2 100644
--- a/scripts/migrations/113-editorial-voice-distinctiveness-stage.js
+++ b/scripts/migrations/113-editorial-voice-distinctiveness-stage.js
@@ -11,66 +11,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-voice-distinctiveness.md';
-const STAGE_KEY = 'pipeline-editorial-voice-distinctiveness';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-voice-distinctiveness prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-voice-distinctiveness: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-voice-distinctiveness: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-voice-distinctiveness: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-voice-distinctiveness stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-voice-distinctiveness: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-voice-distinctiveness stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-voice-distinctiveness: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-voice-distinctiveness', 'pipeline-editorial-voice-distinctiveness.md');
diff --git a/scripts/migrations/115-editorial-theme-coherence-stage.js b/scripts/migrations/115-editorial-theme-coherence-stage.js
index b75d903269..10792ed06a 100644
--- a/scripts/migrations/115-editorial-theme-coherence-stage.js
+++ b/scripts/migrations/115-editorial-theme-coherence-stage.js
@@ -10,66 +10,6 @@
* found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-theme-coherence.md';
-const STAGE_KEY = 'pipeline-editorial-theme-coherence';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-theme-coherence prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-theme-coherence: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-theme-coherence: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-theme-coherence: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-theme-coherence stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-theme-coherence: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-theme-coherence stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-theme-coherence: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-theme-coherence', 'pipeline-editorial-theme-coherence.md');
diff --git a/scripts/migrations/116-editorial-unmodeled-names-stage.js b/scripts/migrations/116-editorial-unmodeled-names-stage.js
index 6d06a8660a..9b19c6d4a3 100644
--- a/scripts/migrations/116-editorial-unmodeled-names-stage.js
+++ b/scripts/migrations/116-editorial-unmodeled-names-stage.js
@@ -10,66 +10,6 @@
* not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-unmodeled-names.md';
-const STAGE_KEY = 'pipeline-editorial-unmodeled-names';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-unmodeled-names prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-unmodeled-names: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-unmodeled-names: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-unmodeled-names: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-unmodeled-names stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-unmodeled-names: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-unmodeled-names stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-unmodeled-names: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-unmodeled-names', 'pipeline-editorial-unmodeled-names.md');
diff --git a/scripts/migrations/117-editorial-eyeline-match-stage.js b/scripts/migrations/117-editorial-eyeline-match-stage.js
index a5347164d2..a0857dbb8f 100644
--- a/scripts/migrations/117-editorial-eyeline-match-stage.js
+++ b/scripts/migrations/117-editorial-eyeline-match-stage.js
@@ -10,66 +10,6 @@
* the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-eyeline-match.md';
-const STAGE_KEY = 'pipeline-editorial-eyeline-match';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-eyeline-match prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-eyeline-match: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-eyeline-match: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-eyeline-match: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-eyeline-match stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-eyeline-match: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-eyeline-match stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-eyeline-match: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-eyeline-match', 'pipeline-editorial-eyeline-match.md');
diff --git a/scripts/migrations/118-editorial-appearance-continuity-stage.js b/scripts/migrations/118-editorial-appearance-continuity-stage.js
index 968a85a550..9f1dfdf31f 100644
--- a/scripts/migrations/118-editorial-appearance-continuity-stage.js
+++ b/scripts/migrations/118-editorial-appearance-continuity-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-appearance-continuity.md';
-const STAGE_KEY = 'pipeline-editorial-appearance-continuity';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-appearance-continuity prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-appearance-continuity: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-appearance-continuity: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-appearance-continuity: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-appearance-continuity stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-appearance-continuity: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-appearance-continuity stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-appearance-continuity: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-appearance-continuity', 'pipeline-editorial-appearance-continuity.md');
diff --git a/scripts/migrations/119-editorial-comic-page-turn-stage.js b/scripts/migrations/119-editorial-comic-page-turn-stage.js
index d732a39b7d..0485842eec 100644
--- a/scripts/migrations/119-editorial-comic-page-turn-stage.js
+++ b/scripts/migrations/119-editorial-comic-page-turn-stage.js
@@ -14,66 +14,6 @@
* `setup-data.js#buildPromptDriftTables` can auto-upgrade other installs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-comic-page-turn.md';
-const STAGE_KEY = 'pipeline-editorial-comic-page-turn';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-comic-page-turn prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-comic-page-turn: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-comic-page-turn: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-comic-page-turn: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-comic-page-turn stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-comic-page-turn: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-comic-page-turn stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-comic-page-turn: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-comic-page-turn', 'pipeline-editorial-comic-page-turn.md');
diff --git a/scripts/migrations/129-editorial-timeline-contradiction-stage.js b/scripts/migrations/129-editorial-timeline-contradiction-stage.js
index 8dd401978c..e21cab00b5 100644
--- a/scripts/migrations/129-editorial-timeline-contradiction-stage.js
+++ b/scripts/migrations/129-editorial-timeline-contradiction-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-timeline-contradiction.md';
-const STAGE_KEY = 'pipeline-editorial-timeline-contradiction';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-timeline-contradiction prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-timeline-contradiction: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-timeline-contradiction: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-timeline-contradiction: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-timeline-contradiction stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-timeline-contradiction: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-timeline-contradiction stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-timeline-contradiction: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-timeline-contradiction', 'pipeline-editorial-timeline-contradiction.md');
diff --git a/scripts/migrations/130-editorial-character-consistency-stage.js b/scripts/migrations/130-editorial-character-consistency-stage.js
index cacc33faaf..58a01d3ff6 100644
--- a/scripts/migrations/130-editorial-character-consistency-stage.js
+++ b/scripts/migrations/130-editorial-character-consistency-stage.js
@@ -10,66 +10,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-character-consistency.md';
-const STAGE_KEY = 'pipeline-editorial-character-consistency';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-character-consistency prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-character-consistency: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-character-consistency: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-character-consistency: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-character-consistency stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-character-consistency: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-character-consistency stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-character-consistency: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-character-consistency', 'pipeline-editorial-character-consistency.md');
diff --git a/scripts/migrations/131-editorial-climax-agency-stage.js b/scripts/migrations/131-editorial-climax-agency-stage.js
index c4955fb31d..573ed59af7 100644
--- a/scripts/migrations/131-editorial-climax-agency-stage.js
+++ b/scripts/migrations/131-editorial-climax-agency-stage.js
@@ -10,66 +10,6 @@
* first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-climax-agency.md';
-const STAGE_KEY = 'pipeline-editorial-climax-agency';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-climax-agency prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-climax-agency: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-climax-agency: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-climax-agency: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-climax-agency stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-climax-agency: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-climax-agency stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-climax-agency: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-climax-agency', 'pipeline-editorial-climax-agency.md');
diff --git a/scripts/migrations/132-editorial-reaction-proportionality-stage.js b/scripts/migrations/132-editorial-reaction-proportionality-stage.js
index efb47809b1..347d3aa847 100644
--- a/scripts/migrations/132-editorial-reaction-proportionality-stage.js
+++ b/scripts/migrations/132-editorial-reaction-proportionality-stage.js
@@ -10,66 +10,6 @@
* throw "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-reaction-proportionality.md';
-const STAGE_KEY = 'pipeline-editorial-reaction-proportionality';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-reaction-proportionality prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-reaction-proportionality: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-reaction-proportionality: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-reaction-proportionality: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-reaction-proportionality stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-reaction-proportionality: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-reaction-proportionality stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-reaction-proportionality: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-reaction-proportionality', 'pipeline-editorial-reaction-proportionality.md');
diff --git a/scripts/migrations/133-editorial-secondary-arc-stage.js b/scripts/migrations/133-editorial-secondary-arc-stage.js
index 05feaecc4b..abbb660232 100644
--- a/scripts/migrations/133-editorial-secondary-arc-stage.js
+++ b/scripts/migrations/133-editorial-secondary-arc-stage.js
@@ -10,66 +10,6 @@
* the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-secondary-arc.md';
-const STAGE_KEY = 'pipeline-editorial-secondary-arc';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-secondary-arc prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-secondary-arc: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-secondary-arc: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-secondary-arc: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-secondary-arc stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-secondary-arc: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-secondary-arc stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-secondary-arc: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-secondary-arc', 'pipeline-editorial-secondary-arc.md');
diff --git a/scripts/migrations/134-editorial-voice-consistency-stage.js b/scripts/migrations/134-editorial-voice-consistency-stage.js
index 62a4bf731f..5b75a1eff7 100644
--- a/scripts/migrations/134-editorial-voice-consistency-stage.js
+++ b/scripts/migrations/134-editorial-voice-consistency-stage.js
@@ -10,66 +10,6 @@
* first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-voice-consistency.md';
-const STAGE_KEY = 'pipeline-editorial-voice-consistency';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-voice-consistency prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-voice-consistency: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-voice-consistency: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-voice-consistency: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-voice-consistency stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-voice-consistency: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-voice-consistency stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-voice-consistency: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-voice-consistency', 'pipeline-editorial-voice-consistency.md');
diff --git a/scripts/migrations/135-editorial-fact-accuracy-stage.js b/scripts/migrations/135-editorial-fact-accuracy-stage.js
index 6db7a85494..2572b19630 100644
--- a/scripts/migrations/135-editorial-fact-accuracy-stage.js
+++ b/scripts/migrations/135-editorial-fact-accuracy-stage.js
@@ -10,66 +10,6 @@
* time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-fact-accuracy.md';
-const STAGE_KEY = 'pipeline-editorial-fact-accuracy';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-fact-accuracy prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-fact-accuracy: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-fact-accuracy: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-fact-accuracy: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-fact-accuracy stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-fact-accuracy: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-fact-accuracy stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-fact-accuracy: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-fact-accuracy', 'pipeline-editorial-fact-accuracy.md');
diff --git a/scripts/migrations/136-editorial-comic-prose-sync-stage.js b/scripts/migrations/136-editorial-comic-prose-sync-stage.js
index 93648e0a29..3fac7e7abd 100644
--- a/scripts/migrations/136-editorial-comic-prose-sync-stage.js
+++ b/scripts/migrations/136-editorial-comic-prose-sync-stage.js
@@ -10,66 +10,6 @@
* runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-comic-prose-sync.md';
-const STAGE_KEY = 'pipeline-editorial-comic-prose-sync';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-comic-prose-sync prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-comic-prose-sync: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-comic-prose-sync: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-comic-prose-sync: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-comic-prose-sync stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-comic-prose-sync: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-comic-prose-sync stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-comic-prose-sync: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-comic-prose-sync', 'pipeline-editorial-comic-prose-sync.md');
diff --git a/scripts/migrations/140-editorial-pacing-escalation-stage.js b/scripts/migrations/140-editorial-pacing-escalation-stage.js
index 897b86a266..cc4f96d9b9 100644
--- a/scripts/migrations/140-editorial-pacing-escalation-stage.js
+++ b/scripts/migrations/140-editorial-pacing-escalation-stage.js
@@ -11,66 +11,6 @@
* "Stage not found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-pacing-escalation-curve.md';
-const STAGE_KEY = 'pipeline-editorial-pacing-escalation-curve';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-pacing-escalation-curve prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-pacing-escalation-curve: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-pacing-escalation-curve: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-pacing-escalation-curve: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-pacing-escalation-curve stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-pacing-escalation-curve: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-pacing-escalation-curve stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-pacing-escalation-curve: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-pacing-escalation-curve', 'pipeline-editorial-pacing-escalation-curve.md');
diff --git a/scripts/migrations/141-editorial-arc-regression-stage.js b/scripts/migrations/141-editorial-arc-regression-stage.js
index d86baacb52..d31e9f2ea9 100644
--- a/scripts/migrations/141-editorial-arc-regression-stage.js
+++ b/scripts/migrations/141-editorial-arc-regression-stage.js
@@ -11,66 +11,6 @@
* found" the first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-arc-regression.md';
-const STAGE_KEY = 'pipeline-editorial-arc-regression';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-arc-regression prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-arc-regression: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-arc-regression: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-arc-regression: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-arc-regression stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-arc-regression: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-arc-regression stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-arc-regression: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-arc-regression', 'pipeline-editorial-arc-regression.md');
diff --git a/scripts/migrations/150-seed-comic-page-refine-render-stage.js b/scripts/migrations/150-seed-comic-page-refine-render-stage.js
index c9f92649ed..8aff0a0d6b 100644
--- a/scripts/migrations/150-seed-comic-page-refine-render-stage.js
+++ b/scripts/migrations/150-seed-comic-page-refine-render-stage.js
@@ -21,68 +21,6 @@
* sweep can auto-update other installs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-comic-page-refine-render.md';
-const STAGE_KEY = 'pipeline-comic-page-refine-render';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- // 1) Seed the `.md` template when missing.
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 comic-page refine stage: ${FILENAME} already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ comic-page refine stage: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ comic-page refine stage: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- // 2) Merge the stage-config entry when absent.
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ comic-page refine stage: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
-
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 comic-page refine stage-config: ${STAGE_KEY} already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ comic-page refine stage: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 comic-page refine stage-config (${action}): ${STAGE_KEY} added`);
- } catch (err) {
- console.warn(`⚠️ comic-page refine stage: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-comic-page-refine-render', 'pipeline-comic-page-refine-render.md', { logPrefix: 'comic-page refine stage' });
diff --git a/scripts/migrations/151-editorial-head-hopping-stage.js b/scripts/migrations/151-editorial-head-hopping-stage.js
index e8203f175b..e7bc6f597a 100644
--- a/scripts/migrations/151-editorial-head-hopping-stage.js
+++ b/scripts/migrations/151-editorial-head-hopping-stage.js
@@ -10,66 +10,6 @@
* first time it runs.
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
-import { dirname, join } from 'path';
+import { makeSeedMigration } from './_seedStageHelpers.js';
-const FILENAME = 'pipeline-editorial-head-hopping.md';
-const STAGE_KEY = 'pipeline-editorial-head-hopping';
-
-export default {
- async up({ rootDir }) {
- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
- await mkdir(stagesDir, { recursive: true });
-
- const dataPath = join(stagesDir, FILENAME);
- const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', FILENAME);
-
- const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
- if (exists) {
- console.log(`📝 pipeline-editorial-head-hopping prompt: already present`);
- } else {
- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
- if (!sampleExists) {
- console.warn(`⚠️ pipeline-editorial-head-hopping: sample missing for ${FILENAME} — skipping copy`);
- } else {
- try {
- await copyFile(samplePath, dataPath);
- console.log(`✅ seeded ${FILENAME}`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-head-hopping: copy failed for ${FILENAME}: ${err.message}`);
- }
- }
- }
-
- const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
- const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
- const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
- if (!sampleConfigExists) {
- console.warn('⚠️ pipeline-editorial-head-hopping: data.reference stage-config.json missing — cannot resolve entry; skipping config write');
- return;
- }
- try {
- const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
- const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
- const installed = installedExists
- ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
- : { stages: {} };
- installed.stages = installed.stages || {};
- if (installed.stages[STAGE_KEY]) {
- console.log(`📝 pipeline-editorial-head-hopping stage-config: already present`);
- return;
- }
- if (!sample?.stages?.[STAGE_KEY]) {
- console.warn(`⚠️ pipeline-editorial-head-hopping: sample stage-config missing ${STAGE_KEY} — skipping`);
- return;
- }
- installed.stages[STAGE_KEY] = sample.stages[STAGE_KEY];
- await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
- const action = installedExists ? 'merged' : 'created';
- console.log(`📝 pipeline-editorial-head-hopping stage-config (${action}): 1 added`);
- } catch (err) {
- console.warn(`⚠️ pipeline-editorial-head-hopping: stage-config merge failed: ${err.message}`);
- }
- },
-};
+export default makeSeedMigration('pipeline-editorial-head-hopping', 'pipeline-editorial-head-hopping.md');
diff --git a/scripts/migrations/_seedStageHelpers.js b/scripts/migrations/_seedStageHelpers.js
new file mode 100644
index 0000000000..32f3892f22
--- /dev/null
+++ b/scripts/migrations/_seedStageHelpers.js
@@ -0,0 +1,96 @@
+/**
+ * Shared scaffolding for first-shipment "seed a pipeline stage" migrations (#1838).
+ *
+ * Companion to `./_lib.js` (hash-driven prompt-*replace*) — this one covers the
+ * *seed-a-brand-new-stage* family: ~40 near-identical migrations (e.g.
+ * `130-editorial-character-consistency-stage.js`) that each
+ * 1) copy a `.md` template from `data.reference/prompts/stages/` into
+ * `data/prompts/stages/` when missing (never clobbering a customized file), and
+ * 2) merge the matching `stage-config.json` entry into the installed config
+ * when absent (never clobbering an existing entry).
+ *
+ * Boot runs migrations (`server/index.js`) but NOT `setup-data.js`, so an upgrade
+ * that pulls + `pm2 restart`s (rather than running `update.sh`) would otherwise
+ * leave a newly-shipped stage unseeded and the dependent check would throw
+ * "Stage not found" the first time it runs.
+ *
+ * `makeSeedMigration(stageKey, filename, { logPrefix })` returns the
+ * `{ up }` object every such migration exports as its default. The runner
+ * (`scripts/run-migrations.js`) only ever calls `up()` and tracks applied
+ * migrations by filename — there is no rollback path, so no `down()` is
+ * emitted (it would be never-invoked dead code; see the `down` note in #1838).
+ *
+ * The runner skips `_`-prefixed files, so this module is never imported as a
+ * migration. `logPrefix` defaults to `stageKey` (what most files already log);
+ * the handful that logged a shortened label pass it explicitly to keep their
+ * console output byte-identical.
+ */
+
+import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
+import { dirname, join } from 'path';
+
+/**
+ * @param {string} stageKey - stage-config key, e.g. `pipeline-editorial-character-consistency`
+ * @param {string} filename - template basename under `prompts/stages/`, e.g. `${stageKey}.md`
+ * @param {{ logPrefix?: string }} [opts] - log label (defaults to `stageKey`)
+ * @returns {{ up: (ctx: { rootDir: string }) => Promise<void> }}
+ */
+export function makeSeedMigration(stageKey, filename, { logPrefix = stageKey } = {}) {
+ return {
+ async up({ rootDir }) {
+ const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
+ await mkdir(stagesDir, { recursive: true });
+
+ const dataPath = join(stagesDir, filename);
+ const samplePath = join(rootDir, 'data.reference', 'prompts', 'stages', filename);
+
+ const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);
+ if (exists) {
+ console.log(`📝 ${logPrefix} prompt: already present`);
+ } else {
+ const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
+ if (!sampleExists) {
+ console.warn(`⚠️ ${logPrefix}: sample missing for ${filename} — skipping copy`);
+ } else {
+ try {
+ await copyFile(samplePath, dataPath);
+ console.log(`✅ seeded ${filename}`);
+ } catch (err) {
+ console.warn(`⚠️ ${logPrefix}: copy failed for ${filename}: ${err.message}`);
+ }
+ }
+ }
+
+ const installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
+ const sampleConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');
+ const sampleConfigExists = await access(sampleConfigPath, constants.F_OK).then(() => true, () => false);
+ if (!sampleConfigExists) {
+ console.warn(`⚠️ ${logPrefix}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);
+ return;
+ }
+ try {
+ const sample = JSON.parse(await readFile(sampleConfigPath, 'utf8'));
+ const installedExists = await access(installedConfigPath, constants.F_OK).then(() => true, () => false);
+ const installed = installedExists
+ ? JSON.parse(await readFile(installedConfigPath, 'utf8'))
+ : { stages: {} };
+ installed.stages = installed.stages || {};
+ if (installed.stages[stageKey]) {
+ console.log(`📝 ${logPrefix} stage-config: already present`);
+ return;
+ }
+ if (!sample?.stages?.[stageKey]) {
+ console.warn(`⚠️ ${logPrefix}: sample stage-config missing ${stageKey} — skipping`);
+ return;
+ }
+ installed.stages[stageKey] = sample.stages[stageKey];
+ await mkdir(dirname(installedConfigPath), { recursive: true });
+ await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
+ const action = installedExists ? 'merged' : 'created';
+ console.log(`📝 ${logPrefix} stage-config (${action}): 1 added`);
+ } catch (err) {
+ console.warn(`⚠️ ${logPrefix}: stage-config merge failed: ${err.message}`);
+ }
+ },
+ };
+}
diff --git a/scripts/migrations/_seedStageHelpers.test.js b/scripts/migrations/_seedStageHelpers.test.js
new file mode 100644
index 0000000000..e738c924b2
--- /dev/null
+++ b/scripts/migrations/_seedStageHelpers.test.js
@@ -0,0 +1,107 @@
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
+import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import { makeSeedMigration } from './_seedStageHelpers.js';
+
+const STAGE_KEY = 'pipeline-test-seed-stage';
+const FILENAME = 'pipeline-test-seed-stage.md';
+const BODY = '# Test seed stage\n\nshipped body\n';
+
+describe('makeSeedMigration', () => {
+ let rootDir;
+ let stagesDir;
+ let refStagesDir;
+ let installedConfigPath;
+
+ const seedReference = ({ withConfig = true } = {}) => {
+ writeFileSync(join(refStagesDir, FILENAME), BODY);
+ if (withConfig) {
+ writeFileSync(
+ join(rootDir, 'data.reference', 'prompts', 'stage-config.json'),
+ JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, model: 'default', returnsJson: true, variables: [] } } }, null, 2) + '\n',
+ );
+ }
+ };
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'seed-stage-helper-'));
+ stagesDir = join(rootDir, 'data', 'prompts', 'stages');
+ refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');
+ installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
+ mkdirSync(stagesDir, { recursive: true });
+ mkdirSync(refStagesDir, { recursive: true });
+ });
+
+ afterEach(() => {
+ rmSync(rootDir, { recursive: true, force: true });
+ vi.restoreAllMocks();
+ });
+
+ it('returns an object exposing only an async up() (no down — runner has no rollback)', () => {
+ const migration = makeSeedMigration(STAGE_KEY, FILENAME);
+ expect(typeof migration.up).toBe('function');
+ expect(migration.down).toBeUndefined();
+ });
+
+ it('seeds the .md template and merges the stage-config entry on a fresh install', async () => {
+ seedReference();
+ const migration = makeSeedMigration(STAGE_KEY, FILENAME);
+ await expect(migration.up({ rootDir })).resolves.not.toThrow();
+ expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);
+ const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));
+ expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });
+ });
+
+ it('is idempotent and never clobbers a customized .md or an existing stage-config entry', async () => {
+ seedReference();
+ const customBody = '# CUSTOMIZED — do not overwrite\n';
+ writeFileSync(join(stagesDir, FILENAME), customBody);
+ writeFileSync(
+ installedConfigPath,
+ JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',
+ );
+
+ await makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir });
+
+ expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);
+ const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));
+ expect(installed.stages[STAGE_KEY]).toEqual({ name: 'user-tuned', model: 'custom' });
+ });
+
+ it('merges into an existing config without disturbing other stages', async () => {
+ seedReference();
+ writeFileSync(
+ installedConfigPath,
+ JSON.stringify({ stages: { 'pipeline-other': { name: 'other' } } }, null, 2) + '\n',
+ );
+
+ await makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir });
+
+ const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));
+ expect(installed.stages['pipeline-other']).toEqual({ name: 'other' });
+ expect(installed.stages[STAGE_KEY]).toMatchObject({ returnsJson: true });
+ });
+
+ it('does not throw and seeds nothing when the data.reference samples are missing', async () => {
+ await expect(makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir })).resolves.not.toThrow();
+ expect(existsSync(join(stagesDir, FILENAME))).toBe(false);
+ expect(existsSync(installedConfigPath)).toBe(false);
+ });
+
+ it('copies the .md but skips config when only the stage-config sample is missing', async () => {
+ seedReference({ withConfig: false });
+ await makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir });
+ expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);
+ expect(existsSync(installedConfigPath)).toBe(false);
+ });
+
+ it('uses logPrefix in console output when provided, else the stageKey', async () => {
+ seedReference();
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ await makeSeedMigration(STAGE_KEY, FILENAME, { logPrefix: 'short-label' }).up({ rootDir });
+ expect(logSpy.mock.calls.some(([msg]) => String(msg).includes('short-label stage-config'))).toBe(true);
+ expect(logSpy.mock.calls.some(([msg]) => String(msg).includes(`${STAGE_KEY} stage-config`))).toBe(false);
+ });
+});