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

review: prose-only stage collection, per-field exportSettings merge, drop dead code (#2181)

Adam Eivy8ec008a33934
diff --git a/server/services/pipeline/proseExport.js b/server/services/pipeline/proseExport.js
index 8881a87a22..3d0faf29a2 100644
--- a/server/services/pipeline/proseExport.js
+++ b/server/services/pipeline/proseExport.js
@@ -37,8 +37,6 @@ import { collectManuscriptSections } from './arcPlanner.js';
export const ERR_NO_PROSE = 'PIPELINE_PROSE_EXPORT_NO_CONTENT';
const makeErr = (message, code) => Object.assign(new Error(message), { code });
-const nowUtc = () => new Date().toISOString().slice(0, 19).replace('T', ' ');
-
// ---------------------------------------------------------------------------
// Section gathering — the shared front for all three exports.
// ---------------------------------------------------------------------------
@@ -53,12 +51,15 @@ const nowUtc = () => new Date().toISOString().slice(0, 19).replace('T', ' ');
*/
export async function gatherProse(seriesId) {
const series = await getSeries(seriesId);
- // MANUSCRIPT_STAGES (the default) already excludes `idea` — so we never
- // export an outline as if it were finished prose.
- const sections = await collectManuscriptSections(seriesId);
+ // Prose export = the `prose` stage ONLY. The default stageOrder
+ // (MANUSCRIPT_STAGES) also picks up comicScript/teleplay, which would package
+ // non-prose text (screenplay/comic-script markup) into an ePub/manuscript; a
+ // prose series' authored artifact is its `prose` stage. `idea` is excluded
+ // either way (never export an outline as finished prose).
+ const sections = await collectManuscriptSections(seriesId, { stageOrder: ['prose'] });
if (!sections.length) {
throw makeErr(
- 'No drafted prose to export — write or import a manuscript on at least one issue first.',
+ 'No drafted prose to export — write or import prose on at least one issue first.',
ERR_NO_PROSE,
);
}
@@ -195,7 +196,7 @@ export function buildChapterXhtml(vol, { multiVolume }) {
}
// The OPF package document (EPUB 3): metadata + manifest + spine.
-export function buildOpf({ series, settings, volumes, coverImage, bookId }) {
+export function buildOpf({ settings, volumes, coverImage, bookId }) {
const items = [];
const spine = [];
items.push('<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>');
@@ -298,7 +299,7 @@ export async function buildEpub(seriesId) {
const entries = [
{ name: 'mimetype', data: 'application/epub+zip' },
{ name: 'META-INF/container.xml', data: CONTAINER_XML },
- { name: 'OEBPS/content.opf', data: buildOpf({ series, settings, volumes, coverImage, bookId }) },
+ { name: 'OEBPS/content.opf', data: buildOpf({ settings, volumes, coverImage, bookId }) },
{ name: 'OEBPS/nav.xhtml', data: buildNavXhtml({ settings, volumes }) },
{ name: 'OEBPS/style.css', data: EPUB_CSS },
...volumes.map((vol, idx) => ({ name: `OEBPS/vol${idx + 1}.xhtml`, data: buildChapterXhtml(vol, { multiVolume }) })),
diff --git a/server/services/pipeline/proseExport.test.js b/server/services/pipeline/proseExport.test.js
index 51a878b00f..35b226eba0 100644
--- a/server/services/pipeline/proseExport.test.js
+++ b/server/services/pipeline/proseExport.test.js
@@ -126,7 +126,6 @@ describe('buildChapterXhtml / buildNavXhtml / buildOpf', () => {
it('builds an OPF manifest + spine covering every volume and marks the cover', () => {
const opf = buildOpf({
- series: { id: 's1' },
settings: { titlePageTitle: 'T', titlePageAuthor: 'A', titlePageSubtitle: '' },
volumes: [vol, { ...vol, id: 'sB' }],
coverImage: { name: 'cover.png', mediaType: 'image/png' },
diff --git a/server/services/pipeline/series.js b/server/services/pipeline/series.js
index 1404073a69..b1c204a98a 100644
--- a/server/services/pipeline/series.js
+++ b/server/services/pipeline/series.js
@@ -584,6 +584,14 @@ export async function updateSeries(id, patch = {}) {
const mergedLlm = 'llm' in patch
? { ...(cur.llm || {}), ...(patch.llm || {}) }
: cur.llm;
+ // Per-field merge for exportSettings (#2181) so a partial PATCH ({ trimSize })
+ // tunes one knob without erasing the others — mirrors mergedLlm. An explicit
+ // `null` still clears the whole sub-object (defaults apply).
+ const mergedExportSettings = 'exportSettings' in patch
+ ? (patch.exportSettings === null
+ ? null
+ : { ...(cur.exportSettings || {}), ...(patch.exportSettings || {}) })
+ : cur.exportSettings;
const next = sanitizeSeries({
...cur,
...('name' in patch ? { name: patch.name } : {}),
@@ -607,10 +615,11 @@ export async function updateSeries(id, patch = {}) {
// Wholesale replace — sanitizeStyleGuide normalizes an empty object back
// to null (clear); omission preserves. Mirrors the arc/readerMap pattern.
...('styleGuide' in patch ? { styleGuide: patch.styleGuide } : {}),
- // Per-series prose-export settings (#2181). Wholesale replace —
- // `null`/`{}` clears (defaults apply); omission preserves.
+ // Per-series prose-export settings (#2181). Per-field merge (see
+ // mergedExportSettings above) — a partial PATCH tunes one knob; `null`
+ // clears (defaults apply); omission preserves.
// sanitizeProseExportSettings normalizes an all-default object back to null.
- ...('exportSettings' in patch ? { exportSettings: patch.exportSettings } : {}),
+ ...('exportSettings' in patch ? { exportSettings: mergedExportSettings } : {}),
...('titleLogo' in patch ? { titleLogo: patch.titleLogo } : {}),
...('author' in patch ? { author: patch.author } : {}),
...('authorId' in patch ? { authorId: patch.authorId } : {}),
diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.js
index 606a7cb226..cb7730a23a 100644
--- a/server/services/pipeline/series.test.js
+++ b/server/services/pipeline/series.test.js
@@ -138,6 +138,26 @@ describe('pipeline series service', () => {
expect(tuned.editorialCheckConfig).toEqual({ 'comic.lettering-density': { maxWordsPerBalloon: 18, x: true } });
});
+ it('defaults exportSettings to null and per-field-merges partial PATCHes (#2181)', async () => {
+ const plain = await svc.createSeries({ name: 'Prose Book' });
+ // Absent / all-default → null (no empty husk), like styleGuide.
+ expect(plain.exportSettings).toBeNull();
+
+ // Set two fields.
+ const set = await svc.updateSeries(plain.id, { exportSettings: { trimSize: 'digest', interiorFont: 'courier' } });
+ expect(set.exportSettings).toMatchObject({ trimSize: 'digest', interiorFont: 'courier' });
+
+ // Partial PATCH of ONE field must NOT erase the other (per-field merge).
+ const tuned = await svc.updateSeries(plain.id, { exportSettings: { titlePageTitle: 'My Title' } });
+ expect(tuned.exportSettings.trimSize).toBe('digest');
+ expect(tuned.exportSettings.interiorFont).toBe('courier');
+ expect(tuned.exportSettings.titlePageTitle).toBe('My Title');
+
+ // Explicit null clears the whole sub-object (defaults apply).
+ const cleared = await svc.updateSeries(plain.id, { exportSettings: null });
+ expect(cleared.exportSettings).toBeNull();
+ });
+
it('sanitizes editorialCheckConfig: drops empty/non-object overrides and non-primitive leaves (#1591)', async () => {
const s = await svc.createSeries({
name: 'Messy',