Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address self-review: derive filename, drop logPrefix, collapse 3 single-stage array migrations (#1838)
[._.]/ Adam Eivy9ab74602c7f6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 82ed5531db..fcf73bd8b0 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -26,7 +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)+- **Extracted a shared helper for the copy-paste stage-seed migrations** — 44 first-shipment "seed a new pipeline stage" migrations under `scripts/migrations/` (e.g. `130-editorial-character-consistency-stage.js`) were near-identical: only the stage key differed while ~65 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)` 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 migrations' on-disk effects exactly — fresh-seed, idempotent no-clobber of a customized `.md`/config, and missing-reference no-throw; `filename` defaults to `${stageKey}.md` (the universal convention, overridable for a divergent template), and no `down()` is emitted because the runner (`run-migrations.js`) only ever calls `up()` and tracks applied migrations by filename. Boot-log copy is incidental and now uniformly keyed on `stageKey`. Net −2,500 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.jsindex 932386505a..0e63be9ab4 100644--- a/scripts/migrations/017-volume-cover-concepts-stage.js+++ b/scripts/migrations/017-volume-cover-concepts-stage.js@@ -21,4 +21,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-volume-cover-concepts', 'pipeline-volume-cover-concepts.md', { logPrefix: 'volume-cover-concepts' });+export default makeSeedMigration('pipeline-volume-cover-concepts');diff --git a/scripts/migrations/020-comic-cover-concepts-stage.js b/scripts/migrations/020-comic-cover-concepts-stage.jsindex 3f4d42e4e4..58b30f33b2 100644--- a/scripts/migrations/020-comic-cover-concepts-stage.js+++ b/scripts/migrations/020-comic-cover-concepts-stage.js@@ -9,4 +9,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-comic-cover-concepts', 'pipeline-comic-cover-concepts.md', { logPrefix: 'comic-cover-concepts' });+export default makeSeedMigration('pipeline-comic-cover-concepts');diff --git a/scripts/migrations/041-editorial-analysis-stage.js b/scripts/migrations/041-editorial-analysis-stage.jsindex 47cf3b7045..3547c2bf34 100644--- a/scripts/migrations/041-editorial-analysis-stage.js+++ b/scripts/migrations/041-editorial-analysis-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-analysis', 'pipeline-editorial-analysis.md', { logPrefix: 'editorial-analysis' });+export default makeSeedMigration('pipeline-editorial-analysis');diff --git a/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.js b/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.jsindex 4845102310..fef1b3be38 100644--- a/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.js+++ b/scripts/migrations/048-catalog-ideas-scenes-concepts-stage.js@@ -13,75 +13,6 @@* concept candidates to review.*/-import { access, copyFile, mkdir, readFile, constants } from 'fs/promises';-import { dirname, join } from 'path';-import { atomicWrite } from '../../server/lib/fileUtils.js';+import { makeSeedMigration } from './_seedStageHelpers.js';-const STAGES = ['catalog-ideas-scenes-concepts'];--export default {- async up({ rootDir }) {- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');- await mkdir(stagesDir, { recursive: true });-- // 1. Copy any missing prompt templates.- for (const key of STAGES) {- const filename = `${key}.md`;- 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(`📝 catalog ingest prompt: ${filename} already present`);- continue;- }- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);- if (!sampleExists) {- console.warn(`⚠️ catalog ingest: sample missing for ${filename} — skipping copy`);- continue;- }- try {- await copyFile(samplePath, dataPath);- console.log(`✅ seeded ${filename}`);- } catch (err) {- console.warn(`⚠️ catalog ingest: copy failed for ${filename}: ${err.message}`);- }- }-- // 2. Merge missing stage-config entries.- 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('⚠️ catalog ingest: data.reference stage-config.json missing — 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 || {};- let added = 0;- for (const key of STAGES) {- if (installed.stages[key]) continue;- if (!sample?.stages?.[key]) {- console.warn(`⚠️ catalog ingest: sample stage-config missing ${key} — skipping`);- continue;- }- installed.stages[key] = sample.stages[key];- added += 1;- }- if (added === 0) {- console.log('📝 catalog ingest stage-config: all entries already present');- return;- }- await mkdir(dirname(installedConfigPath), { recursive: true });- await atomicWrite(installedConfigPath, `${JSON.stringify(installed, null, 2)}\n`);- const action = installedExists ? 'merged' : 'created';- console.log(`📝 catalog ingest stage-config (${action}): ${added} added`);- } catch (err) {- console.warn(`⚠️ catalog ingest: stage-config merge failed: ${err.message}`);- }- },-};+export default makeSeedMigration('catalog-ideas-scenes-concepts');diff --git a/scripts/migrations/087-manuscript-reformat-stage.js b/scripts/migrations/087-manuscript-reformat-stage.jsindex 39b5cd9add..b1406a1aba 100644--- a/scripts/migrations/087-manuscript-reformat-stage.js+++ b/scripts/migrations/087-manuscript-reformat-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('manuscript-reformat', 'manuscript-reformat.md');+export default makeSeedMigration('manuscript-reformat');diff --git a/scripts/migrations/088-series-generate-stage.js b/scripts/migrations/088-series-generate-stage.jsindex bfdbd896fc..751f622f73 100644--- a/scripts/migrations/088-series-generate-stage.js+++ b/scripts/migrations/088-series-generate-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-series-generate', 'pipeline-series-generate.md');+export default makeSeedMigration('pipeline-series-generate');diff --git a/scripts/migrations/089-canon-describe-from-prose-stage.js b/scripts/migrations/089-canon-describe-from-prose-stage.jsindex cb34da6c43..c18c422b1a 100644--- a/scripts/migrations/089-canon-describe-from-prose-stage.js+++ b/scripts/migrations/089-canon-describe-from-prose-stage.js@@ -17,4 +17,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-canon-describe-from-prose', 'pipeline-canon-describe-from-prose.md');+export default makeSeedMigration('pipeline-canon-describe-from-prose');diff --git a/scripts/migrations/090-script-verify-stage.js b/scripts/migrations/090-script-verify-stage.jsindex 90aaa6b92e..761bba08fb 100644--- a/scripts/migrations/090-script-verify-stage.js+++ b/scripts/migrations/090-script-verify-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-script-verify', 'pipeline-script-verify.md');+export default makeSeedMigration('pipeline-script-verify');diff --git a/scripts/migrations/092-editorial-info-dumping-stage.js b/scripts/migrations/092-editorial-info-dumping-stage.jsindex d6f147b9ab..1100b66341 100644--- a/scripts/migrations/092-editorial-info-dumping-stage.js+++ b/scripts/migrations/092-editorial-info-dumping-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-info-dumping', 'pipeline-editorial-info-dumping.md');+export default makeSeedMigration('pipeline-editorial-info-dumping');diff --git a/scripts/migrations/093-reverse-outline-stage.js b/scripts/migrations/093-reverse-outline-stage.jsindex 28a313ca2d..f26ccefe8c 100644--- a/scripts/migrations/093-reverse-outline-stage.js+++ b/scripts/migrations/093-reverse-outline-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-reverse-outline', 'pipeline-reverse-outline.md');+export default makeSeedMigration('pipeline-reverse-outline');diff --git a/scripts/migrations/096-editorial-style-conformance-stage.js b/scripts/migrations/096-editorial-style-conformance-stage.jsindex fdbb18167a..a4c9bea343 100644--- a/scripts/migrations/096-editorial-style-conformance-stage.js+++ b/scripts/migrations/096-editorial-style-conformance-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-style-conformance', 'pipeline-editorial-style-conformance.md');+export default makeSeedMigration('pipeline-editorial-style-conformance');diff --git a/scripts/migrations/097-continuity-bible-stage.js b/scripts/migrations/097-continuity-bible-stage.jsindex 080f598662..2d79ab378f 100644--- a/scripts/migrations/097-continuity-bible-stage.js+++ b/scripts/migrations/097-continuity-bible-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-continuity-bible', 'pipeline-continuity-bible.md');+export default makeSeedMigration('pipeline-continuity-bible');diff --git a/scripts/migrations/099-editorial-interiority-stage.js b/scripts/migrations/099-editorial-interiority-stage.jsindex 7eda8299fb..335b660c0e 100644--- a/scripts/migrations/099-editorial-interiority-stage.js+++ b/scripts/migrations/099-editorial-interiority-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-interiority', 'pipeline-editorial-interiority.md');+export default makeSeedMigration('pipeline-editorial-interiority');diff --git a/scripts/migrations/100-editorial-chekhov-stage.js b/scripts/migrations/100-editorial-chekhov-stage.jsindex 078c5604b2..ae4cbdbcb9 100644--- a/scripts/migrations/100-editorial-chekhov-stage.js+++ b/scripts/migrations/100-editorial-chekhov-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-chekhov', 'pipeline-editorial-chekhov.md');+export default makeSeedMigration('pipeline-editorial-chekhov');diff --git a/scripts/migrations/101-editorial-dead-metaphor-stage.js b/scripts/migrations/101-editorial-dead-metaphor-stage.jsindex 550bf301fe..833a5acd91 100644--- a/scripts/migrations/101-editorial-dead-metaphor-stage.js+++ b/scripts/migrations/101-editorial-dead-metaphor-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-dead-metaphor', 'pipeline-editorial-dead-metaphor.md');+export default makeSeedMigration('pipeline-editorial-dead-metaphor');diff --git a/scripts/migrations/102-editorial-endings-cliffhanger-stage.js b/scripts/migrations/102-editorial-endings-cliffhanger-stage.jsindex 466ef3612c..8820ac1570 100644--- a/scripts/migrations/102-editorial-endings-cliffhanger-stage.js+++ b/scripts/migrations/102-editorial-endings-cliffhanger-stage.js@@ -16,4 +16,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-endings-cliffhanger', 'pipeline-editorial-endings-cliffhanger.md');+export default makeSeedMigration('pipeline-editorial-endings-cliffhanger');diff --git a/scripts/migrations/103-editorial-opening-start-stage.js b/scripts/migrations/103-editorial-opening-start-stage.jsindex 08d327b4e1..57752cd272 100644--- a/scripts/migrations/103-editorial-opening-start-stage.js+++ b/scripts/migrations/103-editorial-opening-start-stage.js@@ -13,4 +13,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-opening-start', 'pipeline-editorial-opening-start.md');+export default makeSeedMigration('pipeline-editorial-opening-start');diff --git a/scripts/migrations/104-editorial-mirror-description-stage.js b/scripts/migrations/104-editorial-mirror-description-stage.jsindex 9c82170900..d055536dab 100644--- a/scripts/migrations/104-editorial-mirror-description-stage.js+++ b/scripts/migrations/104-editorial-mirror-description-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-mirror-description', 'pipeline-editorial-mirror-description.md');+export default makeSeedMigration('pipeline-editorial-mirror-description');diff --git a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.jsindex 48ec5bfef5..7ed695f52c 100644--- a/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js+++ b/scripts/migrations/105-editorial-dialogue-pleasantries-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-dialogue-pleasantries', 'pipeline-editorial-dialogue-pleasantries.md');+export default makeSeedMigration('pipeline-editorial-dialogue-pleasantries');diff --git a/scripts/migrations/106-editorial-kill-your-darlings-stage.js b/scripts/migrations/106-editorial-kill-your-darlings-stage.jsindex 9fc8273f44..426c524e21 100644--- a/scripts/migrations/106-editorial-kill-your-darlings-stage.js+++ b/scripts/migrations/106-editorial-kill-your-darlings-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-kill-your-darlings', 'pipeline-editorial-kill-your-darlings.md');+export default makeSeedMigration('pipeline-editorial-kill-your-darlings');diff --git a/scripts/migrations/109-editorial-arc-transitions-stage.js b/scripts/migrations/109-editorial-arc-transitions-stage.jsindex d85f338f1f..18f972fbf5 100644--- a/scripts/migrations/109-editorial-arc-transitions-stage.js+++ b/scripts/migrations/109-editorial-arc-transitions-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-arc-transitions', 'pipeline-editorial-arc-transitions.md');+export default makeSeedMigration('pipeline-editorial-arc-transitions');diff --git a/scripts/migrations/110-editorial-telling-emotion-stage.js b/scripts/migrations/110-editorial-telling-emotion-stage.jsindex bf0fbeff4d..6556f073a1 100644--- a/scripts/migrations/110-editorial-telling-emotion-stage.js+++ b/scripts/migrations/110-editorial-telling-emotion-stage.js@@ -14,4 +14,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-telling-emotion', 'pipeline-editorial-telling-emotion.md');+export default makeSeedMigration('pipeline-editorial-telling-emotion');diff --git a/scripts/migrations/111-editorial-plot-structure-stage.js b/scripts/migrations/111-editorial-plot-structure-stage.jsindex 0578d0715a..775b6d0c49 100644--- a/scripts/migrations/111-editorial-plot-structure-stage.js+++ b/scripts/migrations/111-editorial-plot-structure-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-plot-structure', 'pipeline-editorial-plot-structure.md');+export default makeSeedMigration('pipeline-editorial-plot-structure');diff --git a/scripts/migrations/112-editorial-on-the-nose-stage.js b/scripts/migrations/112-editorial-on-the-nose-stage.jsindex a1798bed5e..92daae6668 100644--- a/scripts/migrations/112-editorial-on-the-nose-stage.js+++ b/scripts/migrations/112-editorial-on-the-nose-stage.js@@ -13,4 +13,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-on-the-nose', 'pipeline-editorial-on-the-nose.md');+export default makeSeedMigration('pipeline-editorial-on-the-nose');diff --git a/scripts/migrations/113-editorial-voice-distinctiveness-stage.js b/scripts/migrations/113-editorial-voice-distinctiveness-stage.jsindex 1790b304f2..8c6a1da341 100644--- a/scripts/migrations/113-editorial-voice-distinctiveness-stage.js+++ b/scripts/migrations/113-editorial-voice-distinctiveness-stage.js@@ -13,4 +13,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-voice-distinctiveness', 'pipeline-editorial-voice-distinctiveness.md');+export default makeSeedMigration('pipeline-editorial-voice-distinctiveness');diff --git a/scripts/migrations/115-editorial-theme-coherence-stage.js b/scripts/migrations/115-editorial-theme-coherence-stage.jsindex 10792ed06a..55e2381859 100644--- a/scripts/migrations/115-editorial-theme-coherence-stage.js+++ b/scripts/migrations/115-editorial-theme-coherence-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-theme-coherence', 'pipeline-editorial-theme-coherence.md');+export default makeSeedMigration('pipeline-editorial-theme-coherence');diff --git a/scripts/migrations/116-editorial-unmodeled-names-stage.js b/scripts/migrations/116-editorial-unmodeled-names-stage.jsindex 9b19c6d4a3..a3a773f14e 100644--- a/scripts/migrations/116-editorial-unmodeled-names-stage.js+++ b/scripts/migrations/116-editorial-unmodeled-names-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-unmodeled-names', 'pipeline-editorial-unmodeled-names.md');+export default makeSeedMigration('pipeline-editorial-unmodeled-names');diff --git a/scripts/migrations/117-editorial-eyeline-match-stage.js b/scripts/migrations/117-editorial-eyeline-match-stage.jsindex a0857dbb8f..5c19ded63a 100644--- a/scripts/migrations/117-editorial-eyeline-match-stage.js+++ b/scripts/migrations/117-editorial-eyeline-match-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-eyeline-match', 'pipeline-editorial-eyeline-match.md');+export default makeSeedMigration('pipeline-editorial-eyeline-match');diff --git a/scripts/migrations/118-editorial-appearance-continuity-stage.js b/scripts/migrations/118-editorial-appearance-continuity-stage.jsindex 9f1dfdf31f..b6a5aeda1e 100644--- a/scripts/migrations/118-editorial-appearance-continuity-stage.js+++ b/scripts/migrations/118-editorial-appearance-continuity-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-appearance-continuity', 'pipeline-editorial-appearance-continuity.md');+export default makeSeedMigration('pipeline-editorial-appearance-continuity');diff --git a/scripts/migrations/119-editorial-comic-page-turn-stage.js b/scripts/migrations/119-editorial-comic-page-turn-stage.jsindex 0485842eec..ee3508e86d 100644--- a/scripts/migrations/119-editorial-comic-page-turn-stage.js+++ b/scripts/migrations/119-editorial-comic-page-turn-stage.js@@ -16,4 +16,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-comic-page-turn', 'pipeline-editorial-comic-page-turn.md');+export default makeSeedMigration('pipeline-editorial-comic-page-turn');diff --git a/scripts/migrations/129-editorial-timeline-contradiction-stage.js b/scripts/migrations/129-editorial-timeline-contradiction-stage.jsindex e21cab00b5..49ee490fda 100644--- a/scripts/migrations/129-editorial-timeline-contradiction-stage.js+++ b/scripts/migrations/129-editorial-timeline-contradiction-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-timeline-contradiction', 'pipeline-editorial-timeline-contradiction.md');+export default makeSeedMigration('pipeline-editorial-timeline-contradiction');diff --git a/scripts/migrations/130-editorial-character-consistency-stage.js b/scripts/migrations/130-editorial-character-consistency-stage.jsindex 58a01d3ff6..071c57ec7f 100644--- a/scripts/migrations/130-editorial-character-consistency-stage.js+++ b/scripts/migrations/130-editorial-character-consistency-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-character-consistency', 'pipeline-editorial-character-consistency.md');+export default makeSeedMigration('pipeline-editorial-character-consistency');diff --git a/scripts/migrations/131-editorial-climax-agency-stage.js b/scripts/migrations/131-editorial-climax-agency-stage.jsindex 573ed59af7..07373bf81a 100644--- a/scripts/migrations/131-editorial-climax-agency-stage.js+++ b/scripts/migrations/131-editorial-climax-agency-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-climax-agency', 'pipeline-editorial-climax-agency.md');+export default makeSeedMigration('pipeline-editorial-climax-agency');diff --git a/scripts/migrations/132-editorial-reaction-proportionality-stage.js b/scripts/migrations/132-editorial-reaction-proportionality-stage.jsindex 347d3aa847..860de115c6 100644--- a/scripts/migrations/132-editorial-reaction-proportionality-stage.js+++ b/scripts/migrations/132-editorial-reaction-proportionality-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-reaction-proportionality', 'pipeline-editorial-reaction-proportionality.md');+export default makeSeedMigration('pipeline-editorial-reaction-proportionality');diff --git a/scripts/migrations/133-editorial-secondary-arc-stage.js b/scripts/migrations/133-editorial-secondary-arc-stage.jsindex abbb660232..9b00ae9a73 100644--- a/scripts/migrations/133-editorial-secondary-arc-stage.js+++ b/scripts/migrations/133-editorial-secondary-arc-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-secondary-arc', 'pipeline-editorial-secondary-arc.md');+export default makeSeedMigration('pipeline-editorial-secondary-arc');diff --git a/scripts/migrations/134-editorial-voice-consistency-stage.js b/scripts/migrations/134-editorial-voice-consistency-stage.jsindex 5b75a1eff7..0574a3e993 100644--- a/scripts/migrations/134-editorial-voice-consistency-stage.js+++ b/scripts/migrations/134-editorial-voice-consistency-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-voice-consistency', 'pipeline-editorial-voice-consistency.md');+export default makeSeedMigration('pipeline-editorial-voice-consistency');diff --git a/scripts/migrations/135-editorial-fact-accuracy-stage.js b/scripts/migrations/135-editorial-fact-accuracy-stage.jsindex 2572b19630..098afa1f1e 100644--- a/scripts/migrations/135-editorial-fact-accuracy-stage.js+++ b/scripts/migrations/135-editorial-fact-accuracy-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-fact-accuracy', 'pipeline-editorial-fact-accuracy.md');+export default makeSeedMigration('pipeline-editorial-fact-accuracy');diff --git a/scripts/migrations/136-editorial-comic-prose-sync-stage.js b/scripts/migrations/136-editorial-comic-prose-sync-stage.jsindex 3fac7e7abd..14ca8af5d1 100644--- a/scripts/migrations/136-editorial-comic-prose-sync-stage.js+++ b/scripts/migrations/136-editorial-comic-prose-sync-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-comic-prose-sync', 'pipeline-editorial-comic-prose-sync.md');+export default makeSeedMigration('pipeline-editorial-comic-prose-sync');diff --git a/scripts/migrations/140-editorial-pacing-escalation-stage.js b/scripts/migrations/140-editorial-pacing-escalation-stage.jsindex cc4f96d9b9..5f37634ce0 100644--- a/scripts/migrations/140-editorial-pacing-escalation-stage.js+++ b/scripts/migrations/140-editorial-pacing-escalation-stage.js@@ -13,4 +13,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-pacing-escalation-curve', 'pipeline-editorial-pacing-escalation-curve.md');+export default makeSeedMigration('pipeline-editorial-pacing-escalation-curve');diff --git a/scripts/migrations/141-editorial-arc-regression-stage.js b/scripts/migrations/141-editorial-arc-regression-stage.jsindex d31e9f2ea9..8de6e4880d 100644--- a/scripts/migrations/141-editorial-arc-regression-stage.js+++ b/scripts/migrations/141-editorial-arc-regression-stage.js@@ -13,4 +13,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-arc-regression', 'pipeline-editorial-arc-regression.md');+export default makeSeedMigration('pipeline-editorial-arc-regression');diff --git a/scripts/migrations/142-editorial-interiority-balance-stage.js b/scripts/migrations/142-editorial-interiority-balance-stage.jsindex b7efda11e7..2317f3122c 100644--- a/scripts/migrations/142-editorial-interiority-balance-stage.js+++ b/scripts/migrations/142-editorial-interiority-balance-stage.js@@ -11,82 +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 STAGES = [- 'pipeline-editorial-interiority-balance',-];--export default {- async up({ rootDir }) {- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');- await mkdir(stagesDir, { recursive: true });-- // 1) Copy each prompt template if it isn't already present.- for (const stageKey of STAGES) {- const filename = `${stageKey}.md`;- 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(`📝 ${stageKey} prompt: already present`);- continue;- }- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);- if (!sampleExists) {- console.warn(`⚠️ ${stageKey}: sample missing for ${filename} — skipping copy`);- continue;- }- try {- await copyFile(samplePath, dataPath);- console.log(`✅ seeded ${filename}`);- } catch (err) {- console.warn(`⚠️ ${stageKey}: copy failed for ${filename}: ${err.message}`);- }- }-- // 2) Merge each stage-config entry (skip any already present).- 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('⚠️ 142-editorial-interiority-balance-stage: data.reference stage-config.json missing — cannot resolve entries; 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 || {};-- let added = 0;- for (const stageKey of STAGES) {- if (installed.stages[stageKey]) {- console.log(`📝 ${stageKey} stage-config: already present`);- continue;- }- if (!sample?.stages?.[stageKey]) {- console.warn(`⚠️ 142-editorial-interiority-balance-stage: sample stage-config missing ${stageKey} — skipping`);- continue;- }- installed.stages[stageKey] = sample.stages[stageKey];- added += 1;- }-- if (added === 0) {- console.log('📝 142-editorial-interiority-balance-stage: no stage-config entries to add');- return;- }- await mkdir(dirname(installedConfigPath), { recursive: true });- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');- const action = installedExists ? 'merged' : 'created';- console.log(`📝 142-editorial-interiority-balance-stage stage-config (${action}): ${added} added`);- } catch (err) {- console.warn(`⚠️ 142-editorial-interiority-balance-stage: stage-config merge failed: ${err.message}`);- }- },-};+export default makeSeedMigration('pipeline-editorial-interiority-balance');diff --git a/scripts/migrations/143-editorial-object-weight-proportionality-stage.js b/scripts/migrations/143-editorial-object-weight-proportionality-stage.jsindex 05adfb3dca..244ee01dd9 100644--- a/scripts/migrations/143-editorial-object-weight-proportionality-stage.js+++ b/scripts/migrations/143-editorial-object-weight-proportionality-stage.js@@ -11,82 +11,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 STAGES = [- 'pipeline-editorial-object-weight-proportionality',-];--export default {- async up({ rootDir }) {- const stagesDir = join(rootDir, 'data', 'prompts', 'stages');- await mkdir(stagesDir, { recursive: true });-- // 1) Copy each prompt template if it isn't already present.- for (const stageKey of STAGES) {- const filename = `${stageKey}.md`;- 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(`📝 ${stageKey} prompt: already present`);- continue;- }- const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);- if (!sampleExists) {- console.warn(`⚠️ ${stageKey}: sample missing for ${filename} — skipping copy`);- continue;- }- try {- await copyFile(samplePath, dataPath);- console.log(`✅ seeded ${filename}`);- } catch (err) {- console.warn(`⚠️ ${stageKey}: copy failed for ${filename}: ${err.message}`);- }- }-- // 2) Merge each stage-config entry (skip any already present).- 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('⚠️ 143-editorial-object-weight-proportionality-stage: data.reference stage-config.json missing — cannot resolve entries; 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 || {};-- let added = 0;- for (const stageKey of STAGES) {- if (installed.stages[stageKey]) {- console.log(`📝 ${stageKey} stage-config: already present`);- continue;- }- if (!sample?.stages?.[stageKey]) {- console.warn(`⚠️ 143-editorial-object-weight-proportionality-stage: sample stage-config missing ${stageKey} — skipping`);- continue;- }- installed.stages[stageKey] = sample.stages[stageKey];- added += 1;- }-- if (added === 0) {- console.log('📝 143-editorial-object-weight-proportionality-stage: no stage-config entries to add');- return;- }- await mkdir(dirname(installedConfigPath), { recursive: true });- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');- const action = installedExists ? 'merged' : 'created';- console.log(`📝 143-editorial-object-weight-proportionality-stage stage-config (${action}): ${added} added`);- } catch (err) {- console.warn(`⚠️ 143-editorial-object-weight-proportionality-stage: stage-config merge failed: ${err.message}`);- }- },-};+export default makeSeedMigration('pipeline-editorial-object-weight-proportionality');diff --git a/scripts/migrations/150-seed-comic-page-refine-render-stage.js b/scripts/migrations/150-seed-comic-page-refine-render-stage.jsindex 8aff0a0d6b..56ca1cad59 100644--- a/scripts/migrations/150-seed-comic-page-refine-render-stage.js+++ b/scripts/migrations/150-seed-comic-page-refine-render-stage.js@@ -23,4 +23,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-comic-page-refine-render', 'pipeline-comic-page-refine-render.md', { logPrefix: 'comic-page refine stage' });+export default makeSeedMigration('pipeline-comic-page-refine-render');diff --git a/scripts/migrations/151-editorial-head-hopping-stage.js b/scripts/migrations/151-editorial-head-hopping-stage.jsindex e7bc6f597a..01b1473c91 100644--- a/scripts/migrations/151-editorial-head-hopping-stage.js+++ b/scripts/migrations/151-editorial-head-hopping-stage.js@@ -12,4 +12,4 @@import { makeSeedMigration } from './_seedStageHelpers.js';-export default makeSeedMigration('pipeline-editorial-head-hopping', 'pipeline-editorial-head-hopping.md');+export default makeSeedMigration('pipeline-editorial-head-hopping');diff --git a/scripts/migrations/_seedStageHelpers.js b/scripts/migrations/_seedStageHelpers.jsindex 32f3892f22..8fd2dc13a4 100644--- a/scripts/migrations/_seedStageHelpers.js+++ b/scripts/migrations/_seedStageHelpers.js@@ -2,7 +2,7 @@* 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.+ * *seed-a-brand-new-stage* family: ~44 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@@ -14,16 +14,18 @@* 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).- *+ * `makeSeedMigration(stageKey, { filename })` 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).* 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.+ * migration. `filename` defaults to `${stageKey}.md` (the universal convention+ * across every seed migration); pass it only for the rare template whose basename+ * diverges from its stage key.+ *+ * The data effects above are what these migrations are responsible for — the+ * console log copy is incidental and not preserved verbatim from the pre-refactor+ * files (all now log under `stageKey`).*/import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';@@ -31,11 +33,10 @@ 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`)+ * @param {{ filename?: string }} [opts] - template basename under `prompts/stages/` (defaults to `${stageKey}.md`)* @returns {{ up: (ctx: { rootDir: string }) => Promise<void> }}*/-export function makeSeedMigration(stageKey, filename, { logPrefix = stageKey } = {}) {+export function makeSeedMigration(stageKey, { filename = `${stageKey}.md` } = {}) {return {async up({ rootDir }) {const stagesDir = join(rootDir, 'data', 'prompts', 'stages');@@ -46,17 +47,17 @@ export function makeSeedMigration(stageKey, filename, { logPrefix = stageKey } =const exists = await access(dataPath, constants.F_OK).then(() => true, () => false);if (exists) {- console.log(`📝 ${logPrefix} prompt: already present`);+ console.log(`📝 ${stageKey} 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`);+ console.warn(`⚠️ ${stageKey}: 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}`);+ console.warn(`⚠️ ${stageKey}: copy failed for ${filename}: ${err.message}`);}}}@@ -65,7 +66,7 @@ export function makeSeedMigration(stageKey, filename, { logPrefix = stageKey } =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`);+ console.warn(`⚠️ ${stageKey}: data.reference stage-config.json missing — cannot resolve entry; skipping config write`);return;}try {@@ -76,20 +77,20 @@ export function makeSeedMigration(stageKey, filename, { logPrefix = stageKey } =: { stages: {} };installed.stages = installed.stages || {};if (installed.stages[stageKey]) {- console.log(`📝 ${logPrefix} stage-config: already present`);+ console.log(`📝 ${stageKey} stage-config: already present`);return;}if (!sample?.stages?.[stageKey]) {- console.warn(`⚠️ ${logPrefix}: sample stage-config missing ${stageKey} — skipping`);+ console.warn(`⚠️ ${stageKey}: 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`);+ console.log(`📝 ${stageKey} stage-config (${action}): 1 added`);} catch (err) {- console.warn(`⚠️ ${logPrefix}: stage-config merge failed: ${err.message}`);+ console.warn(`⚠️ ${stageKey}: stage-config merge failed: ${err.message}`);}},};diff --git a/scripts/migrations/_seedStageHelpers.test.js b/scripts/migrations/_seedStageHelpers.test.jsindex e738c924b2..1d95e74ab5 100644--- a/scripts/migrations/_seedStageHelpers.test.js+++ b/scripts/migrations/_seedStageHelpers.test.js@@ -40,14 +40,14 @@ describe('makeSeedMigration', () => {});it('returns an object exposing only an async up() (no down — runner has no rollback)', () => {- const migration = makeSeedMigration(STAGE_KEY, FILENAME);+ const migration = makeSeedMigration(STAGE_KEY);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);+ const migration = makeSeedMigration(STAGE_KEY);await expect(migration.up({ rootDir })).resolves.not.toThrow();expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));@@ -63,7 +63,7 @@ describe('makeSeedMigration', () => {JSON.stringify({ stages: { [STAGE_KEY]: { name: 'user-tuned', model: 'custom' } } }, null, 2) + '\n',);- await makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir });+ await makeSeedMigration(STAGE_KEY).up({ rootDir });expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(customBody);const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));@@ -77,7 +77,7 @@ describe('makeSeedMigration', () => {JSON.stringify({ stages: { 'pipeline-other': { name: 'other' } } }, null, 2) + '\n',);- await makeSeedMigration(STAGE_KEY, FILENAME).up({ rootDir });+ await makeSeedMigration(STAGE_KEY).up({ rootDir });const installed = JSON.parse(readFileSync(installedConfigPath, 'utf8'));expect(installed.stages['pipeline-other']).toEqual({ name: 'other' });@@ -85,23 +85,36 @@ describe('makeSeedMigration', () => {});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();+ await expect(makeSeedMigration(STAGE_KEY).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 });+ await makeSeedMigration(STAGE_KEY).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 () => {+ it('defaults filename to `${stageKey}.md` and logs under 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);+ // No filename passed — must derive `${STAGE_KEY}.md` (which is FILENAME here).+ await makeSeedMigration(STAGE_KEY).up({ rootDir });+ expect(readFileSync(join(stagesDir, FILENAME), 'utf8')).toBe(BODY);+ expect(logSpy.mock.calls.some(([msg]) => String(msg).includes(`${STAGE_KEY} stage-config`))).toBe(true);+ });++ it('honors an explicit filename override that diverges from the stageKey', async () => {+ const altFile = 'pipeline-test-seed-stage-alt.md';+ writeFileSync(join(refStagesDir, altFile), BODY);+ writeFileSync(+ join(rootDir, 'data.reference', 'prompts', 'stage-config.json'),+ JSON.stringify({ stages: { [STAGE_KEY]: { name: STAGE_KEY, returnsJson: true } } }, null, 2) + '\n',+ );+ await makeSeedMigration(STAGE_KEY, { filename: altFile }).up({ rootDir });+ expect(readFileSync(join(stagesDir, altFile), 'utf8')).toBe(BODY);+ expect(existsSync(join(stagesDir, FILENAME))).toBe(false);});});