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
address review (self): bulk-import embedBatch + markdown warnings
[._.]/ Adam Eivy21440732ad1b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex ff52c2e692..cb9ad5639a 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -14,7 +14,7 @@## Added- **[catalog-pipeline-series-cast] "Cast (from Catalog)" panel on Series, Issue, and Writers Room pages.** A new reusable panel surfaces every catalog ingredient linked to the active series / issue / work bible — drawn from the existing `catalog_ingredient_refs` table — and lets you attach more via the existing Ingredient Picker or unlink with a click. Series records carry no embedded `characters[]` array, so the cast is purely additive and replicates through the existing catalog sync. The panel lives in the Series bible sidebar above "Canon", at the top of the active stage scroll on Issue (visible across every stage tab), and above the work editor in Writers Room when a work is selected.-- **[catalog-bulk-import] Bulk-ingest endpoint for the Catalog.** A new "Bulk Import" panel on `/catalog/ingest` accepts JSON, CSV (`type,name,description,tags` header), or simple markdown (`## <Type>: <Name>` headings with paragraph body and optional `tags:` line) and creates ingredients directly — no LLM round-trip, no per-row review screen. The whole batch commits or rolls back together, so a malformed entry can't leave the catalog half-populated. `POST /api/catalog/bulk-import` is Zod-validated (2 MB payload cap) and stamps optional `defaults.tags` plus an optional `universe`/`series`/`work`/`issue` ref onto every row in the same transaction.+- **[catalog-bulk-import] Bulk-ingest endpoint for the Catalog.** A new "Bulk Import" panel on `/catalog/ingest` accepts JSON, CSV (`type,name,description,tags` header), or simple markdown (`## <Type>: <Name>` headings with paragraph body and optional `tags:` line) and creates ingredients directly — no per-row review screen. Each row is re-validated against the same Zod schema the single-create endpoint uses, so one bad row rolls back the entire batch; vector embeddings run in parallel before the transaction (same as the scrap-commit path), so bulk-imported rows are search-ready immediately rather than waiting for the embeddings backfill. `POST /api/catalog/bulk-import` is Zod-validated (2 MB payload cap), stamps optional `defaults.tags` plus an optional `universe`/`series`/`work`/`issue` ref onto every row in the same transaction, and surfaces parser warnings (e.g. `## Plce: …` typos in markdown that don't match a known type) in the response so users notice typos that would otherwise be silently skipped.- **[catalog-export-bundle] Export a catalog slice as a portable bundle.** `GET /api/catalog/export?refKind=universe|series|issue|work&refId=…&format=json|markdown|yaml` walks the ref table for the target, hydrates each ingredient + its scraps + ref-links, and returns an `attachment` bundle. Pairs with bulk import for round-trip portability (export → edit → re-import) — useful for sharing a universe's cast outside peer-sync or seeding a fresh install from a community pack. Relations and media-ref hydration ship with their own PLAN items.- **[catalog-cmdk-ask-voice-discovery] Catalog ingredients are now discoverable from ⌘K and voice.** The Command Palette ⌘K shows live catalog hits (top 5, debounced) under a "Catalog" group as you type — selecting one jumps straight to the ingredient detail page. A new voice tool `catalog_lookup({ query, type?, limit? })` returns matching ingredients with type, snippet, and ref-count, intent-gated so it only loads on catalog-y turns and doesn't bloat every prompt. Ask retrieval (the third leg of the original PLAN item) is split out to follow.- **[catalog-extraction-idea-scene-concept] Catalog Ingest now extracts ideas, scenes, and concepts too.** Pasting prose into `/catalog/ingest` previously only surfaced characters / places / objects. A new LLM stage runs alongside the three existing bible passes and proposes idea, scene, and concept candidates from the same scrap — each rendered as its own review section with selectable / editable rows, then committed via the same path. One additional LLM call per ingest; failures isolate to that stage so the other three are unaffected.diff --git a/server/lib/catalogBulkParsers.js b/server/lib/catalogBulkParsers.jsindex 4446ec3c5a..af6f97e717 100644--- a/server/lib/catalogBulkParsers.js+++ b/server/lib/catalogBulkParsers.js@@ -234,6 +234,7 @@ export function parseMarkdownBulk(payload) {// is everything to the right of the first `:`. Heading must start the line.const headingRe = /^##\s+([A-Za-z][A-Za-z-]*)\s*:\s*(.+?)\s*$/;const out = [];+ const warnings = [];let current = null;const flush = () => {if (!current) return;@@ -256,9 +257,11 @@ export function parseMarkdownBulk(payload) {const type = normalizeType(m[1]);const name = m[2].trim();if (!type) {- // Skip unrecognized headings (e.g. `## Notes:`); they'd otherwise- // open a malformed section. Leave `current` null so any following- // body lines are dropped until the next valid heading.+ // Skip unrecognized headings (e.g. `## Notes:`, typos like `## Plce:`);+ // they'd otherwise open a malformed section. Surface as a warning so+ // the user notices typos; the body until the next valid heading is+ // dropped.+ warnings.push(`Unknown type "${m[1]}" in heading "${line.trim()}" — section skipped`);current = null;continue;}@@ -278,7 +281,13 @@ export function parseMarkdownBulk(payload) {if (out.length === 0) {throw new Error('markdown produced zero `## <Type>: <Name>` sections');}- return out.map((entry, i) => normalizeEntry(entry, i));+ const entries = out.map((entry, i) => normalizeEntry(entry, i));+ // Warnings ride as a non-enumerable property on the returned array so+ // existing callers that array-index `result[i]` (or deep-equal it in+ // tests) keep working; the bulk-import handler reads `result.warnings`+ // to surface typos back to the user.+ Object.defineProperty(entries, 'warnings', { value: warnings, enumerable: false });+ return entries;}/**diff --git a/server/lib/catalogBulkParsers.test.js b/server/lib/catalogBulkParsers.test.jsindex bd4b9fe0c0..487746e43b 100644--- a/server/lib/catalogBulkParsers.test.js+++ b/server/lib/catalogBulkParsers.test.js@@ -172,6 +172,20 @@ describe('parseMarkdownBulk', () => {const out = parseMarkdownBulk(md);expect(out[0].type).toBe('character');});++ it('records a warning for each unknown type heading', () => {+ const md = '## Idea: keeper\nkept body\n## Faction: Goons\nfaction body\n## Plce: typo\nbad body\n## Place: keeper2\nplace body\n';+ const out = parseMarkdownBulk(md);+ expect(out.map((e) => e.name)).toEqual(['keeper', 'keeper2']);+ expect(out.warnings).toHaveLength(2);+ expect(out.warnings[0]).toMatch(/Unknown type "Faction"/);+ expect(out.warnings[1]).toMatch(/Unknown type "Plce"/);+ });++ it('exposes an empty warnings array when all headings are valid', () => {+ const out = parseMarkdownBulk('## Idea: X\nbody\n');+ expect(out.warnings).toEqual([]);+ });});describe('parseBulkPayload dispatch', () => {diff --git a/server/routes/catalog.js b/server/routes/catalog.jsindex 1ff6a8dc39..308c98c94f 100644--- a/server/routes/catalog.js+++ b/server/routes/catalog.js@@ -249,14 +249,26 @@ router.post('/bulk-import', asyncHandler(async (req, res) => {if (defaults[field]) refLinks.push({ refKind: kind, refId: defaults[field], role: defaults.role || `bulk-${kind}` });}+ // Embed every entry in parallel BEFORE the transaction — matches the+ // scrap-commit path (line 100). Network round-trips dominate; keeping+ // them outside the DB transaction means a slow embed provider can't+ // hold a Postgres write lock open. Failed embeds land as null `embedding`+ // and the embeddings/backfill endpoint can fill them in later.+ const seeds = entries.map((e) => ingredientEmbedSeed(e));+ const embeds = await embedBatch(seeds);+const created = await withTransaction(async (client) => {const out = [];- for (const entry of entries) {+ for (let i = 0; i < entries.length; i++) {+ const entry = entries[i];+ const e = embeds[i];const ing = await catalogDB.createIngredient({type: entry.type,name: entry.name,payload: entry.payload || {},tags: entry.tags || [],+ embedding: e?.embedding ?? null,+ embeddingModel: e?.model ?? null,}, { client });// Stamp ref links inside the same transaction so a mid-batch failure// rolls back the link rows alongside their ingredients.@@ -274,8 +286,11 @@ router.post('/bulk-import', asyncHandler(async (req, res) => {return out;});- console.log(`📥 Catalog bulk import: ${format} → ${created.length} ingredient(s)`);- res.status(201).json({ created, count: created.length });+ // Parser warnings (today: unrecognized markdown type headings) ride+ // back on the response so the user notices typos like `## Plce: …`.+ const warnings = Array.isArray(parsed.warnings) ? parsed.warnings : [];+ console.log(`📥 Catalog bulk import: ${format} → ${created.length} ingredient(s)${warnings.length ? ` (${warnings.length} warning(s))` : ''}`);+ res.status(201).json({ created, count: created.length, warnings });}));// Export one ref slice (universe/series/issue/work) as a portable bundle.