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
Merge remote-tracking branch 'origin/main' into next/issue-2179
Adam Eivy2a013f8c0876
diff --cc .changelog/NEXT.mdindex b3e3278263,422220312d..760a7aead5--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@@ -47,7 -48,7 +48,8 @@@## Creative Writing Quality Engine- - **[issue-2179] The Writers Room now anchors a freeform work's voice with the same exemplar/anti-exemplar passages ("the tuning fork") the series pipeline already uses.** Completing #2179's Writers Room parity: a work can now carry `voiceExemplars` (1–3 short passages that nail its target voice, each with an optional note on what it demonstrates) and `voiceAntiExemplars` (passages in the wrong register, noted with what's wrong — "too ornate", "wrong temperature"), edited in a new **Voice exemplars** drawer on the work editor. On generation those render into the SAME "MATCH this voice / NEVER drift toward this" blocks as the series style guide — via the shared `renderVoiceExemplars`/`sanitizeVoiceExemplars` helpers now exported from `server/lib/styleGuide.js` (one sanitizer, one set of caps, no drift between surfaces) — and are injected into the two prose-generation paths: the **live-continuation** prompt (`writers-room-continue.md`, gated by a conditional `{{#voiceGuide}}` block so a work with no passages carries zero per-call overhead) and the **Phase 9 polish loop**'s revision brief (folded into VOICE RULES so the rewrite is held to the chosen voice, not just told to "match the existing voice"). The editor UI is the shared `VoiceExemplarEditor` component (extracted from the series style-guide editor and reused by both). Zod parity on `writersRoomWorkUpdateSchema` (each passage capped at 2000 chars, list at 3; an explicit `[]` clears); the server sanitizer drops empty passages and re-sanitizes on read. `writers-room-continue.md` is a shipped template, so the block ships to existing installs via a standard hash-keyed migration (179) with migration 166 resynced and the drift baseline updated. (Final slice of #2179 — the earlier slices shipped the series exemplar fields, the AI voice-discovery flow, and the voice-fingerprint baseline hook.) (`server/lib/styleGuide.js`, `server/lib/pipelineValidation.js`, `server/services/writersRoom/local.js`, `server/services/writersRoom/liveDirector.js`, `server/services/writersRoom/polish.js`, `data.reference/prompts/stages/writers-room-continue.md`, `scripts/migrations/179-writers-room-voice-exemplars.js`, `client/src/components/VoiceExemplarEditor.jsx`, `client/src/components/writers-room/WorkEditor.jsx`)++- **[issue-2179] The Writers Room now anchors a freeform work's voice with the same exemplar/anti-exemplar passages ("the tuning fork") the series pipeline already uses.** Completing #2179's Writers Room parity: a work can now carry `voiceExemplars` (1–3 short passages that nail its target voice, each with an optional note on what it demonstrates) and `voiceAntiExemplars` (passages in the wrong register, noted with what's wrong — "too ornate", "wrong temperature"), edited in a new **Voice exemplars** drawer on the work editor. On generation those render into the SAME "MATCH this voice / NEVER drift toward this" blocks as the series style guide — via the shared `renderVoiceExemplars`/`sanitizeVoiceExemplars` helpers now exported from `server/lib/styleGuide.js` (one sanitizer, one set of caps, no drift between surfaces) — and are injected into the two prose-generation paths: the **live-continuation** prompt (`writers-room-continue.md`, gated by a conditional `{{#voiceGuide}}` block so a work with no passages carries zero per-call overhead) and the **Phase 9 polish loop**'s revision brief (folded into VOICE RULES so the rewrite is held to the chosen voice, not just told to "match the existing voice"). The editor UI is the shared `VoiceExemplarEditor` component (extracted from the series style-guide editor and reused by both). Zod parity on `writersRoomWorkUpdateSchema` (each passage capped at 2000 chars, list at 3; an explicit `[]` clears); the server sanitizer drops empty passages and re-sanitizes on read. `writers-room-continue.md` is a shipped template, so the block ships to existing installs via a standard hash-keyed migration (181) with migration 166 resynced and the drift baseline updated. (Final slice of #2179 — the earlier slices shipped the series exemplar fields, the AI voice-discovery flow, and the voice-fingerprint baseline hook.) (`server/lib/styleGuide.js`, `server/lib/pipelineValidation.js`, `server/services/writersRoom/local.js`, `server/services/writersRoom/liveDirector.js`, `server/services/writersRoom/polish.js`, `data.reference/prompts/stages/writers-room-continue.md`, `scripts/migrations/181-writers-room-voice-exemplars.js`, `client/src/components/VoiceExemplarEditor.jsx`, `client/src/components/writers-room/WorkEditor.jsx`)+ - **[issue-2180] Series invention now generates several distinct concepts under an anti-generic banlist, then user-picks (interactive) or judge-picks (autonomous) the winner — concept diversity at the seed is the cheapest quality lever in the pipeline.** Autonomous series invention used to produce ONE concept with no anti-generic pressure; autonovel's seed stage generates many concepts under an explicit banlist ("no chosen-one prophecies, no dark lords, no medieval-Europe-with-elves, no magic academies, no love triangles"), then selects. The `pipeline-series-generate` stage now invents **N genuinely distinct candidate concepts** (default 5, clamped 2–8), each carrying craft facets — HOOK / WORLD / CONFLICT ENGINE + COST / TENSION (personal AND larger-scale) / THEME (genre-neutral, not every series has magic) — under an **anti-generic banlist** that merges a shipped default list with the universe's own `influences.avoid` (case-insensitive dedupe, so an author's "steer clear of X" gets a hard veto at the seed). **Interactive mode** (the "Generate with AI" button on the New Series form) now presents the candidates for **user pick** — a deep-linkable card selection (`?concept=` is the URL source of truth) that pre-fills the form; the rejected candidates stay in memory (and in run history) so the user can switch without regenerating. **Autonomous mode** (CoS-driven invention) **judge-picks** the winner via a new one-call forced-rank stage `pipeline-series-concept-judge` ("which concept would a reader who has seen a thousand pitches stop scrolling for?" — ties forbidden), reusing the writer/judge split (#2167) resolved from the generation stage's `judgeProvider`/`judgeModel`; it **falls back to the first candidate** when no judge is configured or the call fails, so invention never blocks. Seed-faithful expansion is untouched — when the user typed their own idea it's still expanded, never replaced with a "better" concept. Runs ONLY from an explicit user action or the already-consented autonomous path — never at boot (AI-provider policy). Candidate normalization, banlist merge, forced-rank parsing, and judge-pick fallback are unit-tested; the modified prompt ships a hash-keyed migration (customized prompts preserved + warned) and the new judge stage a seed migration. (`server/services/pipeline/seriesGenerate.js`, `data.reference/prompts/stages/pipeline-series-generate.md`, `data.reference/prompts/stages/pipeline-series-concept-judge.md`, `server/routes/pipeline/series.js`, `server/services/creative/tools/pipeline.js`, `scripts/migrations/179-series-multi-concept-ideation.js`, `scripts/migrations/180-series-concept-judge-stage.js`, `client/src/pages/Pipeline.jsx`, `client/src/services/apiPipeline.js`)- **[issue-2169] Two comparative-quality mechanisms build on the calibrated judge — a multi-candidate draft gate, and head-to-head Elo ranking of a series' issues.** Both compose the Phase 3 judge (#2167) to escape autonovel's "rubric trap" (absolute 1-10 scores collapse into a 2-point band; comparison forces the discrimination the judge can't avoid). **(1) Multi-candidate draft gate** — a new opt-in per-stage config (`draftAttempts` 1–3, default **1 = off**; optional `draftGateThreshold`, schema parity added to `stageConfigUpdateSchema`) makes `generateStage` generate → judge → re-roll a FRESH draft while the composite `qualityScore` is below the threshold, up to the attempt cap, and keep the best-scoring attempt. Every attempt persists (rejected drafts stay recoverable in run history) and a per-attempt scorecard lands on `stage.draftGate` (`{ winner, threshold, attempts:[{ runId, qualityScore, rejected }] }`) — never silently discarded. Only the judgeable stages (prose/comicScript/teleplay) gate; the single-shot path is byte-for-byte unchanged when off. When run from Series Autopilot each re-roll bills one cos action and stops re-rolling when the daily budget is spent (keeping the best so far); a manual regenerate is never cos-billed. Canon extraction runs once, on the winning draft. **(2) Head-to-head Elo ranking** — a new `comparativeRank.js` + forced-pick `pipeline-judge-compare.md` stage prompt ("you are not allowed to call it a tie" — quote the deciding passage) runs a Swiss-style tournament (~4 rounds, K=32 Elo) across the series' drafted issues, each side truncated to a comparable budget via `contextBudget.js`. The ranking + per-match records persist at `data/pipeline-comparative-rank/{seriesId}.json`, content-hash-pinned for staleness (reuses `computeSourceContentHash`), with the weakest-N slice as the revision-priority order Phase 7 consumes. A tie/hedge/garbage pick from the judge falls through to a deterministic, balanced tiebreak. Surfaced as a new **Rankings** tab on the Reader Map page (`?tab=rank`) — an Elo table with the weakest issues flagged as revision priorities. Runs ONLY from the explicit "Rank issues" action or an autopilot step — never at boot (AI-provider policy). Pure Elo math + Swiss pairing + tie-refusal parsing + staleness are unit-tested. (`server/services/pipeline/editorial/comparativeRank.js`, `server/services/pipeline/textStages.js`, `server/services/pipeline/issues.js`, `server/services/pipeline/seriesAutopilot.js`, `server/lib/pipelineValidation.js`, `server/routes/pipeline/editorial.js`, `data.reference/prompts/stages/pipeline-judge-compare.md`, `client/src/components/pipeline/ComparativeRankView.jsx`, `client/src/pages/PipelineSeriesRoadmap.jsx`, `client/src/services/apiPipeline.js`)diff --cc scripts/migrations/166-craft-knowledge-prompt-upgrades.jsindex d6b388b61f,30e129380b..44961644af--- a/scripts/migrations/166-craft-knowledge-prompt-upgrades.js+++ b/scripts/migrations/166-craft-knowledge-prompt-upgrades.js@@@ -38,10 -38,7 +38,10 @@@ import { makePromptReplaceMigration } f// Pre-change shipped hashes (the current shipped bodies before #2172).export const ACCEPTED_OLD_MD5 = {'pipeline-prose.md': ['25e3d58c2741bd98acd5d08ba70d8a5e', '430d38ed2da59e0d4212e65edc499a74'],- 'writers-room-continue.md': ['93bfe80543ceca39842201a78b8393fa'],+ 'writers-room-continue.md': [+ '93bfe80543ceca39842201a78b8393fa',- '67663696c97ebaeb23de25f7410cfdd4', // post-166 / pre-179 (voice exemplars)++ '67663696c97ebaeb23de25f7410cfdd4', // post-166 / pre-181 (voice exemplars)+ ],'pipeline-arc-overview.md': ['0a1f6ffa6908522e3690c5e9e53a6ee0','612f8b04950e2ff26dd350dd76a062fe', // post-166 / pre-173 (MICE thread nesting)@@@ -53,7 -50,7 +53,7 @@@// continuity, #2177) per the drift-cross-sync convention.export const NEW_SHIPPED_MD5 = {'pipeline-prose.md': '4cb3ef48309f3673570cf80e4d544b54',- 'writers-room-continue.md': '458dc5ff4732befc1fb90890bdc885c2', // post-179 (voice exemplars)- 'writers-room-continue.md': '67663696c97ebaeb23de25f7410cfdd4',++ 'writers-room-continue.md': '458dc5ff4732befc1fb90890bdc885c2', // post-181 (voice exemplars)'pipeline-arc-overview.md': '74d6c26548660d85fc345b2099c63b6c', // post-173 (MICE thread nesting)};diff --cc scripts/migrations/181-writers-room-voice-exemplars.jsindex 7d3831c9f9,0000000000..bb526df179mode 100644,000000..100644--- a/scripts/migrations/181-writers-room-voice-exemplars.js+++ b/scripts/migrations/181-writers-room-voice-exemplars.js@@@ -1,58 -1,0 +1,58 @@@+/**+ * CWQE Phase 14 — Writers Room voice exemplars (#2179 parity slice).+ *+ * `writers-room-continue.md` gained a conditional "Voice (the tuning fork)"+ * block (`{{#voiceGuide}} … {{voiceGuide}} … {{/voiceGuide}}`) that injects a+ * work's voice exemplar / anti-exemplar passages into the live-continuation+ * prompt — the same "the tuning fork" anchoring the series style guide already+ * ships to prose/revision prompts. Absent exemplars render nothing (the section+ * is gated), so works without a configured voice carry no per-call overhead.+ *+ * `scripts/setup-data.js` only copies *missing* prompt files, so existing+ * installs keep their old `writers-room-continue.md` until this migration+ * rewrites it. The template already has a migration lineage (065 seed / 166+ * craft-anti-patterns) — per the drift-cross-sync convention, migration 166 is+ * resynced in this same change: its previous current hash+ * (`67663696…`) moved into its `ACCEPTED_OLD_MD5` and its `NEW_SHIPPED_MD5`- * bumped to the post-179 hash, so 166's "NEW matches live data.reference"++ * bumped to the post-181 hash, so 166's "NEW matches live data.reference"+ * drift-catch test stays green. The drift baseline in `setup-data-drift.test.js`+ * was updated to match the merged sweep.+ *+ * Customization-safe: only installs whose copy still hashes to the prior shipped+ * version are auto-updated; customized prompts are left intact and warned about.+ *+ * Strategy: hash-driven prompt-replace via `./_lib.js`. Idempotent.+ */++import { makePromptReplaceMigration } from './_lib.js';++// Pre-change shipped hash (the current shipped body before #2179 — post-166).+export const ACCEPTED_OLD_MD5 = {+ 'writers-room-continue.md': ['67663696c97ebaeb23de25f7410cfdd4'],+};++// Post-change shipped hash (voice-guide block added).+export const NEW_SHIPPED_MD5 = {+ 'writers-room-continue.md': '458dc5ff4732befc1fb90890bdc885c2',+};++const { applyMigration, up } = makePromptReplaceMigration({+ accepted: ACCEPTED_OLD_MD5,+ current: NEW_SHIPPED_MD5,+ label: 'writers-room voice exemplars',+ customizedHint: (filename) =>+ ` To upgrade it manually, diff:\n` ++ ` data.reference/prompts/stages/${filename}\n` ++ ` against your current:\n` ++ ` data/prompts/stages/${filename}\n` ++ ` and add the "Voice (the tuning fork)" block (the\n` ++ ` {{#voiceGuide}} / {{voiceGuide}} / {{/voiceGuide}} section).`,+ skipFooter: (count) =>+ `⚠️ ${count} live-continuation prompt(s) could not be auto-updated because\n` ++ ` they were customized. Live suggestions still work, but they will miss\n` ++ ` the work's voice exemplars (the tuning fork) until you merge the\n` ++ ` {{#voiceGuide}} block from data.reference/prompts/stages/writers-room-continue.md.`,+});++export { applyMigration };+export default { up };diff --cc scripts/migrations/181-writers-room-voice-exemplars.test.jsindex 3fa38314a4,0000000000..6324b600f3mode 100644,000000..100644--- a/scripts/migrations/181-writers-room-voice-exemplars.test.js+++ b/scripts/migrations/181-writers-room-voice-exemplars.test.js@@@ -1,14 -1,0 +1,14 @@@+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';- import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './179-writers-room-voice-exemplars.js';++import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './181-writers-room-voice-exemplars.js';+- describe('migration 179 — writers-room voice exemplars', () => {++describe('migration 181 — writers-room voice exemplars', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,- prefix: 'migration-179-',++ prefix: 'migration-181-',+ });+});