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

address review (codex): exclude outlines from the manuscript-completeness pass and clear stale bible fields on replace import

[._.]/ Adam Eivy97e12d8a8744
diff --git a/server/services/importer.js b/server/services/importer.js
index 0d28e2456d..6f18a51014 100644
--- a/server/services/importer.js
+++ b/server/services/importer.js
@@ -1191,9 +1191,13 @@ export async function commitImport({
const arcPremise = sanitizedArc?.summary || sanitizedArc?.protagonistArc || '';
const biblePatch = {};
if (replaceMode) {
- if (arcLogline) biblePatch.logline = arcLogline;
- if (arcPremise) biblePatch.premise = arcPremise;
- if (issueCount > 0) biblePatch.issueCountTarget = issueCount;
+ // Replace mode is a user-confirmed full overwrite — write the new arc's
+ // bible fields unconditionally, INCLUDING empty strings, so an import whose
+ // extracted arc lacks a logline/summary clears the prior work's bible
+ // rather than leaving stale text beside the freshly-replaced arc + seasons.
+ biblePatch.logline = arcLogline;
+ biblePatch.premise = arcPremise;
+ biblePatch.issueCountTarget = issueCount;
} else {
if (arcLogline && !(series.logline || '').trim()) biblePatch.logline = arcLogline;
if (arcPremise && !(series.premise || '').trim()) biblePatch.premise = arcPremise;
diff --git a/server/services/importer.test.js b/server/services/importer.test.js
index 8284f0cf77..67997e8c69 100644
--- a/server/services/importer.test.js
+++ b/server/services/importer.test.js
@@ -857,6 +857,11 @@ describe('commitImport', () => {
expect(result.series.arc.shape).toBe('man-in-hole');
expect(result.series.seasons).toHaveLength(1);
expect(result.series.seasons[0].title).toBe('Foundry');
+ // Bible top-level fields populated from the extracted arc + issue count
+ // (the sidebar used to stay blank after import).
+ expect(result.series.logline).toBe('A reluctant heir.');
+ expect(result.series.premise).toBe('Big story.');
+ expect(result.series.issueCountTarget).toBe(1);
// One issue created with prose + idea seeded.
expect(result.createdIssueIds).toHaveLength(1);
const issue = await issuesSvc.getIssue(result.createdIssueIds[0]);
@@ -903,6 +908,35 @@ describe('commitImport', () => {
expect(issue.stages.comicScript?.output).toBeFalsy();
});
+ it('replace mode overwrites the bible, clearing stale fields when the new arc lacks them', async () => {
+ const { uni, ser } = await setupForCommit();
+ // First (additive) import seeds a bible logline + premise.
+ await importerSvc.commitImport({
+ universeId: uni.id,
+ seriesId: ser.id,
+ canonSelections: { characters: [], places: [], objects: [] },
+ arc: { logline: 'Old logline', summary: 'Old premise' },
+ seasons: [],
+ issues: [{ title: 'I1', arcPosition: 1, proseExcerpt: 'p1' }],
+ });
+ expect((await seriesSvc.getSeries(ser.id)).logline).toBe('Old logline');
+
+ // Replace with an arc that has NO logline/summary — the bible must be
+ // cleared, not left showing the prior work's text beside a replaced arc.
+ const result = await importerSvc.commitImport({
+ universeId: uni.id,
+ seriesId: ser.id,
+ replaceMode: true,
+ canonSelections: { characters: [], places: [], objects: [] },
+ arc: { logline: '', summary: '', protagonistArc: '' },
+ seasons: [],
+ issues: [{ title: 'I2', arcPosition: 1, proseExcerpt: 'p2' }],
+ });
+ expect(result.series.logline).toBe('');
+ expect(result.series.premise).toBe('');
+ expect(result.series.issueCountTarget).toBe(1);
+ });
+
it('refuses to commit when the series arc is locked', async () => {
const { uni, ser } = await setupForCommit();
await seriesSvc.updateSeries(ser.id, { locked: { arc: true } });
diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.js
index 43eafec2bc..cd841f6378 100644
--- a/server/services/pipeline/arcPlanner.js
+++ b/server/services/pipeline/arcPlanner.js
@@ -165,22 +165,35 @@ const BACKFILL_SOURCE_MAX = 200_000;
// binding is undefined at module-eval time. The one-liner is stable.
const stageTextOf = (stage) => (stage?.input?.trim() || stage?.output?.trim() || '');
+// Default stage precedence: the richest authored artifact per issue. `idea`
+// (the outline/synopsis seed) is the lowest-priority fallback — it lets an
+// arc be back-derived from outlines alone. Callers that specifically mean
+// "the DRAFTED MANUSCRIPT" must pass MANUSCRIPT_STAGES to exclude it.
+const SOURCE_STAGE_ORDER = ['comicScript', 'teleplay', 'prose', 'idea'];
+export const MANUSCRIPT_STAGES = ['comicScript', 'teleplay', 'prose'];
+
/**
- * Concatenate the richest authored artifact per issue (comicScript → teleplay →
- * prose → idea) into one corpus an upstream pass can back-derive FROM — the
- * "started from a finished manuscript" case. Issues are ordered by arcPosition
- * so the corpus reads in story order. Returns '' when no issue has any text.
+ * Concatenate the richest authored artifact per issue into one corpus an
+ * upstream pass can back-derive FROM — the "started from a finished manuscript"
+ * case. Issues are ordered by arcPosition so the corpus reads in story order.
+ * Returns '' when no issue has text in any of `stageOrder`.
+ *
+ * `stageOrder` selects which stages count (and their precedence). The default
+ * includes `idea`, so an arc can be derived from outlines; pass
+ * `MANUSCRIPT_STAGES` to require actual drafted script (excludes `idea`) —
+ * that's what `analyzeManuscriptCompleteness` uses so it never grades an
+ * outline as if it were a finished manuscript.
*
* Shared by `deriveFromManuscript` here and the Story Builder's plotArc/idea
* backfill (storyBuilder.js) so both see the identical corpus shape.
*/
-export async function collectIssueSourceText(seriesId) {
+export async function collectIssueSourceText(seriesId, { stageOrder = SOURCE_STAGE_ORDER } = {}) {
if (!seriesId) return '';
const issues = (await listIssues({ seriesId }).catch(() => [])).sort(compareIssuesByPosition);
const parts = [];
for (const iss of issues) {
const st = iss.stages || {};
- const pick = ['comicScript', 'teleplay', 'prose', 'idea']
+ const pick = stageOrder
.map((sid) => ({ sid, content: stageTextOf(st[sid]) }))
.find((x) => x.content);
if (!pick) continue;
@@ -613,7 +626,9 @@ async function buildCompletenessContext(series, manuscript, preloadedWorld) {
*/
export async function analyzeManuscriptCompleteness(seriesId, options = {}) {
const series = await getSeries(seriesId);
- const manuscript = await collectIssueSourceText(seriesId);
+ // Manuscript-only: exclude `idea` so an outline/synopsis seed can't pass the
+ // guard below and get graded as if it were a drafted manuscript.
+ const manuscript = await collectIssueSourceText(seriesId, { stageOrder: MANUSCRIPT_STAGES });
if (!manuscript) {
throw makeErr(
'No manuscript to analyze — write a comic script, prose, or teleplay on at least one issue first',
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index 139ca1399c..b8bd8131e3 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -1533,6 +1533,13 @@ describe('arcPlanner — manuscript completeness + derive-from-manuscript', () =
await expect(planner.analyzeManuscriptCompleteness(s.id)).rejects.toMatchObject({ code: 'PIPELINE_ARC_VALIDATION' });
});
+ it('analyzeManuscriptCompleteness treats an idea-only issue as no manuscript (outline is not a draft)', async () => {
+ const s = await setupSeries();
+ // Only an idea/synopsis seed — no drafted comicScript/prose/teleplay.
+ await issuesSvc.createIssue({ seriesId: s.id, title: 'Outline only', arcPosition: 1, stages: { idea: { input: 'a synopsis', status: 'edited' } } });
+ await expect(planner.analyzeManuscriptCompleteness(s.id)).rejects.toMatchObject({ code: 'PIPELINE_ARC_VALIDATION' });
+ });
+
it('deriveFromManuscript proposes a single volume + bible + zipped issue synopses', async () => {
const s = await setupSeries();
const sea = await seasonsSvc.createSeason(s.id, { title: 'V1', episodeCountTarget: 3 });