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

docs([extract-descriptorforcanonentry-kind-entry-into]): archive to DONE.md

[._.]/ Adam Eivy422d2b85f1d7
diff --git a/DONE.md b/DONE.md
index 2c72300766..9918ee313d 100644
--- a/DONE.md
+++ b/DONE.md
@@ -10,6 +10,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./
### 2026-05-17
+- **[extract-descriptorforcanonentry-kind-entry-into] Extract `descriptorForCanonEntry(kind, entry)` into `server/lib/canonPrompt.js` (mirror in client).** New `server/lib/canonPrompt.js` + `client/src/lib/canonPrompt.js` mirror is the single source of truth for per-kind canon descriptor fields. Exports `shortCanonDescriptorFragments` (UI summary scope: physicalDescription || description for chars; description + Palette + recurringDetails for settings; description || significance for objects), `richCanonDescriptorFragments` (adds role, era, weather, significance-as-additive — the render-prompt scope), `descriptorForCanonEntry` (flattened short string matching legacy `KINDS[].descFor`), and `hasCanonDescriptorContent` (rich-field union for "is there anything to render?" gates). Migrated four call sites: `synthesizeCanonPrompt` (`server/services/universeBuilder.js`), `KINDS[].descFor` (`client/src/components/universe/UniverseCanonSection.jsx`), `canonEntryHasContent` (`client/src/pages/UniverseBuilder.jsx`), and `settingFrags` in `server/lib/scenePrompt.js` + client mirror. Tests: 29 new in `server/lib/canonPrompt.test.js`. Minor cosmetic uniformity in canon render prompts: lowercase `palette:`/`era:`/`weather:`/`significance:` prefixes are now capitalized (`Palette:` etc.) to match the UI descriptor format — case-only diff, no functional impact on diffusion models.
- **[auto-sort-with-ai-llm-classify-each-kind-other] Universe Builder — Auto-sort with AI.** New `POST /api/universe-builder/:id/auto-sort` (server: `server/services/universeBuilderAutoSort.js`, `server/routes/universeBuilder.js`) batches every `kind: 'other'` bucket into a single LLM call that returns `{ classifications: [{ key, kind, suggestedKey? }] }`. The service applies kind reassignments atomically via one `updateUniverse` patch (defensive per-entry kind gate filters hallucinated kinds); `suggestedKey` renames stay opt-in — they surface as a count in the success toast but the bucket key isn't auto-renamed. Replaces the Other-tab's toast-stub `onAutoSort` handler with a real spinner-driven handler in `client/src/pages/UniverseBuilder.jsx`; new `autoSortBuckets` API helper in `client/src/services/apiUniverseBuilder.js`. Concurrent-edit safety: the service re-fetches the latest universe state immediately before the write so a variation added to a soon-to-be-classified bucket in another tab during the LLM call isn't overwritten; the client merges only the reclassified buckets into the draft to preserve user edits to other buckets. Covered by 15 unit tests in `universeBuilderAutoSort.test.js` (happy path, no-other-buckets short-circuit, hallucinated-key filter, `LLM_INVALID_JSON` (empty response + no-parse + non-array `classifications`) vs `NO_CLASSIFICATIONS` paths, `NO_PROVIDER` gate, prompt-injection defense via newline + Unicode-line-separator stripping on labels/styleNotes/logline) + 4 route tests in `universeBuilder.test.js`.
- **[extract-a-shared-tabpills-primitive-in-client-src] Extract a shared `<TabPills>` primitive in `client/src/components/ui/`.** New `client/src/components/ui/TabPills.jsx` with two variants (`underline` default + `pills` for UniverseBuilder) and knobs for the call-site quirks: `runningKind` (StoryboardPanel's per-tab spinner), `stretch` (flex-1 equal-width tabs), `mobileDropdown` (UniverseBuilder's `<select>` fallback), `hideLabelOnMobile` (Brain/DigitalTwin/ChiefOfStaff icon-only at < sm), `controlsIdPrefix` (ChiefOfStaff's `aria-controls` wiring), `listRef`+`onScroll` (ChiefOfStaff's scroll-arrow overlay). Migrated ten call sites — two local `TabNav` components (UniverseBuilder, StoryboardPanel) plus eight inline tab-button blocks (Brain, Calendar, ChiefOfStaff, DigitalTwin, MediaGen, Messages, Settings, Wiki). Net -250+ LOC consolidated into one primitive + 7 vitest cases. Small intentional visual unification across the surface area: StoryboardPanel active text-white → text-port-accent, ChiefOfStaff/Settings gained the standard `bg-port-accent/5` active wash + `hover:bg-port-card` inactive. PipelineIssue's status-dot tab variant is captured in PLAN.md as a follow-up needing a `trailing` slot extension on the primitive.
- **[unify-canoncard-variation-card-into-a-single] Universe Builder — unify CanonCard + variation card into shared `EntryCard` shell.** New `client/src/components/universe/EntryCard.jsx` slot-based primitive (locked accent, title row, body, action column, optional thumbnail, optional footer). `CanonCard` now renders through it and surfaces a top-left thumbnail derived from `primaryImageRef` (falling back to the first `imageRefs[0]`) so each canon entry has a visual at-a-glance. The variation `<li>` in `CategoryEditor` is extracted into a `VariationCard` helper that also renders through `EntryCard` — view mode shows label + prompt + action column (promote / render / lock / edit / remove); edit mode swaps the body for an inline form. Visual consistency between the two card families now flows from the shared shell rather than parallel Tailwind class strings.
diff --git a/PLAN.md b/PLAN.md
index ec2eac843f..a2e6e795ab 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -12,7 +12,6 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]
- **Phase C — Layout rewrite.** Tabbed top-level (Bible / Cast / Places / Objects / Other / Composites / Render) with URL state (`?tab=cast&bucket=heroes` per CLAUDE.md linkable-routes convention) — Bible is its own tab (not a sticky header). Per-trunk view = sub-bucket chip filter row + responsive card grid. Unify `CanonCard` + a new card for category variations into a single `EntryCard` component (renders thumbnail from `primaryImageRef` or most recent render). **Canon entries are first-class batch-render targets** alongside category variations and composite sheets: per-bucket actions are "Generate N more" + "Bulk-render this bucket"; per-trunk action is "Bulk-render all Cast/Places/Objects" (includes BOTH canon entries AND every variation in every sub-bucket under that trunk); the Batch Render tab itself offers per-trunk, per-bucket, and "All canon" selectors plus the existing composite-sheets mode. Composite reference images stay intact as their own render mode (no regression). Server-side: extend `compilePrompts` to accept canon entries as render sources (synthesize a prompt from `name + physicalDescription/palette/description`, layered with the universe style preset the same way variations are today). The **Other** tab only appears when un-kinded buckets exist, and shows the **Auto-sort with AI** action. Mobile: tabs collapse to a select dropdown.
- **Phase D — Polish & promotion.** ~~"Promote variation to canon" action~~ shipped: `POST /api/universe-builder/:id/promote-variation` LLM-expands a `{label, prompt}` variation into a full canon entry (per-kind `physicalDescription` / `slugline`+`palette` / `description`+`significance`) and atomically writes the canon append + variation removal in one `updateUniverse` patch. CategoryEditor renders a promote button per row; Other-tab buckets open a trunk picker (since `kind: 'other'` can't be auto-resolved). Duplicate-name collisions short-circuit with a 409 before the LLM call. Deferred: client component tests; standalone design doc (not warranted — CLAUDE.md notes + this PR's prose cover the contract).
- **Phase C follow-ups (deferred from the Phase C PR):**
- - [ ] [extract-descriptorforcanonentry-kind-entry-into] **Extract `descriptorForCanonEntry(kind, entry)` into `server/lib/canonPrompt.js` (mirror in client).** The new server-side `synthesizeCanonPrompt()` in `server/services/universeBuilder.js` duplicates the per-kind descriptor logic already present in `client/src/components/universe/UniverseCanonSection.jsx`'s `KINDS[].descFor` closures and overlaps with `server/lib/scenePrompt.js` (`settingFrags`). One helper would let canon-render synthesis, the canon UI summary, and scene-prompt framing all share the same field-precedence rules.
- [ ] [extract-builduniversestylecontext-helper] **Extract `buildUniverseStyleContext(universe, options)` helper.** The `LOGLINE / STYLE NOTES / EMBRACE INFLUENCES` prompt prefix is duplicated verbatim in three places: `server/services/universeBuilderPromote.js#buildPromotePrompt`, `server/services/universeBuilderAutoSort.js#buildAutoSortPrompt`, and a near-twin in `server/services/universeBuilderExpand.js` (adds `premise`). A single helper in `server/services/universeBuilder.js` (next to `joinInfluenceList`) would consolidate. Pipeline callsites at `server/services/pipeline/visualStages.js` and `pipeline/seriesTitleLogo.js` hand-roll variants of the same shape — fold them in too.
- [ ] [extract-useuniverseaction-hook] **Extract `useUniverseAction({ selectedId, mountedRef, setWorlds, setDraft })` hook.** `handlePromoteVariation`, `handleAutoSort`, and (to a lesser extent) `handleGenerateInCategory` in `client/src/pages/UniverseBuilder.jsx` share the same `*Ref` re-entrancy guard → `capturedId = selectedId` → `toast.loading` → API call → `mountedRef && capturedId === selectedId` stale-write guard → `setWorlds` + selective `setDraft` skeleton. `useAsyncAction` is too thin — it doesn't model the stale-write guard CLAUDE.md calls out. Extract when a 4th LLM-driven handler lands.
- [ ] [universe-builder-llm-action-read-modify-write-inside-queue] **Move LLM-action read-modify-write inside `queueUniverseWrite`.** `autoSortOtherBuckets` (and `promoteVariationToCanon`) currently read the universe state, run a long LLM call, then write — the gap between the LLM call and `updateUniverse` admits a narrow race where another tab can edit the same bucket. The service-level refetch right before write narrows the window to ~ms but doesn't eliminate it (concurrent writes between refetch and `updateUniverse`'s own queued readState can still drop a variation). Real fix: extend `updateUniverse` to accept a `mutator(latest) => patch` callback so the read-modify-write runs inside the file-level queue. Cross-cutting (touches every LLM-driven mutator).