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

importer: offer single-volume vs multi-volume split and populate the bible on commit

[._.]/ Adam Eivya864a5df80d8
diff --git a/client/src/pages/Importer.collapse.test.jsx b/client/src/pages/Importer.collapse.test.jsx
new file mode 100644
index 0000000000..98d2fe5039
--- /dev/null
+++ b/client/src/pages/Importer.collapse.test.jsx
@@ -0,0 +1,49 @@
+import { describe, it, expect } from 'vitest';
+import { collapseToSingleVolume } from './Importer.jsx';
+
+describe('collapseToSingleVolume', () => {
+ const seasonsPreview = [
+ { number: 1, title: 'The Miracle Man', logline: 'Beanstalk begins', synopsis: 'syn1' },
+ { number: 2, title: 'Magic Beans', logline: 'The climb', synopsis: 'syn2' },
+ { number: 3, title: 'Sins of the Fathers', logline: 'The fall', synopsis: 'syn3' },
+ { number: 4, title: 'The Curse Lifted', logline: 'The end', synopsis: 'syn4' },
+ ];
+ const issues = [
+ { title: 'Issue 1', arcPosition: 1, proseExcerpt: 'PAGE 1...' },
+ { title: 'Issue 2', arcPosition: 2, proseExcerpt: 'PAGE 23...' },
+ { title: 'Issue 3', arcPosition: 3, proseExcerpt: 'PAGE 45...' },
+ ];
+
+ it('produces exactly one volume sized to the issue count', () => {
+ const out = collapseToSingleVolume({ seasonsPreview, issues, seriesName: 'Giant', arc: { logline: 'LG', summary: 'SM' } });
+ expect(out.seasons).toHaveLength(1);
+ expect(out.seasons[0]).toMatchObject({ number: 1, title: 'Giant', logline: 'LG', synopsis: 'SM', episodeCountTarget: 3 });
+ });
+
+ it('pins every issue to volume 1 and zips the season descriptions into synopses', () => {
+ const out = collapseToSingleVolume({ seasonsPreview, issues, seriesName: 'Giant', arc: {} });
+ expect(out.issues).toHaveLength(3);
+ expect(out.issues.every((i) => i.seasonNumber === 1)).toBe(true);
+ // Extra 4th season (no matching issue) falls off — that's expected.
+ expect(out.issues[0].synopsis).toContain('Beanstalk begins');
+ expect(out.issues[0].synopsis).toContain('syn1');
+ expect(out.issues[2].synopsis).toContain('The fall');
+ });
+
+ it('keeps an issue synopsis the user already authored', () => {
+ const withSyn = [{ title: 'Issue 1', arcPosition: 1, synopsis: 'user wrote this' }];
+ const out = collapseToSingleVolume({ seasonsPreview, issues: withSyn, seriesName: 'Giant', arc: {} });
+ expect(out.issues[0].synopsis).toBe('user wrote this');
+ });
+
+ it('falls back to the first season title when there is no series name', () => {
+ const out = collapseToSingleVolume({ seasonsPreview, issues, seriesName: '', arc: {} });
+ expect(out.seasons[0].title).toBe('The Miracle Man');
+ });
+
+ it('clamps a long zipped synopsis to the 4000-char cap', () => {
+ const longSeason = [{ number: 1, title: 'X', logline: 'a'.repeat(3000), synopsis: 'b'.repeat(3000) }];
+ const out = collapseToSingleVolume({ seasonsPreview: longSeason, issues: [{ title: 'I1', arcPosition: 1 }], seriesName: 'S', arc: {} });
+ expect(out.issues[0].synopsis.length).toBe(4000);
+ });
+});
diff --git a/client/src/pages/Importer.jsx b/client/src/pages/Importer.jsx
index 16c8e2f166..e5f3cd66d8 100644
--- a/client/src/pages/Importer.jsx
+++ b/client/src/pages/Importer.jsx
@@ -43,6 +43,35 @@ const pickArcFields = (arc) => {
return out;
};
+// importerIssueEntry caps synopsis at 4000 chars (server schema) — clamp the
+// zipped season text so the structural remap can't 400 on commit.
+const IMPORT_ISSUE_SYNOPSIS_MAX = 4000;
+
+// Collapse the LLM's multi-season proposal into a SINGLE graphic-novel volume.
+// Every issue is pinned to volume 1; each season's logline/synopsis is folded
+// into the matching issue's synopsis (zipped by order) so the user's "the
+// volume descriptions read better as issue descriptions" intuition is the
+// default for a single book. Issues that already carry a synopsis keep it.
+export function collapseToSingleVolume({ seasonsPreview, issues, seriesName, arc }) {
+ const list = Array.isArray(issues) ? issues : [];
+ const seasons = [{
+ number: 1,
+ title: seriesName || seasonsPreview?.[0]?.title || 'Volume 1',
+ logline: arc?.logline || seasonsPreview?.[0]?.logline || '',
+ synopsis: arc?.summary || '',
+ episodeCountTarget: list.length,
+ }];
+ const mappedIssues = list.map((iss, i) => {
+ if (iss.synopsis && iss.synopsis.trim()) return { ...iss, seasonNumber: 1 };
+ const season = (seasonsPreview || [])[i];
+ const synopsis = season
+ ? [season.logline, season.synopsis].filter(Boolean).join('\n\n').slice(0, IMPORT_ISSUE_SYNOPSIS_MAX)
+ : (iss.synopsis || '');
+ return { ...iss, seasonNumber: 1, synopsis };
+ });
+ return { seasons, issues: mappedIssues };
+}
+
const emptyIntake = () => ({
universeName: '',
seriesName: '',
@@ -140,6 +169,10 @@ export default function Importer() {
const [arcDraft, setArcDraft] = useState(null);
const [seasonsDraft, setSeasonsDraft] = useState([]);
const [issuesDraft, setIssuesDraft] = useState([]);
+ // 'single' = one graphic-novel volume holding every issue as a chapter/act;
+ // 'multi' = keep the LLM's multi-season breakdown. Defaults to 'single' for
+ // comic scripts (a graphic novel is one book), 'multi' otherwise.
+ const [structureMode, setStructureMode] = useState('multi');
// Server already persisted universe+series+arc but the issue-loop rolled
// back. The next commit drops arc/seasons/canon so a retry can't overwrite
// server-side edits made between attempts.
@@ -208,9 +241,26 @@ export default function Importer() {
});
// Strip non-arc keys (e.g. the LLM's top-level `seasons`) at seed time
// — guards against the wire schema tightening to `.strict()`.
- setArcDraft(pickArcFields(result.arcPreview));
- setSeasonsDraft((result.seasonsPreview || []).map((s) => ({ ...s })));
- setIssuesDraft((result.issueProposals || []).map((i) => ({ ...i })));
+ const seededArc = pickArcFields(result.arcPreview);
+ setArcDraft(seededArc);
+ const initialIssues = (result.issueProposals || []).map((i) => ({ ...i }));
+ // Comic scripts default to a single graphic-novel volume; everything else
+ // keeps the LLM's multi-season proposal. The user can flip this in Review.
+ if (intake.contentType === 'comic-script') {
+ setStructureMode('single');
+ const collapsed = collapseToSingleVolume({
+ seasonsPreview: result.seasonsPreview || [],
+ issues: initialIssues,
+ seriesName: result.series?.name || intake.seriesName,
+ arc: seededArc,
+ });
+ setSeasonsDraft(collapsed.seasons);
+ setIssuesDraft(collapsed.issues);
+ } else {
+ setStructureMode('multi');
+ setSeasonsDraft((result.seasonsPreview || []).map((s) => ({ ...s })));
+ setIssuesDraft(initialIssues);
+ }
setIssueSplitFailed(Boolean(result.issueSplitFailed));
setIssueSplitError(result.issueSplitError || null);
setArcAlreadyPersisted(false);
@@ -225,6 +275,27 @@ export default function Importer() {
return result;
}, { errorMessage: 'Failed to analyze import' });
+ // Flip between single-volume (graphic novel) and multi-volume structure. A
+ // structural reset re-derives seasons + issues from the original proposal, so
+ // it intentionally discards per-issue title/synopsis edits.
+ const handleStructureMode = (mode) => {
+ setStructureMode(mode);
+ const baseIssues = (preview?.issueProposals || []).map((i) => ({ ...i }));
+ if (mode === 'single') {
+ const collapsed = collapseToSingleVolume({
+ seasonsPreview: preview?.seasonsPreview || [],
+ issues: baseIssues,
+ seriesName: preview?.series?.name || intake.seriesName,
+ arc: arcDraft,
+ });
+ setSeasonsDraft(collapsed.seasons);
+ setIssuesDraft(collapsed.issues);
+ } else {
+ setSeasonsDraft((preview?.seasonsPreview || []).map((s) => ({ ...s })));
+ setIssuesDraft(baseIssues);
+ }
+ };
+
const [runCommit, committing] = useAsyncAction(async () => {
if (!preview) return null;
// arcAlreadyPersisted retry: server kept arc/seasons/canon from the
@@ -361,6 +432,8 @@ export default function Importer() {
setIssuesDraft={setIssuesDraft}
arcRoles={config.arcRoles}
arcShapeIds={config.arcShapeIds}
+ structureMode={structureMode}
+ onStructureModeChange={handleStructureMode}
replaceMode={replaceMode}
setReplaceMode={setReplaceMode}
committing={committing}
@@ -606,12 +679,54 @@ function ImporterProgress({ stages }) {
);
}
+// Lets the user pick how the import is structured: one graphic-novel volume
+// holding every issue as a chapter/act, vs the LLM's multi-volume breakdown.
+// Switching is a structural reset (re-derives seasons + issues), so the copy
+// warns that per-issue edits are discarded.
+function StructureChooser({ mode, onChange, issueCount, seasonCount }) {
+ const opt = (value, title, desc) => {
+ const active = mode === value;
+ return (
+ <label
+ className={`flex-1 cursor-pointer rounded-lg border p-3 transition-colors ${
+ active ? 'border-port-accent bg-port-accent/10' : 'border-port-border bg-port-bg hover:border-port-accent/40'
+ }`}
+ >
+ <div className="flex items-center gap-2">
+ <input
+ type="radio"
+ name="import-structure"
+ checked={active}
+ onChange={() => onChange(value)}
+ className="accent-port-accent"
+ />
+ <span className="text-sm font-medium">{title}</span>
+ </div>
+ <p className="text-xs text-port-text-muted mt-1 ml-6">{desc}</p>
+ </label>
+ );
+ };
+ return (
+ <div className="bg-port-card border border-port-border rounded-lg p-4 space-y-2">
+ <div className="text-xs uppercase tracking-wider text-port-text-muted">Structure</div>
+ <div className="flex flex-col md:flex-row gap-2">
+ {opt('single', 'Single volume (graphic novel)',
+ `One volume holding all ${issueCount} issue${issueCount === 1 ? '' : 's'} as chapters/acts. The extracted volume descriptions become the issue synopses.`)}
+ {opt('multi', 'Multi-volume series',
+ `Keep the ${seasonCount || 'extracted'} volume${seasonCount === 1 ? '' : 's'} the LLM proposed as separate books.`)}
+ </div>
+ <p className="text-[11px] text-port-text-muted italic">Switching re-derives the structure below and discards per-issue title/synopsis edits.</p>
+ </div>
+ );
+}
+
function ReviewPanel({
preview, contentType, canonSelections,
selectedCanon, setSelectedCanon,
arcDraft, setArcDraft, seasonsDraft, setSeasonsDraft,
issuesDraft, setIssuesDraft,
arcRoles, arcShapeIds,
+ structureMode, onStructureModeChange,
replaceMode, setReplaceMode,
committing, onCommit, onBack,
issueSplitFailed, issueSplitError, onRetryIssues, retryingIssues,
@@ -690,6 +805,13 @@ function ReviewPanel({
onToggle={(idx) => toggleSelected('objects', idx)}
/>
+ <StructureChooser
+ mode={structureMode}
+ onChange={onStructureModeChange}
+ issueCount={issuesDraft.length}
+ seasonCount={(preview.seasonsPreview || []).length}
+ />
+
<ArcReviewSection arc={arcDraft} setArc={setArcDraft} seasons={seasonsDraft} setSeasons={setSeasonsDraft} arcShapeIds={arcShapeIds} />
{issueSplitFailed && (
diff --git a/server/services/importer.js b/server/services/importer.js
index 3e1f88ea55..0d28e2456d 100644
--- a/server/services/importer.js
+++ b/server/services/importer.js
@@ -1179,6 +1179,27 @@ export async function commitImport({
: universe;
const sanitizedArc = sanitizeArc(arc);
+
+ // Bible top-level fields the Arc Canvas sidebar reads. The importer used to
+ // write only series.arc + seasons, leaving logline/premise/issueCountTarget
+ // empty — so a freshly-imported series showed a blank bible. Fill them from
+ // the extracted arc + the count of issues being created. replaceMode
+ // overwrites (user-confirmed wipe); additive only fills fields the series
+ // doesn't already have, so a re-import never clobbers a hand-edited bible.
+ const issueCount = issuesWithPositions.length;
+ const arcLogline = sanitizedArc?.logline || '';
+ 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;
+ } else {
+ if (arcLogline && !(series.logline || '').trim()) biblePatch.logline = arcLogline;
+ if (arcPremise && !(series.premise || '').trim()) biblePatch.premise = arcPremise;
+ if (issueCount > 0 && !(series.issueCountTarget > 0)) biblePatch.issueCountTarget = issueCount;
+ }
+
let updatedSeries = series;
if (replaceMode) {
// null arc + empty seasons are user-confirmed clears in replace mode
@@ -1186,8 +1207,9 @@ export async function commitImport({
updatedSeries = await updateSeries(series.id, {
arc: sanitizedArc,
seasons: sanitizeSeasonList(seasons),
+ ...biblePatch,
});
- } else if (sanitizedArc || seasons.length > 0) {
+ } else if (sanitizedArc || seasons.length > 0 || Object.keys(biblePatch).length > 0) {
// Only build + persist a seasons array when the caller actually sent
// some — otherwise an arc-only re-import on a series that already has
// seasons rewrites the array byte-for-byte identical (just to bump
@@ -1201,6 +1223,7 @@ export async function commitImport({
updatedSeries = await updateSeries(series.id, {
...(sanitizedArc ? { arc: sanitizedArc } : {}),
...seasonsPatch,
+ ...biblePatch,
});
}