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 split-choice + back-generate series arc/bible from manuscript + finish-the-draft editor feedback
Context
A comic script was imported (series ser-c22c6c9e-3a02-43be-bc38-6cd2de82bd27). Three problems surfaced, all rooted in how the importer treats a single graphic novel:
- 4 "volumes" but 3 issues, no user choice. The "volumes" are actually
series.seasons[], produced by theimporter-arc-extractLLM independently of the 3 issues the mechanicalsplitComicScriptIssues()produced. The two passes never reconcile, and neither surfaces a user choice. For a single graphic novel the right shape is 1 volume containing 3–4 issues-as-acts — the 4 season titles (Magic Beans, Sins of the Fathers, …) read as act/chapter descriptions, not separate volumes. - Empty bible. Commit only writes
series.arc+series.seasons. It never sets the top-levelseries.logline/series.premise/issueCountTargetthat the bible sidebar reads, so the bible shows only the name. The mechanical comic split also seedsstages.comicScript(the verbatim manuscript) but notstages.idea.input(synopsis) — so Verify Arc, which readsidea.input, sees empty synopses for these issues. - No way to back-derive arc/bible from an existing manuscript, and no "finish the draft" feedback.
generateArcFromSource()already back-derives arc+seasons from issue content (arcPlanner.js:306) but is only reachable from the Story Builder session flow — there's no route or series-page action. AndverifyArc/verifyVolumeare synopsis-level only (readidea.input/idea.output); they're blind to the actualcomicScriptmanuscript, so they cannot tell you "you're missing pages / the draft is 90% done — here's what to finish."
Outcome (user-confirmed decisions): all four workstreams in one plan; target structure is 1 volume, 3–4 issues as acts (no new data model — "issue" stays the unit, "volume"=season); a new manuscript-completeness editor action (leave Verify Arc/Volume as-is); the derive-from-manuscript action uses a preview-and-confirm flow like the importer review. Implementation runs in a fresh git worktree off main so it doesn't collide with another agent already working in this checkout.
Step 0 — Worktree (do this first, before any edits)
Create an isolated worktree off the latest main and do all work there:
git -C /Users/adameivy/github.com/atomantic/PortOS fetch origin
git -C /Users/adameivy/github.com/atomantic/PortOS worktree add -b feat/importer-derive-manuscript ../PortOS-derive origin/main
Run npm run install:all in the worktree (submodules + deps). All file paths below are relative to the worktree root. Commit/push only when the user asks.
Workstream 1 — Importer: split choice, arc + bible population
Goal: let the user choose single-volume-with-N-chapters vs N-volumes at import, reconcile seasons↔issues, and populate the bible on commit. Handle the volume strategy as a review-UI remap + commit field so we do NOT modify the importer-arc-extract.md prompt (avoids a prompt migration per the CLAUDE.md stage-prompt rule).
client/src/pages/Importer.jsx(ReviewPanel + commit path):- Add a Structure control to
ReviewPanel(nearArcReviewSection/IssuesReviewSection): radio "Single volume (graphic novel)" vs "Multi-volume series", plus a chapter/issue count. - When "Single volume" is chosen: collapse
seasonsDraftto one season (keep its title or default to the series name), and remap the extra extracted season titles/loglines into the issue/chapter drafts (issuesDraft) as titles/synopses — surfacing the user's "volume descriptions are better as issue descriptions" intuition automatically. Re-split issues to the chosen count using the existing even-distribution intent (mirrorsplitComicScriptIssues's page-bundling — see below). - On commit, send the reconciled
seasons+issues(existingcommitImportpayload already carries both).
- Add a Structure control to
server/services/importer.js(commitImport, ~line 1181–1205): after writingarc+seasons, also patch top-level bible fields when present and not locked:series.logline←arc.loglineseries.premise←arc.summary(fallbackarc.protagonistArc)series.issueCountTarget← number of issues being created- Use the existing
updateSeriespatch (it already supports these keys — seeseries.js:298–312). Guard each so a re-import never clobbers a non-empty/locked field (replaceModemay overwrite; additive preserves).
- Per-issue synopsis seed: in the commit issue-loop (
importer.js:1269–1281), when a comic-script issue has nologline/synopsis(mechanical split), still seedstages.idea.inputwith the season/chapter description mapped in the review step, so Verify Arc has synopsis material. Keepstages.comicScriptseeding unchanged. - Reconciliation guard: in
analyzeImport(importer.js:642), whencontentType==='comic-script'and the mechanical split produced N issues, default theseasonsPreviewthe client shows to a single season (graphic-novel default) while still returning the LLM's multi-season proposal as the alternative the "Multi-volume" radio reveals. This makes single-volume the sane default without discarding the arc-extract's act breakdown. - Validation:
importerCommitSchemaalready acceptsseasons(max 50) +issues; no schema change needed unless we add an explicitvolumeStrategyfield (optional — the remap can be done entirely client-side, so prefer no new field).
Workstream 2 — Reusable "Derive arc / bible / structure from manuscript" (series page, preview & confirm)
Goal: a series-page action that reads the existing issue manuscripts and proposes arc + bible + a 1-volume/issues-as-acts restructure, shown as a preview the user confirms before anything is written. Reuse the existing back-gen primitive.
- Service —
server/services/pipeline/arcPlanner.js:- Export a
collectIssueSourceText(seriesId)equivalent. One already exists inserver/services/storyBuilder.js:436(preferscomicScript → teleplay → prose → idea) but isn't exported — extract it into a shared spot (e.g.arcPlanner.jsor a smallserver/services/pipeline/helper, referenced from both) rather than duplicating. - Add
deriveFromManuscript(seriesId, { providerOverride, modelOverride })that: collects manuscript text, calls the existinggenerateArcFromSource()(arcPlanner.js:306) to get{ arc, seasons }, and also derives bible fields (logline,premise,issueCountTarget) + a proposed single-volume structure mapping each existing issue to one volume. Returns a preview object (no writes):{ arc, bible, volume, issueMapping, runId, providerId, model }. - Add
commitDerivedManuscript(seriesId, preview)that applies on confirm: write bible fields viaupdateSeries; replace seasons with the single volume viacommitSeasonsWithRemap(series, { arc, seasons })(honors per-field arc locks, per-season locks, and remaps/keeps child issues —arcPlanner.jsalready owns this); reassign every issue'sseasonIdto the retained volume; optionally backfill each issue'sidea.inputsynopsis. Per-episode issue scripts are never overwritten (same contract asresolveVerifyIssues).
- Export a
- Routes —
server/routes/pipeline.js(mirror the/arc/generatepreview+commit shape at:1062):POST /series/:id/arc/derive-from-manuscript→ returns preview; with{ commit: true }(or a separate confirm route) applies it.
- Validation —
server/lib/validation.js: addarcDeriveSchema(provider/model overrides + optionalcommit), wired into the route viavalidateRequest. - Client API —
client/src/services/apiPipeline.js: addderivePipelineArcFromManuscript(seriesId, opts)next togeneratePipelineArcOverview(:353). Re-export per the barrel/README maintenance rule. - Client UI —
client/src/components/pipeline/ArcCanvas.jsx: add a "Derive from manuscript" action near the arc header / Verify Arc, opening a preview panel (reuse the importer-review styling pattern: show proposed arc fields, bible, and the 1-volume/issues mapping with edit + Confirm/Cancel). On confirm, call the commit route and refresh series + issues via existing reactive-update patterns (setState, not full refetch where possible).
Workstream 3 — Repair THIS series
No one-off script needed — Workstream 2 is the repair tool. On the existing series:
- Run Derive from manuscript → preview proposes single volume + arc + bible from the 3 issues'
comicScriptcontent. - Confirm → collapses V1–V4 to one volume, reassigns the 3 issues, fills the bible.
- Delete the now-empty V2/V3/V4 if
commitSeasonsWithRemapleaves any (the existingdeletePipelineSeason(seriesId, seasonId, { reassignTo })wrapper atapiPipeline.js:344handles reassign-then-delete). - Optionally re-split into 3–4 acts using the editable issue mapping in the preview.
Verify end-to-end on https://host-beta.example-tailnet.ts.net:5555/pipeline/series/ser-c22c6c9e-... after implementing.
Workstream 4 — Manuscript-completeness ("finish the draft") editor action
Goal: a new series-level action that ingests the actual comicScript manuscript across issues + the arc + canon, and returns categorized findings: missing pages/beats, arc holes, character-development gaps. Leave Verify Arc/Volume unchanged.
- Prompt —
data.reference/prompts/stages/pipeline-manuscript-completeness.md(new file;setup-data.jsauto-copies missing prompt files into installs, so no migration needed for a brand-new prompt). Register it indata.reference/prompts/stage-config.json(heavy tier,returnsJson: true) alongsidepipeline-arc-verify(:273). The prompt takes the concatenated manuscript + arc + canon and returns{ issues: [{ severity, category, location, problem, suggestion }] }. - Service —
arcPlanner.js:analyzeManuscriptCompleteness(seriesId, options)— builds context fromcollectIssueSourceText(real script, not synopsis) +buildArcBaseContext+ canon, runs the new prompt, shapes results with acategory-aware variant of the existingshapeVerifyIssues(:873). Read-only (no writes). - Route —
server/routes/pipeline.js:POST /series/:id/manuscript/completeness(mirror/arc/verifyat:1174). - Validation:
manuscriptCompletenessSchemainvalidation.js(provider/model overrides). - Client —
apiPipeline.js:analyzePipelineManuscriptCompleteness(seriesId, opts)+ barrel/README;ArcCanvas.jsx: a "Finish the draft" button near Verify Arc that renders findings in the existingVerifyResults-style panel (grouped by category). These are advisory suggestions (no auto-resolve in v1).
Cross-cutting
- Schemas: every new route input validated via
validation.js(POST + PUT parity rule). New fields added to any sanitizer/payload get a matching Zod update in the same change. - Barrels/README: any new
client/src/servicesexport re-exported fromapi.js+ a README row; any newserver/libhelper added to itsindex.js+ README (boot test enforces this). - Migrations: none required if we (a) keep
importer-arc-extract.mdunchanged and (b) only add the newpipeline-manuscript-completeness.md. If we end up modifying an existing shipped stage prompt, add ascripts/migrations/NNN-*.jsper the CLAUDE.md stage-prompt rule (hash-gated update of installed copy) and update the drift constants inscripts/setup-data.js. - Tests: unit-test the pure pieces — the importer single-volume remap/split helper,
deriveFromManuscriptpreview shaping, and the completeness result shaper. Add route tests mirroring existingpipelineroute tests. Runcd server && npm testandcd client && npm test. - Simplify: run
/simplifyafter the diff settles (judgment-gated), then commit/push when the user asks.
Verification
- Unit/route tests:
cd server && npm test,cd client && npm test— all green. - Importer choice (Workstream 1): in the worktree,
npm run dev; import a small comic script with PAGE markers; in review, pick "Single volume" + 3 chapters → confirm. Inspectdata/pipeline-series/<id>/index.json: one season,logline/premise/issueCountTargetpopulated; 3 issues all under that season withcomicScript(ready) +idea.inputseeded. - Derive from manuscript (Workstreams 2+3): on
ser-c22c6c9e-..., click "Derive from manuscript" → preview shows 1 volume + arc + bible; confirm → UI shows 1 volume, 3 issues reassigned, bible filled; extra empty volumes gone. Verify the verbatim issue scripts are untouched. - Finish the draft (Workstream 4): click "Finish the draft" → returns categorized findings (missing pages, arc holes, character gaps) computed from the real manuscript; confirm Verify Arc still works at synopsis level independently.
- Confirm no nav-manifest/barrel boot failures (
npm startwarms providers + barrels).