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

feat: Universe Canon — "Appears in" cross-references on each card

[._.]/ Adam Eivy8fabfd7988df
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4d6f2fec66..54436489d2 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -206,6 +206,16 @@
it) — the post-merge length comparison was always equal. Now clones the
universe-side array before passing.
+- **Universe Canon page — "Appears in" cross-references.** Each canon card
+ (characters / places / objects) now shows which linked series + how many
+ issues that entry appears in: `Appears in: Clandestiny (15 issues)`. New
+ server service `canonUsage.js` aggregates prose-matched usage across
+ every linked series's issues (scans prose + idea + scripts via the same
+ matchers the comic-page renderer uses). New route
+ `GET /api/universe-builder/:id/canon-usage`. Loaded lazily after the
+ initial Canon page paint and refreshed after extract operations so new
+ entries get usage attribution automatically.
+
- **Nouns page is universe-only — orphan fallback removed (Phase B.3b).**
The per-issue Nouns page no longer falls back to series-side canon for
unlinked series. A series with no `universeId` now renders a clear gate
diff --git a/client/src/components/pipeline/CanonCard.jsx b/client/src/components/pipeline/CanonCard.jsx
index 9e36816c4e..3eca151dad 100644
--- a/client/src/components/pipeline/CanonCard.jsx
+++ b/client/src/components/pipeline/CanonCard.jsx
@@ -17,6 +17,9 @@ export default function CanonCard({
inFlightJobId,
onRender, onJobCompleted, onJobFailed, onPreview, onRefine,
refining = false, refineDisabled = false,
+ // Cross-reference usage: `[{ seriesId, seriesName, issueCount, issueIds }, ...]`
+ // populated lazily by the Universe Canon page. Null while still loading.
+ usage = null,
}) {
const description = kind.descFor(entry);
const refs = Array.isArray(entry.imageRefs) ? entry.imageRefs : [];
@@ -103,6 +106,18 @@ export default function CanonCard({
))}
</div>
) : null}
+ {usage && usage.length > 0 ? (
+ <div className="mt-2 text-[10px] text-gray-500">
+ Appears in:{' '}
+ {usage.map((u, i) => (
+ <span key={u.seriesId}>
+ {i > 0 ? ', ' : ''}
+ <span className="text-gray-400">{u.seriesName}</span>
+ <span className="text-gray-600"> ({u.issueCount} {u.issueCount === 1 ? 'issue' : 'issues'})</span>
+ </span>
+ ))}
+ </div>
+ ) : null}
</li>
);
}
diff --git a/client/src/pages/UniverseCanon.jsx b/client/src/pages/UniverseCanon.jsx
index aeea3c9a60..a2b208a997 100644
--- a/client/src/pages/UniverseCanon.jsx
+++ b/client/src/pages/UniverseCanon.jsx
@@ -20,6 +20,7 @@ import {
refineUniverseCharacter,
differentiateUniverseCast,
updateUniverse,
+ getUniverseCanonUsage,
} from '../services/apiUniverseBuilder';
import { generateImage, getSettings } from '../services/apiSystem';
import { composeStyledPrompt } from '../lib/composeStyledPrompt';
@@ -64,6 +65,11 @@ export default function UniverseCanon() {
const [extractText, setExtractText] = useState('');
const [extractOpen, setExtractOpen] = useState(false);
const [preview, setPreview] = useState(null);
+ // Per-canon-entry usage map: `{ characters: { [entryId]: [{seriesId, seriesName, issueCount, ...}] }, ... }`.
+ // Loaded lazily after the universe itself — usage is a derived view and
+ // shouldn't block the initial render. Refetched after mutations that change
+ // the canon shape (extract / differentiate-cast) so new entries get usage.
+ const [usage, setUsage] = useState(null);
useEffect(() => {
let cancelled = false;
@@ -78,6 +84,16 @@ export default function UniverseCanon() {
return () => { cancelled = true; };
}, [universeId, mountedRef]);
+ // Lazy usage fetch. Decoupled from the universe load so a slow cross-
+ // reference scan doesn't gate the page paint, and so it can be refetched
+ // independently after canon mutations.
+ const refreshUsage = useCallback(() => {
+ getUniverseCanonUsage(universeId)
+ .then((u) => { if (mountedRef.current) setUsage(u); })
+ .catch(() => { /* non-fatal; cards just render without usage footer */ });
+ }, [universeId, mountedRef]);
+ useEffect(() => { refreshUsage(); }, [refreshUsage]);
+
const previewItems = useMemo(() => {
if (!universe) return [];
const out = [];
@@ -119,6 +135,7 @@ export default function UniverseCanon() {
const result = await runExtract();
if (!result || !mountedRef.current) return;
setUniverse(result.universe);
+ refreshUsage();
const counts = KINDS
.map((k) => `${result.universe[k.key]?.length ?? 0} ${k.label.toLowerCase()}`)
.join(', ');
@@ -283,6 +300,7 @@ export default function UniverseCanon() {
key={kind.key}
kind={kind}
all={universe[kind.key] || []}
+ usage={usage?.[kind.key] || null}
renderingJobs={renderingJobs}
onRender={(entry) => handleRenderRef(kind, entry)}
onJobCompleted={(entryId, filename) => handleRefCompleted(kind.key, entryId, filename)}
@@ -298,7 +316,7 @@ export default function UniverseCanon() {
);
}
-function KindSection({ kind, all, renderingJobs, onRender, onJobCompleted, onJobFailed, onPreview, onRefine, refiningId }) {
+function KindSection({ kind, all, usage, renderingJobs, onRender, onJobCompleted, onJobFailed, onPreview, onRefine, refiningId }) {
const Icon = kind.icon;
return (
<section className="rounded-lg border border-port-border bg-port-card/40">
@@ -325,6 +343,7 @@ function KindSection({ kind, all, renderingJobs, onRender, onJobCompleted, onJob
onRefine={onRefine}
refining={refiningId === entry.id}
refineDisabled={!!refiningId && refiningId !== entry.id}
+ usage={usage?.[entry.id] || null}
/>
))}
</ul>
diff --git a/client/src/services/apiUniverseBuilder.js b/client/src/services/apiUniverseBuilder.js
index ae4510f355..43efa8f669 100644
--- a/client/src/services/apiUniverseBuilder.js
+++ b/client/src/services/apiUniverseBuilder.js
@@ -161,3 +161,10 @@ export const differentiateUniverseCast = (universeId, { providerId, model } = {}
method: 'POST',
body: JSON.stringify({ providerId, model }),
});
+
+// Cross-reference: where each canon entry appears across the universe's
+// linked series. Returns `{ characters: { [entryId]: [{seriesId, seriesName,
+// issueIds, issueCount}] }, settings: ..., objects: ..., seriesCount,
+// issueCount }`. Read-only aggregation.
+export const getUniverseCanonUsage = (universeId) =>
+ request(`/universe-builder/${encodeURIComponent(universeId)}/canon-usage`);
diff --git a/server/routes/universeBuilder.js b/server/routes/universeBuilder.js
index de47759fe8..bf2e5e1383 100644
--- a/server/routes/universeBuilder.js
+++ b/server/routes/universeBuilder.js
@@ -18,6 +18,7 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { validateRequest } from '../lib/validation.js';
import * as svc from '../services/universeBuilder.js';
import * as canonSvc from '../services/universeCanon.js';
+import { getUniverseCanonUsage } from '../services/canonUsage.js';
import { expandWorldTemplate } from '../services/universeBuilderExpand.js';
import { refineWorldPrompts } from '../services/universeBuilderRefine.js';
import { enqueueJob } from '../services/mediaJobQueue/index.js';
@@ -427,4 +428,14 @@ router.post('/:id/characters/differentiate-cast', asyncHandler(async (req, res)
res.json(result);
}));
+// Cross-reference: per-canon-entry usage across the universe's linked series.
+// Read-only aggregation; no LLM calls, no writes. Surfaces which series + how
+// many issues each character / place / object appears in, so the user can
+// see crossover/cameo footprint at a glance on the Universe Canon page.
+router.get('/:id/canon-usage', asyncHandler(async (req, res) => {
+ const result = await getUniverseCanonUsage(req.params.id)
+ .catch((err) => { throw mapServiceError(err); });
+ res.json(result);
+}));
+
export default router;
diff --git a/server/services/canonUsage.js b/server/services/canonUsage.js
new file mode 100644
index 0000000000..fd6dd2774d
--- /dev/null
+++ b/server/services/canonUsage.js
@@ -0,0 +1,111 @@
+// Cross-reference where each canon entry on a universe appears across the
+// series + issues that link to that universe. Pure aggregation over existing
+// stores — no new writes, no LLM calls. Match is by prose text scanning,
+// same pattern the comic-page renderer uses to decide which characters to
+// cite in the diffusion prompt.
+
+import { getUniverse } from './universeBuilder.js';
+import { listSeries } from './pipeline/series.js';
+import { listIssues } from './pipeline/issues.js';
+import {
+ matchCharactersInText, matchSettingsInText, matchObjectsInText,
+} from '../lib/scenePrompt.js';
+import { ServerError } from '../lib/errorHandler.js';
+
+const MATCHERS = Object.freeze({
+ characters: matchCharactersInText,
+ settings: matchSettingsInText,
+ objects: matchObjectsInText,
+});
+
+// Collect the searchable prose for an issue. Prose stage is the canonical
+// source the canon matchers were tuned against; idea + scripts are included
+// so a character that only ever appears in dialogue (no prose) still
+// surfaces in the cross-reference.
+function corpusForIssue(issue) {
+ const stages = issue.stages || {};
+ const parts = [
+ stages.prose?.output,
+ stages.prose?.input,
+ stages.idea?.output,
+ stages.idea?.input,
+ stages.comicScript?.output,
+ stages.tvScript?.output,
+ ];
+ return parts.filter(Boolean).join('\n\n');
+}
+
+/**
+ * Return per-canon-entry usage across the universe's series.
+ *
+ * Shape:
+ * {
+ * characters: { [entryId]: [{ seriesId, seriesName, issueIds, issueCount }, ...] },
+ * settings: { [entryId]: [...] },
+ * objects: { [entryId]: [...] },
+ * seriesCount, // how many series link to this universe
+ * issueCount, // total issues scanned
+ * }
+ */
+export async function getUniverseCanonUsage(universeId) {
+ const universe = await getUniverse(universeId).catch((err) => {
+ throw new ServerError(err.message || 'Universe not found', { status: 404, code: 'UNIVERSE_NOT_FOUND' });
+ });
+
+ const allSeries = await listSeries();
+ const linkedSeries = allSeries.filter((s) => s.universeId === universeId);
+
+ // Per (kind, entryId) → Map(seriesId → { seriesName, issueIds: Set })
+ const tally = { characters: new Map(), settings: new Map(), objects: new Map() };
+
+ let issueCount = 0;
+ for (const series of linkedSeries) {
+ const issues = await listIssues({ seriesId: series.id });
+ issueCount += issues.length;
+ for (const issue of issues) {
+ const corpus = corpusForIssue(issue);
+ if (!corpus.trim()) continue;
+ for (const kind of Object.keys(MATCHERS)) {
+ const canon = Array.isArray(universe[kind]) ? universe[kind] : [];
+ if (canon.length === 0) continue;
+ const matched = MATCHERS[kind](corpus, canon);
+ for (const entry of matched) {
+ const id = entry.id || entry.name;
+ if (!id) continue;
+ let perSeries = tally[kind].get(id);
+ if (!perSeries) {
+ perSeries = new Map();
+ tally[kind].set(id, perSeries);
+ }
+ let bucket = perSeries.get(series.id);
+ if (!bucket) {
+ bucket = { seriesName: series.name, issueIds: new Set() };
+ perSeries.set(series.id, bucket);
+ }
+ bucket.issueIds.add(issue.id);
+ }
+ }
+ }
+ }
+
+ const shape = (perKind) => {
+ const out = {};
+ for (const [entryId, perSeries] of perKind.entries()) {
+ out[entryId] = [...perSeries.entries()].map(([seriesId, { seriesName, issueIds }]) => ({
+ seriesId,
+ seriesName,
+ issueIds: [...issueIds],
+ issueCount: issueIds.size,
+ }));
+ }
+ return out;
+ };
+
+ return {
+ characters: shape(tally.characters),
+ settings: shape(tally.settings),
+ objects: shape(tally.objects),
+ seriesCount: linkedSeries.length,
+ issueCount,
+ };
+}