Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: seed voice-discover stage via migration + drop redundant seen Set (#2179)
Adam Eivyd90619ae47d5
diff --git a/scripts/migrations/174-series-voice-discover-stage.js b/scripts/migrations/174-series-voice-discover-stage.jsnew file mode 100644index 0000000000..1787d997f0--- /dev/null+++ b/scripts/migrations/174-series-voice-discover-stage.js@@ -0,0 +1,20 @@+/**+ * Seed the `pipeline-series-voice-discover` prompt stage into existing installs+ * (#2179, CWQE Phase 14 — voice discovery).+ *+ * Mirrors 048-catalog-ideas-scenes-concepts-stage.js — copies the `.md`+ * template from `data.reference/prompts/stages/` and merges the stage-config+ * entry into `data/prompts/stage-config.json`. Boot runs migrations+ * (server/index.js) BEFORE the AI toolkit reads stage-config.json, but does NOT+ * run `setup-data.js`. Without this migration, an upgrade that pulls main and+ * `pm2 restart`s (rather than running `update.sh`) leaves the new stage+ * unregistered — the "Discover voice" action would throw "Stage+ * pipeline-series-voice-discover not found" the first time the user clicks it.+ *+ * Customization-safe + idempotent: the template is copied only when missing and+ * the config entry merged only when absent.+ */++import { makeSeedMigration } from './_seedStageHelpers.js';++export default makeSeedMigration('pipeline-series-voice-discover');diff --git a/scripts/migrations/174-series-voice-discover-stage.test.js b/scripts/migrations/174-series-voice-discover-stage.test.jsnew file mode 100644index 0000000000..a766a1567a--- /dev/null+++ b/scripts/migrations/174-series-voice-discover-stage.test.js@@ -0,0 +1,86 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';++import migration from './174-series-voice-discover-stage.js';++const STAGES = ['pipeline-series-voice-discover'];+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));++describe('migration 174 — seed series voice-discovery stage', () => {+ let rootDir;+ let installedStagesDir;+ let installedConfigPath;+ let refStagesDir;+ let refConfigPath;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-174-'));+ refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');+ refConfigPath = join(rootDir, 'data.reference', 'prompts', 'stage-config.json');+ mkdirSync(refStagesDir, { recursive: true });+ for (const key of STAGES) {+ writeFileSync(join(refStagesDir, `${key}.md`), `# ${key}\n\nbody for ${key}\n`);+ }+ const refConfig = { stages: {} };+ for (const key of STAGES) {+ refConfig.stages[key] = { name: key, model: 'default', returnsJson: true, variables: [] };+ }+ writeFileSync(refConfigPath, JSON.stringify(refConfig, null, 2) + '\n');++ installedStagesDir = join(rootDir, 'data', 'prompts', 'stages');+ installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');+ });++ afterEach(() => {+ rmSync(rootDir, { recursive: true, force: true });+ });++ it('seeds the prompt file + stage-config entry on a fresh install', async () => {+ await migration.up({ rootDir });+ for (const key of STAGES) {+ expect(existsSync(join(installedStagesDir, `${key}.md`))).toBe(true);+ }+ const config = readJson(installedConfigPath);+ for (const key of STAGES) {+ expect(config.stages[key]).toBeTruthy();+ }+ });++ it('merges into an existing stage-config without clobbering other stages', async () => {+ mkdirSync(installedStagesDir, { recursive: true });+ writeFileSync(installedConfigPath, JSON.stringify({ stages: { 'pipeline-prose': { name: 'Prose' } } }, null, 2) + '\n');+ await migration.up({ rootDir });+ const config = readJson(installedConfigPath);+ expect(config.stages['pipeline-prose']).toBeTruthy();+ for (const key of STAGES) {+ expect(config.stages[key]).toBeTruthy();+ }+ });++ it('is idempotent and preserves a user-customized installed prompt', async () => {+ mkdirSync(installedStagesDir, { recursive: true });+ const customPath = join(installedStagesDir, 'pipeline-series-voice-discover.md');+ writeFileSync(customPath, '# CUSTOM voice discovery\n');+ await migration.up({ rootDir });+ expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');+ // Second run is a clean no-op.+ await migration.up({ rootDir });+ expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');+ const config = readJson(installedConfigPath);+ expect(Object.keys(config.stages).filter((k) => STAGES.includes(k))).toHaveLength(1);+ });++ it('logs and skips when the data.reference template is missing (no crash)', async () => {+ rmSync(join(refStagesDir, 'pipeline-series-voice-discover.md'));+ await migration.up({ rootDir });+ expect(existsSync(join(installedStagesDir, 'pipeline-series-voice-discover.md'))).toBe(false);+ });++ it('logs and skips when the data.reference stage-config is missing (no crash)', async () => {+ rmSync(refConfigPath);+ await migration.up({ rootDir });+ expect(existsSync(join(installedStagesDir, 'pipeline-series-voice-discover.md'))).toBe(true);+ });+});diff --git a/server/services/pipeline/seriesVoiceDiscover.js b/server/services/pipeline/seriesVoiceDiscover.jsindex 15b62bdc25..7f5ffa06b4 100644--- a/server/services/pipeline/seriesVoiceDiscover.js+++ b/server/services/pipeline/seriesVoiceDiscover.js@@ -117,13 +117,12 @@ export async function discoverSeriesVoice(seriesId, options = {}) {});// Dedupe by register (a model that emits two `spare` passages should not// crowd out a missing one) and keep the canonical register order so the- // side-by-side UI is stable across runs.- const seen = new Set();+ // side-by-side UI is stable across runs. The Map itself is the seen-set —+ // keep the FIRST candidate for a register.const byRegister = new Map();for (const raw of content.candidates) {const cand = normalizeCandidate(raw);- if (!cand || seen.has(cand.register)) continue;- seen.add(cand.register);+ if (!cand || byRegister.has(cand.register)) continue;byRegister.set(cand.register, cand);}const candidates = VOICE_REGISTER_IDS