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: check off catalog-type-table-vs-check (option b); note user-defined-types precondition resolved
[._.]/ Adam Eivy49cd00d72bb8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 2322760d56..5907f89ea9 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,7 @@## Changed+- **[catalog-type-table-vs-check] Adding a new catalog ingredient type no longer needs a database migration.** The `catalog_ingredients.type` column previously carried a hardcoded `CHECK (type IN (…six types…))` duplicated in both the fresh-install SQL and the runtime schema-upgrade path, so introducing a seventh type meant a two-file constraint migration. The CHECK is dropped (and the column widened to `VARCHAR(32)`); valid types are now enforced purely at the app layer by the shared type registry (`catalogTypes.js`) and its Zod enum — the same gate that was already validating every create/update. Existing installs drop the constraint idempotently on the next restart. No behavior change for the current six types and no cross-peer sync version bump (the wire payloads are identical until a new type is actually introduced); this clears the precondition for user-defined ingredient types.- **[catalog-detail-batched-endpoint] Catalog ingredient detail page loads in one request.** The detail page used to fire five separate requests on mount (the ingredient, its relations, revision history, media attachments, and the missing-media integrity overlay). A new `GET /api/catalog/ingredients/:id/details` hydrates all of them in a single round-trip, and the page consumes it on initial load. Post-mutation updates (attach media, restore a revision, add a relation) still use the granular endpoints so a single edit doesn't re-pull the whole record. No visible change beyond a faster, less flickery detail load.- **[catalog-import-sync-hardening] Catalog bulk-import keeps scraps; legacy universe tags self-heal across peers.** Bulk-importing markdown that carries a `### Scraps` subsection now persists those scraps as `catalog_scraps` rows + source links inside the same transaction (previously the round-tripped scraps were silently dropped on import); the response reports a `scrapsCreated` count. Separately, an ingredient synced from an older or offline peer *after* the one-time boot tag-repair ran would reintroduce raw `from-universe` / `universe:<uuid>` machine tags via last-writer-wins — those are now friendlified to the universe NAME on inbound sync — re-applying the repair whenever an ingredient is (re)synced and its universe is resolvable locally, instead of only at boot (a catalog row that arrives before its universe keeps its machine tags and is cleaned up on the next sync or by the boot repair). Internal: the seven near-identical per-kind apply loops in `catalogSync.applyRemoteChanges` collapse into a single `applyKind` helper (pure refactor, behavior-identical), and `createScrap` gains a `{ client }` transaction option. Adds route-level Postgres integration tests for `/bulk-import` and revision `/restore`.diff --git a/PLAN.md b/PLAN.mdindex 41d9b21296..f1c15893bf 100644--- a/PLAN.md+++ b/PLAN.md@@ -34,9 +34,9 @@ New follow-ups surfaced during the 2026-05-30 review pass:The v1 catalog hardcodes six types (`character|place|object|idea|scene|concept`) in at least eight places: the Postgres CHECK constraint (`server/scripts/init-db.sql` + `server/lib/db.js:ensureSchema`), the Zod enum in `server/lib/catalogValidation.js`, the extraction prompt in `server/services/catalogExtraction.js`, the `TYPES` array + `PRIMARY_CONTENT_KEY` + `PRIMARY_CONTENT_LABEL` + `payloadSnippet` fallback chain in `client/src/pages/Catalog.jsx`, the type-specific editor branches in `client/src/pages/CatalogIngredient.jsx`, the `IngredientPicker.jsx` type filter, and the `search_tsv` generated column expression. Adding a seventh type today is an 8-file touch across server, client, and a Postgres migration. The items below collapse that surface so the catalog can grow into the long tail of creative shards (lore fragments, factions, magic systems, vehicles, wardrobe, dialogue snippets, beat cards, prompt fragments, voice-memo transcripts, mood references, etc.) without each new shard being a multi-PR effort.- [x] [catalog-shared-type-registry] **Lift catalog ingredient types into a single shared registry (`server/lib/catalogTypes.js` + mirrored client constants).** Today the 6 types are duplicated across `init-db.sql`, `db.js:ensureSchema`, `catalogValidation.js` (Zod enum), `catalogExtraction.js` (prompt slot + JSON schema), `Catalog.jsx` (`TYPES`/`PRIMARY_CONTENT_KEY`/`PRIMARY_CONTENT_LABEL`/`payloadSnippet`), `CatalogIngredient.jsx` (per-type editor branches), `IngredientPicker.jsx` (type chips). One registry entry per type: `{ id, label, idPrefix, badgeColor, primaryContentKey, primaryContentLabel, snippetFallbackKeys, payloadSchema, extractionPromptFragment, editorComponent }`. Server-side: validation, extraction, ID prefix, and FTS field set derive from the registry. Client-side: list, picker, editor branches, and snippet fallback all map over the same registry. Adding a new type becomes one registry entry + one editor component + one migration that loosens the CHECK constraint (or replaces it with an FK to a `catalog_ingredient_types` table — see `[catalog-type-table-vs-check]`). Surfaced 2026-05-29 during the extensibility review.-- [ ] [catalog-type-table-vs-check] **Replace the `type` CHECK constraint with a `catalog_ingredient_types` table (or relax to a free-form `VARCHAR(32)` + app-layer validation).** Today `catalog_ingredients.type` is `CHECK (type IN ('character','place','object','idea','scene','concept'))`, so adding a type requires a Postgres migration that DROP/RE-ADD the constraint in both `server/scripts/init-db.sql` and `server/lib/db.js:ensureSchema`, plus a `PORTOS_SCHEMA_VERSIONS.catalog` bump. Either (a) seed a `catalog_ingredient_types(id, label, payload_schema_version, system bool, created_at)` table and FK `catalog_ingredients.type → catalog_ingredient_types.id`, letting registry-driven seeds + user-defined types coexist; OR (b) drop the constraint entirely and validate `type` against the registry at the app layer. Pairs with `[catalog-shared-type-registry]` and is the precondition for `[catalog-user-defined-types]`. Decide before adding the 7th type.+- [x] [catalog-type-table-vs-check] **Replace the `type` CHECK constraint with a `catalog_ingredient_types` table (or relax to a free-form `VARCHAR(32)` + app-layer validation).** Today `catalog_ingredients.type` is `CHECK (type IN ('character','place','object','idea','scene','concept'))`, so adding a type requires a Postgres migration that DROP/RE-ADD the constraint in both `server/scripts/init-db.sql` and `server/lib/db.js:ensureSchema`, plus a `PORTOS_SCHEMA_VERSIONS.catalog` bump. Either (a) seed a `catalog_ingredient_types(id, label, payload_schema_version, system bool, created_at)` table and FK `catalog_ingredients.type → catalog_ingredient_types.id`, letting registry-driven seeds + user-defined types coexist; OR (b) drop the constraint entirely and validate `type` against the registry at the app layer. Pairs with `[catalog-shared-type-registry]` and is the precondition for `[catalog-user-defined-types]`. Decide before adding the 7th type.- [x] [catalog-payload-schemaversion-per-type] **Stamp `payload.schemaVersion` per ingredient row + add a migration helper.** Today the JSONB `payload` is loose — when a type's payload shape evolves (e.g. character adds a `voiceNotes` field, scene adds `beat`/`povShift`), older rows have no marker for which shape they're in, and the sanitizer must tolerate any historical key set forever. Mirror the per-record `schemaVersion` convention already documented in CLAUDE.md (separate from the storage-layout version): each `createIngredient` stamps `payload.schemaVersion: <registry-current>`, and `server/scripts/migrateCatalogPayload.js` walks rows whose `payload.schemaVersion < registry-current` and applies registered upgraders. Registry entry gains `payloadSchemaVersion: number` + `payloadUpgraders: { 1: (p) => p2, 2: ... }`. Without this, payload evolution silently mixes shapes across rows.-- [ ] [catalog-user-defined-types] **Allow user-defined ingredient types in the Settings → Catalog section.** Once `[catalog-type-table-vs-check]` lands, expose a Settings UI to add a user type: `{ id, label, primaryContentKey, fields: [{ key, label, kind: 'string'|'longtext'|'tags'|'ref', maxLength? }] }`. Persisted in the new `catalog_ingredient_types` table with `system: false`; the registry merges seeded + user types at boot. Editor component for user types is a generic form renderer driven by the `fields` array (no per-type React file). Unblocks the long tail of personal creative shards (wardrobe, vehicle, faction, magic-system, voice-line, prompt-fragment, etc.) without a code change per shard. Decision needed on whether user types federate to peers (probably yes, with the type row riding the catalog sync envelope and gated by `PORTOS_SCHEMA_VERSIONS.catalog`).+- [ ] [catalog-user-defined-types] **Allow user-defined ingredient types in the Settings → Catalog section.** Once `[catalog-type-table-vs-check]` lands, expose a Settings UI to add a user type: `{ id, label, primaryContentKey, fields: [{ key, label, kind: 'string'|'longtext'|'tags'|'ref', maxLength? }] }`. Persisted in the new `catalog_ingredient_types` table with `system: false`; the registry merges seeded + user types at boot. Editor component for user types is a generic form renderer driven by the `fields` array (no per-type React file). Unblocks the long tail of personal creative shards (wardrobe, vehicle, faction, magic-system, voice-line, prompt-fragment, etc.) without a code change per shard. Decision needed on whether user types federate to peers (probably yes, with the type row riding the catalog sync envelope and gated by `PORTOS_SCHEMA_VERSIONS.catalog`). _Precondition resolved 2026-05-30: `[catalog-type-table-vs-check]` landed as **option (b)** (DB `CHECK` dropped + `type VARCHAR(32)`; validity gated by the `INGREDIENT_TYPES` registry + Zod enum) — so user types do NOT need a `catalog_ingredient_types` table; they can persist in settings and merge into the registry at boot, and a user-typed row already inserts at the DB layer. Still open as a larger Settings-UI + generic-form-renderer feature; remains deferred until picked up deliberately._- [x] [catalog-ingredient-relations] **Add a `catalog_ingredient_relations` table for ingredient↔ingredient edges.** Today the only ingredient relationships are to *external* records (`catalog_ingredient_refs` → universe/series/issue/work). Within the catalog, a character has no link to its place or to scenes it appears in, a concept has no link to objects that embody it, and a scene can't enumerate its cast. Schema: `(from_id, to_id, kind, created_at, sync_sequence, deleted, deleted_at)` with `kind` from a registry (`appears-in`, `lives-in`, `created-by`, `parent-of`, `variant-of`, `references`, ...). FK both ids to `catalog_ingredients(id) ON DELETE CASCADE`. UI: a "Relations" panel on `CatalogIngredient.jsx` with picker-driven add. Federate via the existing catalog sync envelope (new `relations: [...]` block). Use `deleted/deleted_at` soft-delete from day one (don't repeat the `[catalog-ref-deletion-tombstones]` mistake). This is the seam that makes the catalog a graph instead of a flat list — required before the "Knowledge Graph Visualization" Future Idea (line 249) can include creative content.- [x] [catalog-tag-taxonomy] **Promote tags from `TEXT[]` to a first-class `catalog_tags` table with autocomplete.** Today `catalog_ingredients.tags` is freeform (GIN-indexed, no canonical list) — `noir` / `Noir` / `noir-style` / `film noir` accumulate as separate tags and search by tag has no autocomplete. Add `catalog_tags(id, label, description?, color?, parent_id?, created_at, sync_sequence)`; keep the freeform `tags TEXT[]` column for write-path simplicity but add a normalization step that maps user input through the canonical table, creating new rows on first use. UI: tag picker autocomplete on `CatalogIngredient.jsx` and the Quick Idea form. Optional parent_id enables tag hierarchies (genre/tone vs structural vs character-trait). Pairs with `[catalog-shared-type-registry]` — the registry can also declare default tags per type.- [x] [catalog-ingredient-revisions] **Add a `catalog_ingredient_revisions` history table.** Today `updateIngredient` overwrites `payload` + `tags` in place and only `updated_at` records that it changed — no "what changed" diff, no "restore previous version" UI, no audit trail for AI-driven refinement runs (story-builder refine, future agent edits). Schema: `(id, ingredient_id, payload, tags, name, source: 'user'|'extract'|'refine'|'sync', actor?: string, created_at)` keyed `(ingredient_id, created_at)`. Write a row inside `updateIngredient` whenever `payload`/`tags`/`name` changes. UI: revision history list on `CatalogIngredient.jsx` with inline diff + "Restore" button. Cap retention to last N revisions per ingredient (config; default 50) to avoid unbounded growth. Pairs naturally with the existing Writers-Room version-history pattern.