Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-708]): address review — seed prompt via migration + UI polish

[._.]/ Adam Eivy56a18ae454a4
diff --git a/client/src/components/digital-twin/tabs/VoiceStyleTab.jsx b/client/src/components/digital-twin/tabs/VoiceStyleTab.jsx
index 6f5883852f..b8e336e11d 100644
--- a/client/src/components/digital-twin/tabs/VoiceStyleTab.jsx
+++ b/client/src/components/digital-twin/tabs/VoiceStyleTab.jsx
@@ -97,7 +97,11 @@ export default function VoiceStyleTab({ onRefresh }) {
const res = await api.compareSpokenWrittenStyle(payload, { silent: true })
.catch((err) => ({ error: err.message }));
- if (res.error) {
+ if (res.error && res.rawResponse) {
+ // The model replied but its output couldn't be parsed — surface the
+ // unparseable-response notice inline instead of only a transient toast.
+ setResult(res);
+ } else if (res.error) {
toast.error(res.error);
} else {
setResult(res);
@@ -194,7 +198,7 @@ export default function VoiceStyleTab({ onRefresh }) {
<div className="flex justify-end">
<button
onClick={handleCompare}
- disabled={comparing || transcript.trim().length < MIN_TRANSCRIPT || !selectedProviderId}
+ disabled={comparing || transcript.trim().length < MIN_TRANSCRIPT || !selectedProviderId || !selectedModel}
className="flex items-center gap-2 px-6 py-3 min-h-[48px] bg-port-accent text-white rounded-lg font-medium hover:bg-port-accent/80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
{comparing ? (
diff --git a/scripts/migrations/069-twin-spoken-written-compare-prompt.js b/scripts/migrations/069-twin-spoken-written-compare-prompt.js
new file mode 100644
index 0000000000..608420698c
--- /dev/null
+++ b/scripts/migrations/069-twin-spoken-written-compare-prompt.js
@@ -0,0 +1,84 @@
+/**
+ * Seed the Digital Twin spoken-vs-written comparison prompt stage into existing
+ * installs (issue #708, M34 P5 — multi-modal personality capture).
+ *
+ * Single-stage sibling of the audio-cues prompt seed (migration 068): copies the
+ * `twin-spoken-written-compare.md` template from `data.reference/prompts/stages/`
+ * and merges its stage-config entry into `data/prompts/stage-config.json`. Boot
+ * runs migrations (server/index.js) but NOT `setup-data.js`, so an upgrade that
+ * pulls + `pm2 restart`s (rather than running the full setup) would otherwise
+ * leave the new stage unseeded and the first POST .../style/spoken-written call
+ * would throw "Stage not found".
+ *
+ * FIRST-SHIPMENT SEED ONLY — no MD5 hashing: it copies the template only when
+ * missing and never overwrites an install's existing prompt. A FUTURE migration
+ * that AMENDS this prompt must follow migration 003's hash-driven pattern
+ * (normalize line endings, ship OLD + NEW shipped hashes) instead.
+ */
+
+import { access, copyFile, mkdir, readFile, constants } from 'fs/promises';
+import { dirname, join } from 'path';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
+
+// The prompt file's basename doubles as its stage-config key (sans `.md`).
+const STAGE = 'twin-spoken-written-compare';
+
+export default {
+ async up({ rootDir }) {
+ const stagesDir = join(rootDir, 'data', 'prompts', 'stages');
+ await mkdir(stagesDir, { recursive: true });
+
+ // 1. Copy the prompt template if it's missing.
+ const filename = `${STAGE}.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(`📝 twin-style prompt: ${filename} already present`);
+ } else {
+ const sampleExists = await access(samplePath, constants.F_OK).then(() => true, () => false);
+ if (!sampleExists) {
+ console.warn(`⚠️ twin-style: sample missing for ${filename} — skipping copy`);
+ } else {
+ try {
+ await copyFile(samplePath, dataPath);
+ console.log(`✅ seeded ${filename}`);
+ } catch (err) {
+ console.warn(`⚠️ twin-style: copy failed for ${filename}: ${err.message}`);
+ }
+ }
+ }
+
+ // 2. Merge the stage-config entry if it's missing.
+ 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('⚠️ twin-style: 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 || {};
+ if (installed.stages[STAGE]) {
+ console.log(`📝 twin-style stage-config: ${STAGE} already present`);
+ return;
+ }
+ if (!sample?.stages?.[STAGE]) {
+ console.warn(`⚠️ twin-style: sample stage-config missing ${STAGE} — skipping`);
+ return;
+ }
+ installed.stages[STAGE] = sample.stages[STAGE];
+ await mkdir(dirname(installedConfigPath), { recursive: true });
+ await atomicWrite(installedConfigPath, `${JSON.stringify(installed, null, 2)}\n`);
+ const action = installedExists ? 'merged' : 'created';
+ console.log(`📝 twin-style stage-config (${action}): ${STAGE} added`);
+ } catch (err) {
+ console.warn(`⚠️ twin-style: stage-config merge failed: ${err.message}`);
+ }
+ },
+};
diff --git a/scripts/migrations/069-twin-spoken-written-compare-prompt.test.js b/scripts/migrations/069-twin-spoken-written-compare-prompt.test.js
new file mode 100644
index 0000000000..8a4318035a
--- /dev/null
+++ b/scripts/migrations/069-twin-spoken-written-compare-prompt.test.js
@@ -0,0 +1,58 @@
+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 './069-twin-spoken-written-compare-prompt.js';
+
+const STAGE = 'twin-spoken-written-compare';
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+describe('migration 069 — seed twin spoken-vs-written comparison prompt', () => {
+ let rootDir;
+ let installedStagesDir;
+ let installedConfigPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-069-'));
+ const refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');
+ mkdirSync(refStagesDir, { recursive: true });
+ writeFileSync(join(refStagesDir, `${STAGE}.md`), `# ${STAGE}\n\nbody\n`);
+ const refConfig = { stages: { [STAGE]: { name: STAGE, model: 'default', returnsJson: true, variables: [] } } };
+ writeFileSync(join(rootDir, 'data.reference', 'prompts', 'stage-config.json'), 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 });
+ expect(existsSync(join(installedStagesDir, `${STAGE}.md`))).toBe(true);
+ expect(readJson(installedConfigPath).stages[STAGE]).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();
+ expect(config.stages[STAGE]).toBeTruthy();
+ });
+
+ it('is idempotent and preserves a user-customized installed prompt', async () => {
+ mkdirSync(installedStagesDir, { recursive: true });
+ const customPath = join(installedStagesDir, `${STAGE}.md`);
+ writeFileSync(customPath, '# CUSTOM comparison prompt\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');
+ expect(readJson(installedConfigPath).stages[STAGE]).toBeTruthy();
+ });
+});