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
docs: changelog + archived design plan for manuscript-driven series tools
[._.]/ Adam Eivy2cdb84b841e8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex ad92543644..2feb098b09 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -18,6 +18,8 @@## Added+- **[pipeline-derive-from-manuscript + manuscript-completeness] Reconstruct a series arc/bible from an imported manuscript, and get editor feedback on what's left to finish.** Two new series-level actions on the Arc Canvas. **Derive from manuscript** reads the comic-script / prose / teleplay you already drafted across the issues and proposes — in a review-and-confirm preview — a series arc, the bible fields (logline, premise, issue-count target), and a single graphic-novel volume holding every issue as a chapter/act; confirming collapses any stray extra volumes into one, reassigns the issues, fills the bible, and seeds each issue's synopsis so the synopsis-level **Verify Arc** pass becomes useful — without ever touching your verbatim scripts. (Reuses the existing `importer-arc-extract` back-derivation that previously lived only inside the Story Builder; `collectIssueSourceText` is now shared.) **Finish the draft** is a separate developmental-editor pass that reads the *actual drafted manuscript* (not synopses, which Verify Arc/Volume are limited to) and returns categorized suggestions — missing content, arc gaps, character-development gaps, pacing, continuity — for rounding out a near-complete draft before you generate every per-issue stage. New routes `POST /api/pipeline/series/:id/arc/derive-from-manuscript(/commit)` and `…/manuscript/completeness`, a new `pipeline-manuscript-completeness` stage prompt (auto-installed via the stage-config merge — no migration), and Zod-validated inputs.+- **[importer-single-volume-choice] The importer lets you choose how a finished work is split — one graphic-novel volume of chapters, or a multi-volume series — and no longer leaves the bible blank.** Importing a comic script used to create the LLM's multi-volume breakdown (often 3–4 "volumes") regardless of intent, with no choice offered, *and* wrote only `series.arc` + seasons — leaving the bible sidebar (logline, premise, issue-count target) empty after a successful import. The Review step now has a **Structure** control: comic scripts default to a single volume holding every issue as a chapter/act (the extracted volume descriptions fold into the issue synopses — "the volume descriptions read better as issue descriptions"), with one click to switch back to multi-volume. On commit, the bible's logline / premise / issue-count are populated from the extracted arc + issue count (additive imports only fill empty fields; Replace overwrites).- **[catalog-character-sheet-enrichment] Catalog and Universe Builder are now the same durable record, and the catalog's color palette / stats / aliases are editable inline.** Editing a character/place/object on the Catalog detail page and editing it on the Universe Builder canon surface used to write two parallel copies (the `catalog_ingredients` row and the embedded `universe.characters[]` entry) that silently drifted apart. They're now kept in lockstep by a bidirectional projection (`server/services/catalogCanonProjection.js`): a Catalog edit fans into every linked universe's embedded canon entry (best-effort, after the response), and a canon edit projects back into the catalog row synchronously inside `updateUniverse` so the embedded copy is a never-lagging cache of the one store of record. Conflicts resolve last-writer-wins on `updatedAt`; an in-flight re-entrancy guard breaks the catalog→canon→catalog loop so each side is written exactly once per edit. A one-time boot reconciliation (`reconcileCanonCatalog.js`, marker `data/catalog-canon-reconcile.applied.json`, registered as migration `055`) collapses any pre-existing divergence on first upgrade. Separately, the catalog character/place/object detail page now edits the enriched array fields inline — Aliases (string chips), Color Palette (`{ name, hex, role }` swatch rows with a native color picker), and Stats (`{ label, value }` rows) — instead of rendering them read-only; add-buttons disable at the storyBible caps (12 colors, 30 stats, 12 aliases). Bible-type payloads are now run through their storyBible sanitizer (`sanitizeCharacter`/`sanitizePlace`/`sanitizeObject`) on every catalog create/update so the array editors can't land malformed rows; idea/scene/concept and user-defined types are untouched. (Builds on the editable grouped sheet + reference-sheet panel + friendly-tag repair that shipped earlier as a slice.)- **[catalog-user-defined-types] Define your own Catalog ingredient types in Settings → Catalog.** The catalog shipped six built-in types (character / place / object / idea / scene / concept); you can now add your own — wardrobe, vehicle, faction, magic-system, prompt-fragment, anything — without a code change. A new Settings → Catalog tab lists the built-ins read-only and lets you build custom types from a flat field list: each type is `{ id, label, primaryContentKey, fields: [{ key, label, kind: 'string' | 'longtext' | 'tags' | 'ref', maxLength? }] }`. User types persist in `data/settings.json` (`catalogUserTypes`) — not a new table — and merge into the active type registry at boot and on every save, so they show up immediately as filter chips, in the "New" dropdown, and as a fully editable detail page driven by a single generic field renderer (no per-type React file). A `ref` field links to another catalog ingredient via the existing picker; `tags` reuses the tag chip input. Validity is enforced at the app layer (the registry + a Zod refinement on the ingredient `type`), building on the already-dropped DB `CHECK`. User types federate: they ride a new additive `catalogTypes` block in the catalog sync envelope (LWW-merged into each peer's own settings slice, skipping built-in-id collisions), gated by `PORTOS_SCHEMA_VERSIONS.catalog` bumped to 8 — a peer on an older catalog schema rejects a forward-shaped push with a clean 412 rather than dropping the definitions and then choking on ingredients of an unknown type. Deleting a type that still has ingredients is refused unless you force it (the orphaned rows survive under a fallback editor). No DB migration — settings-only.diff --git a/docs/plans/2026-05-30-importer-derive-manuscript.md b/docs/plans/2026-05-30-importer-derive-manuscript.mdnew file mode 100644index 0000000000..054e8ee3fd--- /dev/null+++ b/docs/plans/2026-05-30-importer-derive-manuscript.md@@ -0,0 +1,91 @@+# 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:++1. **4 "volumes" but 3 issues, no user choice.** The "volumes" are actually `series.seasons[]`, produced by the `importer-arc-extract` LLM *independently* of the 3 issues the mechanical `splitComicScriptIssues()` 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.+2. **Empty bible.** Commit only writes `series.arc` + `series.seasons`. It never sets the top-level `series.logline` / `series.premise` / `issueCountTarget` that the bible sidebar reads, so the bible shows only the name. The mechanical comic split also seeds `stages.comicScript` (the verbatim manuscript) but **not** `stages.idea.input` (synopsis) — so Verify Arc, which reads `idea.input`, sees empty synopses for these issues.+3. **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. And `verifyArc` / `verifyVolume` are **synopsis-level only** (read `idea.input`/`idea.output`); they're blind to the actual `comicScript` manuscript, 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` (near `ArcReviewSection`/`IssuesReviewSection`): radio **"Single volume (graphic novel)"** vs **"Multi-volume series"**, plus a chapter/issue count.+ - When "Single volume" is chosen: collapse `seasonsDraft` to 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 (mirror `splitComicScriptIssues`'s page-bundling — see below).+ - On commit, send the reconciled `seasons` + `issues` (existing `commitImport` payload already carries both).+- **`server/services/importer.js` (`commitImport`, ~line 1181–1205):** after writing `arc` + `seasons`, also patch top-level bible fields when present and not locked:+ - `series.logline` ← `arc.logline`+ - `series.premise` ← `arc.summary` (fallback `arc.protagonistArc`)+ - `series.issueCountTarget` ← number of issues being created+ - Use the existing `updateSeries` patch (it already supports these keys — see `series.js:298–312`). Guard each so a re-import never clobbers a non-empty/locked field (`replaceMode` may overwrite; additive preserves).+- **Per-issue synopsis seed:** in the commit issue-loop (`importer.js:1269–1281`), when a comic-script issue has no `logline`/`synopsis` (mechanical split), still seed `stages.idea.input` with the season/chapter description mapped in the review step, so Verify Arc has synopsis material. Keep `stages.comicScript` seeding unchanged.+- **Reconciliation guard:** in `analyzeImport` (`importer.js:642`), when `contentType==='comic-script'` and the mechanical split produced N issues, default the `seasonsPreview` the 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:** `importerCommitSchema` already accepts `seasons` (max 50) + `issues`; no schema change needed unless we add an explicit `volumeStrategy` field (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 in `server/services/storyBuilder.js:436` (prefers `comicScript → teleplay → prose → idea`) but isn't exported — extract it into a shared spot (e.g. `arcPlanner.js` or a small `server/services/pipeline/` helper, referenced from both) rather than duplicating.+ - Add `deriveFromManuscript(seriesId, { providerOverride, modelOverride })` that: collects manuscript text, calls the existing `generateArcFromSource()` (`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 via `updateSeries`; replace seasons with the single volume via `commitSeasonsWithRemap(series, { arc, seasons })` (honors per-field arc locks, per-season locks, and remaps/keeps child issues — `arcPlanner.js` already owns this); reassign every issue's `seasonId` to the retained volume; optionally backfill each issue's `idea.input` synopsis. Per-episode issue **scripts are never overwritten** (same contract as `resolveVerifyIssues`).+- **Routes — `server/routes/pipeline.js`** (mirror the `/arc/generate` preview+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`:** add `arcDeriveSchema` (provider/model overrides + optional `commit`), wired into the route via `validateRequest`.+- **Client API — `client/src/services/apiPipeline.js`:** add `derivePipelineArcFromManuscript(seriesId, opts)` next to `generatePipelineArcOverview` (`: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:+1. Run **Derive from manuscript** → preview proposes single volume + arc + bible from the 3 issues' `comicScript` content.+2. Confirm → collapses V1–V4 to one volume, reassigns the 3 issues, fills the bible.+3. Delete the now-empty V2/V3/V4 if `commitSeasonsWithRemap` leaves any (the existing `deletePipelineSeason(seriesId, seasonId, { reassignTo })` wrapper at `apiPipeline.js:344` handles reassign-then-delete).+4. Optionally re-split into 3–4 acts using the editable issue mapping in the preview.++Verify end-to-end on `https://null.taile8179.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.js` auto-copies *missing* prompt files into installs, so **no migration needed** for a brand-new prompt). Register it in `data.reference/prompts/stage-config.json` (heavy tier, `returnsJson: true`) alongside `pipeline-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 from `collectIssueSourceText` (real script, not synopsis) + `buildArcBaseContext` + canon, runs the new prompt, shapes results with a `category`-aware variant of the existing `shapeVerifyIssues` (`:873`). Read-only (no writes).+- **Route — `server/routes/pipeline.js`:** `POST /series/:id/manuscript/completeness` (mirror `/arc/verify` at `:1174`).+- **Validation:** `manuscriptCompletenessSchema` in `validation.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 existing `VerifyResults`-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/services` export re-exported from `api.js` + a README row; any new `server/lib` helper added to its `index.js` + README (boot test enforces this).+- **Migrations:** none required if we (a) keep `importer-arc-extract.md` unchanged and (b) only *add* the new `pipeline-manuscript-completeness.md`. If we end up modifying an existing shipped stage prompt, add a `scripts/migrations/NNN-*.js` per the CLAUDE.md stage-prompt rule (hash-gated update of installed copy) and update the drift constants in `scripts/setup-data.js`.+- **Tests:** unit-test the pure pieces — the importer single-volume remap/split helper, `deriveFromManuscript` preview shaping, and the completeness result shaper. Add route tests mirroring existing `pipeline` route tests. Run `cd server && npm test` and `cd client && npm test`.+- **Simplify:** run `/simplify` after the diff settles (judgment-gated), then commit/push when the user asks.++## Verification++1. **Unit/route tests:** `cd server && npm test`, `cd client && npm test` — all green.+2. **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. Inspect `data/pipeline-series/<id>/index.json`: one season, `logline`/`premise`/`issueCountTarget` populated; 3 issues all under that season with `comicScript` (ready) + `idea.input` seeded.+3. **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.+4. **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.+5. Confirm no nav-manifest/barrel boot failures (`npm start` warms providers + barrels).