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
feat([importer-canonprompt-preview-fragments-helper]): share per-kind preview-fragments helper between Importer and canonPrompt.js
[._.]/ Adam Eivy1df88fb867c5
diff --git a/client/src/lib/canonPrompt.js b/client/src/lib/canonPrompt.jsindex 493f3d526f..d4b7f7f44a 100644--- a/client/src/lib/canonPrompt.js+++ b/client/src/lib/canonPrompt.js@@ -20,6 +20,35 @@ const SHORT_SPEC = Object.freeze({objects: Object.freeze({ primary: 'description', fallback: 'significance' }),});+// PREVIEW spec: importer pre-commit review surface. Wider than SHORT (the+// user needs to see narrative-only fields like `personality` / `background`+// to judge "include this character?") and intentionally distinct from RICH+// (RICH drives render prompts; preview is about identity disambiguation).+// `subtitleField` is the single-line tagline; `bodyFields` uses the same+// `[{ field }]` sequence shape as RICH_SPEC so `fragmentsFromSequence` can+// be reused (no prefixes — importer cards render values verbatim).+const PREVIEW_SPEC = Object.freeze({+ characters: Object.freeze({+ subtitleField: 'role',+ bodyFields: Object.freeze([+ { field: 'physicalDescription' },+ { field: 'personality' },+ { field: 'background' },+ ]),+ }),+ places: Object.freeze({+ subtitleField: 'slugline',+ bodyFields: Object.freeze([{ field: 'description' }]),+ }),+ objects: Object.freeze({+ subtitleField: null,+ bodyFields: Object.freeze([+ { field: 'description' },+ { field: 'significance' },+ ]),+ }),+});+// RICH spec: ordered list of all descriptor fields. Prefixes capitalized// uniformly so flattened output reads as natural sentence fragments.const RICH_SPEC = Object.freeze({@@ -118,6 +147,30 @@ export function descriptorForCanonEntry(kind, entry) {.join('. ');}+/**+ * PREVIEW fragments — importer pre-commit review surface.+ *+ * Returns `{ subtitle, body }` where `subtitle` is a single trimmed string+ * (empty when the kind has no subtitle field or the value is blank) and+ * `body` is an ordered `[{ field, value }]` array of non-blank fields,+ * intended for ` • `-joined rendering in importer cards. Unknown kinds and+ * non-object entries return the empty shape so callers can render+ * unconditionally.+ *+ * This is intentionally wider than `shortCanonDescriptorFragments` (which+ * is scoped to the visual subset that drives render-prompts and ref-image+ * gating). PREVIEW exists so the user can disambiguate which character /+ * place / object to commit, so it surfaces narrative-only fields+ * (`personality`, `background`, `slugline`) that have no visual role.+ */+export function previewCanonFragments(kind, entry) {+ if (!entry || typeof entry !== 'object') return { subtitle: '', body: [] };+ const spec = PREVIEW_SPEC[normalizeKind(kind)];+ if (!spec) return { subtitle: '', body: [] };+ const subtitle = spec.subtitleField ? trim(entry[spec.subtitleField]) : '';+ return { subtitle, body: fragmentsFromSequence(spec.bodyFields, entry) };+}+/*** True when the entry has any non-blank value across the RICH field set.* Mirrors `canonEntryHasContent`'s per-kind union check (UniverseBuilder.jsx)diff --git a/client/src/pages/Importer.jsx b/client/src/pages/Importer.jsxindex d87c338163..a132f67abe 100644--- a/client/src/pages/Importer.jsx+++ b/client/src/pages/Importer.jsx@@ -5,6 +5,7 @@ import toast from '../components/ui/Toast';import { useAsyncAction } from '../hooks/useAsyncAction';import { STORY_SHAPES } from '../components/pipeline/StoryShapes';import EntryCard from '../components/universe/EntryCard';+import { previewCanonFragments } from '../lib/canonPrompt';import {analyzeImport,classifyImport,@@ -471,8 +472,6 @@ function ReviewPanel({entries={canonSelections.characters}selectedIdxs={selectedCanon.characters}onToggle={(idx) => toggleSelected('characters', idx)}- renderSubtitle={(e) => e.role || ''}- renderBody={(e) => [e.physicalDescription, e.personality, e.background].filter(Boolean).join(' • ')}/><CanonReviewSection@@ -481,8 +480,6 @@ function ReviewPanel({entries={canonSelections.places}selectedIdxs={selectedCanon.places}onToggle={(idx) => toggleSelected('places', idx)}- renderSubtitle={(e) => e.slugline || ''}- renderBody={(e) => e.description || ''}/><CanonReviewSection@@ -491,8 +488,6 @@ function ReviewPanel({entries={canonSelections.objects}selectedIdxs={selectedCanon.objects}onToggle={(idx) => toggleSelected('objects', idx)}- renderSubtitle={() => ''}- renderBody={(e) => [e.description, e.significance].filter(Boolean).join(' • ')}/><ArcReviewSection arc={arcDraft} setArc={setArcDraft} seasons={seasonsDraft} setSeasons={setSeasonsDraft} arcShapeIds={arcShapeIds} />@@ -528,7 +523,7 @@ function ReviewPanel({);}-function CanonReviewSection({ title, kind, entries, selectedIdxs, onToggle, renderSubtitle, renderBody }) {+function CanonReviewSection({ title, kind, entries, selectedIdxs, onToggle }) {if (entries.length === 0) {return (<section className="bg-port-card border border-port-border rounded-lg p-4">@@ -547,8 +542,8 @@ function CanonReviewSection({ title, kind, entries, selectedIdxs, onToggle, rend</div><ul className="grid grid-cols-1 md:grid-cols-2 gap-2">{entries.map((entry, idx) => {- const subtitle = renderSubtitle(entry);- const bodyText = renderBody(entry);+ const { subtitle, body } = previewCanonFragments(kind, entry);+ const bodyText = body.map((f) => f.value).join(' • ');const name = entry.name || '(unnamed)';return (<EntryCarddiff --git a/server/lib/canonPrompt.js b/server/lib/canonPrompt.jsindex 1ad1f32133..e2c4ce1e3b 100644--- a/server/lib/canonPrompt.js+++ b/server/lib/canonPrompt.js@@ -13,12 +13,17 @@* UI summary + handleRenderRef button-enable predicate (SHORT fields)* - `settingFrags` (server/lib/scenePrompt.js) → scene-prompt framing* for places (SHORT fields)+ * - `CanonReviewSection` (client/src/pages/Importer.jsx) → importer+ * pre-commit per-card preview (PREVIEW fields)*- * SHORT vs RICH:+ * SHORT vs PREVIEW vs RICH:* - SHORT = the visual descriptor subset shown in UI cards. For* chars/objects: single primary field with a single fallback (mirrors* the legacy `descFor` `||` chain). For places: description +* palette + recurringDetails (the "place baseline" from scenePrompt).+ * - PREVIEW = narrative + identity-disambiguation fields surfaced in the+ * importer's pre-commit review cards. Includes prose-only fields+ * (`personality`, `background`, `slugline`) that have no visual role.* - RICH = every descriptive field that contributes to a render prompt.* Adds `role` (chars), `era`+`weather` (places), additive* `significance` (objects).@@ -40,6 +45,35 @@ const SHORT_SPEC = Object.freeze({objects: Object.freeze({ primary: 'description', fallback: 'significance' }),});+// PREVIEW spec: importer pre-commit review surface. Wider than SHORT (the+// user needs to see narrative-only fields like `personality` / `background`+// to judge "include this character?") and intentionally distinct from RICH+// (RICH drives render prompts; preview is about identity disambiguation).+// `subtitleField` is the single-line tagline; `bodyFields` uses the same+// `[{ field }]` sequence shape as RICH_SPEC so `fragmentsFromSequence` can+// be reused (no prefixes — importer cards render values verbatim).+const PREVIEW_SPEC = Object.freeze({+ characters: Object.freeze({+ subtitleField: 'role',+ bodyFields: Object.freeze([+ { field: 'physicalDescription' },+ { field: 'personality' },+ { field: 'background' },+ ]),+ }),+ places: Object.freeze({+ subtitleField: 'slugline',+ bodyFields: Object.freeze([{ field: 'description' }]),+ }),+ objects: Object.freeze({+ subtitleField: null,+ bodyFields: Object.freeze([+ { field: 'description' },+ { field: 'significance' },+ ]),+ }),+});+// RICH spec: ordered list of all descriptor fields. Prefixes capitalized// uniformly so flattened output reads as natural sentence fragments.const RICH_SPEC = Object.freeze({@@ -142,6 +176,30 @@ export function descriptorForCanonEntry(kind, entry) {.join('. ');}+/**+ * PREVIEW fragments — importer pre-commit review surface.+ *+ * Returns `{ subtitle, body }` where `subtitle` is a single trimmed string+ * (empty when the kind has no subtitle field or the value is blank) and+ * `body` is an ordered `[{ field, value }]` array of non-blank fields,+ * intended for ` • `-joined rendering in importer cards. Unknown kinds and+ * non-object entries return the empty shape so callers can render+ * unconditionally.+ *+ * This is intentionally wider than `shortCanonDescriptorFragments` (which+ * is scoped to the visual subset that drives render-prompts and ref-image+ * gating). PREVIEW exists so the user can disambiguate which character /+ * place / object to commit, so it surfaces narrative-only fields+ * (`personality`, `background`, `slugline`) that have no visual role.+ */+export function previewCanonFragments(kind, entry) {+ if (!entry || typeof entry !== 'object') return { subtitle: '', body: [] };+ const spec = PREVIEW_SPEC[normalizeKind(kind)];+ if (!spec) return { subtitle: '', body: [] };+ const subtitle = spec.subtitleField ? trim(entry[spec.subtitleField]) : '';+ return { subtitle, body: fragmentsFromSequence(spec.bodyFields, entry) };+}+/*** True when the entry has any non-blank value across the RICH field set.* Mirrors `canonEntryHasContent`'s per-kind union check (UniverseBuilder.jsx)diff --git a/server/lib/canonPrompt.test.js b/server/lib/canonPrompt.test.jsindex 68303da648..ae7432efcf 100644--- a/server/lib/canonPrompt.test.js+++ b/server/lib/canonPrompt.test.js@@ -4,6 +4,7 @@ import {richCanonDescriptorFragments,descriptorForCanonEntry,hasCanonDescriptorContent,+ previewCanonFragments,} from './canonPrompt.js';describe('canonPrompt.js', () => {@@ -227,6 +228,123 @@ describe('canonPrompt.js', () => {});});+ describe('previewCanonFragments', () => {+ it('returns empty shape for null/non-object entry', () => {+ expect(previewCanonFragments('characters', null)).toEqual({ subtitle: '', body: [] });+ expect(previewCanonFragments('characters', undefined)).toEqual({ subtitle: '', body: [] });+ expect(previewCanonFragments('characters', 'nope')).toEqual({ subtitle: '', body: [] });+ });++ it('returns empty shape for unknown kind', () => {+ expect(previewCanonFragments('unknown', { name: 'x', description: 'y' }))+ .toEqual({ subtitle: '', body: [] });+ });++ it('accepts singular and plural kinds (normalizeKind passthrough)', () => {+ const entry = { physicalDescription: 'tall', role: 'protagonist' };+ expect(previewCanonFragments('character', entry).subtitle).toBe('protagonist');+ expect(previewCanonFragments('CHARACTERS', entry).subtitle).toBe('protagonist');+ expect(previewCanonFragments('place', { slugline: 'INT. — DAY' }).subtitle).toBe('INT. — DAY');+ });++ describe('characters', () => {+ it('returns role as subtitle and physicalDescription/personality/background as body in order', () => {+ expect(previewCanonFragments('characters', {+ name: 'Alice',+ role: 'protagonist',+ physicalDescription: 'tall, dark hair',+ personality: 'curious, restless',+ background: 'orphaned at twelve',+ })).toEqual({+ subtitle: 'protagonist',+ body: [+ { field: 'physicalDescription', value: 'tall, dark hair' },+ { field: 'personality', value: 'curious, restless' },+ { field: 'background', value: 'orphaned at twelve' },+ ],+ });+ });++ it('omits blank body fields and yields blank subtitle when role missing', () => {+ expect(previewCanonFragments('characters', {+ physicalDescription: 'tall',+ background: '',+ })).toEqual({+ subtitle: '',+ body: [{ field: 'physicalDescription', value: 'tall' }],+ });+ });++ it('trims whitespace-only fields', () => {+ expect(previewCanonFragments('characters', {+ role: ' ',+ physicalDescription: ' tall ',+ personality: '',+ background: ' ',+ })).toEqual({+ subtitle: '',+ body: [{ field: 'physicalDescription', value: 'tall' }],+ });+ });++ it('does NOT include description as a fallback (preview is field-keyed, not legacy-fallback)', () => {+ expect(previewCanonFragments('characters', { description: 'old desc' }))+ .toEqual({ subtitle: '', body: [] });+ });+ });++ describe('places', () => {+ it('returns slugline as subtitle and description as body', () => {+ expect(previewCanonFragments('places', {+ name: 'The Plaza',+ slugline: 'EXT. — DUSK',+ description: 'a dusty plaza with a cracked statue',+ })).toEqual({+ subtitle: 'EXT. — DUSK',+ body: [{ field: 'description', value: 'a dusty plaza with a cracked statue' }],+ });+ });++ it('does NOT include palette/era/weather/recurringDetails (those are RICH-only)', () => {+ expect(previewCanonFragments('places', {+ slugline: 'INT.',+ description: 'plaza',+ palette: 'noir',+ era: '2099',+ weather: 'foggy',+ recurringDetails: 'statue',+ })).toEqual({+ subtitle: 'INT.',+ body: [{ field: 'description', value: 'plaza' }],+ });+ });+ });++ describe('objects', () => {+ it('returns empty subtitle and description+significance body', () => {+ expect(previewCanonFragments('objects', {+ name: 'Brass Key',+ description: 'tarnished brass key with a green ribbon',+ significance: 'opens the vault under the chapel',+ })).toEqual({+ subtitle: '',+ body: [+ { field: 'description', value: 'tarnished brass key with a green ribbon' },+ { field: 'significance', value: 'opens the vault under the chapel' },+ ],+ });+ });++ it('returns significance additively (not as fallback)', () => {+ expect(previewCanonFragments('objects', { significance: 'opens the vault' }))+ .toEqual({+ subtitle: '',+ body: [{ field: 'significance', value: 'opens the vault' }],+ });+ });+ });+ });+describe('richCanonDescriptorFragments edge cases', () => {it('returns [] for empty places entry', () => {expect(richCanonDescriptorFragments('places', {})).toEqual([]);