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: check off catalog-ask-retrieval + changelog

[._.]/ Adam Eivy135409436ee2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9db16e59a3..2322760d56 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -17,6 +17,8 @@
## Added
+- **[catalog-ask-retrieval] Ask now draws on your Creative Catalog.** Asking a question (`/api/ask`, the Ask page, voice) now retrieves matching catalog ingredients — characters, places, objects, ideas, scenes, concepts — alongside memory, brain notes, goals, autobiography, and calendar. Matches use a hybrid Reciprocal-Rank-Fusion search (full-text + vector embedding) sharing the same scoring/budget model as memory retrieval, capped at 4 catalog sources per answer and weighted between brain-notes and autobiography. Each surfaced ingredient is a clickable source chip that deep-links to its catalog detail page. Full-text matching works immediately; semantic (vector) matches appear once you've configured an embedding model and run the catalog embeddings backfill. A catalog hiccup never blocks an answer (the retriever is isolated in the parallel fan-out).
+
- **[catalog-federation-orchestrator] The creative catalog now auto-replicates between peers.** The catalog sync routes existed but nothing pulled from peers — orphan ingredients (ideas / scenes / concepts not attached to a universe) and the universe→ingredient ref links stayed local. The sync orchestrator now runs `catalog` as a delta-based PostgreSQL category alongside Memory: on every peer-online event and on the background interval it pulls `GET /api/catalog/sync` (the seven independent per-kind BIGSERIAL cursors: scraps / ingredients / sources / refs / relations / tags / media) and applies each batch locally with the same last-writer-wins + per-row isolation + schema-version gate as direct sync. A peer ahead on the `catalog` schema records a gap on the Instances page (the existing SchemaGapBadge) and pauses draining instead of looping. Toggle it per peer under Instances → Sync Categories → "Catalog"; Postgres-only (a non-Postgres peer simply never enables it).
- **[catalog-bundled-universe-push] Universe peer-pushes now carry their catalog enrichments.** When peer A pushes a universe to peer B, the push bundles the `catalog_ingredients` rows referenced by that universe's canon plus the universe→ingredient ref links. Previously only the embedded canon replicated, so the receiver re-derived a strictly-lossy view on first backfill — the `tags`, vector `embedding`, and `payload.summary`-style enrichments that live only in the catalog row were dropped. The bundle ships the full enriched rows (including tombstoned ref rows so unlinks propagate), applied through the same catalog-sync path; it rides only universe pushes (never series / mediaCollection), skips tombstone pushes, and is gated by `PORTOS_SCHEMA_VERSIONS.catalog` so a receiver on an older catalog schema rejects a forward-shaped bundle with a clean 409 rather than corrupting local rows. Postgres-only and best-effort — a bundle failure never fails the universe push.
- **[catalog-character-sheet-enrichment] The Catalog character detail page is now a full editable character sheet, and backfilled rows get friendly universe tags.** Opening a `character` ingredient (e.g. `/catalog/character/cat-chr-…`) now shows grouped DnD-style sheet sections — Identity, Appearance, Personality & Voice, Goals & Drives, Background & Relationships, Notes — exposing every enriched canon scalar field the Universe Builder already tracks (role/archetype, pronouns, age, core theme, physical description, visual/silhouette/posture notes, special traits, personality, mannerisms, speech accent/pattern, motivations, likes, dislikes/fears, background, relationships, skills). Because the editor keys mirror `sanitizeCharacter` exactly, an edit on the Catalog surface lands in the same payload field the Universe Builder canon surface reads — the two are the same durable row (linked by the embedded `ingredientId` + `catalog_ingredient_refs`). The catalog's enriched array fields (color palette swatches, stats, aliases) render read-only here (their structured per-item editors live in Universe Builder), and a new "Reference sheet" panel shows the rendered turnaround when one exists (`/data/image-refs/…`) or, when the character belongs to a universe, links straight to Universe Builder to render one from that universe's style data. Places and objects get the same grouped-section treatment. Migration: a one-time boot-time data repair rewrites the legacy machine tags backfilled rows carried (`from-universe`, `universe:<uuid>`) into the friendly universe NAME tag while preserving every user tag and the structured universe ref — marker-gated in `data/catalog-universe-tags.applied.json` and registered in the migration ledger as `053-catalog-friendly-universe-tags`; new bible→catalog promotions stamp the friendly name from the start. (The deeper unification — collapsing the embedded canon entry to a pure `ingredientId` projection so the catalog row is the single store of record — is scoped to follow.)
diff --git a/PLAN.md b/PLAN.md
index 689ca1eeef..41d9b21296 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -44,7 +44,7 @@ The v1 catalog hardcodes six types (`character|place|object|idea|scene|concept`)
- [x] [catalog-bulk-import] **Bulk-ingest path for markdown/CSV/JSON dumps.** _Shipped 2026-05-29: `POST /api/catalog/bulk-import` with JSON / CSV / markdown (`## <Type>: <Name>`) parsers, single-transaction insert, optional `defaults.tags` + `*Ref` stamping. UI on `CatalogIngest.jsx`._
- [x] [catalog-export-bundle] **Export a catalog slice as a portable bundle.** _Shipped 2026-05-29: `GET /api/catalog/export?refKind=&refId=&format=json|markdown|yaml` hydrates ingredients + scraps + ref-links, sets `Content-Disposition: attachment`. Relations + media-refs deferred to those PLAN items._
- [x] [catalog-cmdk-ask-voice-discovery] **Surface catalog ingredients in ⌘K / Ask / voice (cross-surface discovery).** _Partially shipped 2026-05-29: ⌘K palette renders live catalog hits under a "Catalog" group (debounced search); voice tool `catalog_lookup({ query, type?, limit? })` registered with intent-gated loading. **Ask retrieval still open — see `[catalog-ask-retrieval]`.**_
-- [ ] [catalog-ask-retrieval] **Wire catalog ingredients into `/api/ask` context (token-budgeted, top-K hybrid search).** Deferred from `[catalog-cmdk-ask-voice-discovery]` — needs a research pass on the existing Ask retriever + budgeter before implementing so the catalog slice shares the same scoring/budget model as memory/universe context.
+- [x] [catalog-ask-retrieval] **Wire catalog ingredients into `/api/ask` context (token-budgeted, top-K hybrid search).** Deferred from `[catalog-cmdk-ask-voice-discovery]` — needs a research pass on the existing Ask retriever + budgeter before implementing so the catalog slice shares the same scoring/budget model as memory/universe context.
- [x] [catalog-export-bundle-import-refs] **JSON export bundles don't recreate ref links on re-import.** `parseJsonBulk` (in `server/lib/catalogBulkParsers.js`) unwraps `{ ingredients }` from an export bundle, but the route only stamps refLinks from `defaults.*Ref` — so when a user re-imports a bundle through `/catalog/ingest` → "Bulk Import", new ingredients land *without* the bundle's `ref` link and each row's per-row `roleForExportedRef` is dropped. Result: the imported slice is invisible to `listIngredientsForRef` and to future slice exports. Fix: have `parseJsonBulk` attach `bundleRef = { kind, id }` (non-enumerable, like `warnings`) when it detects a bundle root; have the bulk-import route fall back to `bundleRef` for refLinks when no `defaults.*Ref` overrides it, and (separately) propagate `roleForExportedRef` per row instead of the batch-level `defaults.role || bulk-<kind>` default. Surfaced by codex iter-2 review on PR #552.
- [x] [catalog-markdown-roundtrip-fences-scraps] **Markdown export → re-import loses non-primary payload keys + scraps.** `ingredientToMarkdown` (`catalogBulkParsers.js:303`) emits a ` ```json … ``` ` fence for non-primary payload keys (e.g. character `personality`) and a `### Scraps` subsection; but `parseMarkdownBulk` only recognizes the heading + `tags:` line and appends every other line to the primary content body, so re-importing pollutes `description`/`summary` with fence text and JSON. Fix: in `parseMarkdownBulk`, recognize ` ``` ` as a fence start/end and either skip (current behavior — but cleanly) or parse the JSON fence into `payload.*`; treat `### Scraps` as a body terminator and either preserve as a sibling `scraps[]` (full round-trip) or skip cleanly (lossy but not corrupt). Pairs with `[catalog-export-bundle-import-refs]` for the broader "round-trip lossy → round-trip fidelity" pass. Surfaced by codex iter-2.
- [x] [catalog-cast-panel-multi-role-unlink] **`CatalogCastPanel` unlink removes every row with the matching ingredient id, ignoring `role`.** `client/src/components/CatalogCastPanel.jsx:99` filters `r.ingredient.id !== ingredient.id` — but the ref table key is `(ingredient_id, ref_kind, ref_id, role)`, so an ingredient linked to the same record under multiple roles (which the API allows) loses all rows from local state on a single-role unlink until reload. Fix: filter by `!(r.ingredient.id === ingredient.id && r.role === role)`. Today the panel's role-mapping always picks one role per ingredient type, so this is latent — but peer-sync or future role-aware UI can populate multi-role rows. Surfaced by codex iter-2.