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 (codex, claude): per-type catalog search + auto-cast spinner reset
Adam Eivy9caafcebe6a0
diff --git a/client/src/components/creative-director/OverviewTab.jsx b/client/src/components/creative-director/OverviewTab.jsxindex 3fbf10fd70..9c52b49815 100644--- a/client/src/components/creative-director/OverviewTab.jsx+++ b/client/src/components/creative-director/OverviewTab.jsx@@ -26,6 +26,10 @@ export default function OverviewTab({ project, onProjectUpdate }) {setDisableAudio(project.disableAudio === true);setSaving(false);savingRef.current = false;+ // Reset auto-cast spinner on project switch too — its .finally gates on the+ // id matching, so without this a same-instance project swap could strand the+ // flag (defensive; the parent currently remounts on id change).+ setAutoCasting(false);}, [project.id]);useEffect(() => {if (!savingRef.current) {diff --git a/server/services/creativeDirector/autoCast.js b/server/services/creativeDirector/autoCast.jsindex 8f5b0b87d4..654677d49a 100644--- a/server/services/creativeDirector/autoCast.js+++ b/server/services/creativeDirector/autoCast.js@@ -79,11 +79,26 @@ export async function suggestCastForBrief({ brief, types = DEFAULT_CASTABLE_TYPEif (!text) return [];const castable = Array.isArray(types) && types.length ? types : DEFAULT_CASTABLE_TYPES;const embedding = await generateQueryEmbedding(text, { types: castable }).catch(() => null);- // hybridSearchIngredients filters by a single `type`; fetch a wider unfiltered- // page and post-filter to the castable set so multiple types work in one query.- const hits = await hybridSearchIngredients(text, embedding, { limit: limit * 3 });- const allowed = new Set(castable);- return hits.filter((h) => allowed.has(h.ingredient?.type)).slice(0, limit);+ // hybridSearchIngredients filters by a SINGLE `type`, so query each castable+ // type and merge — post-filtering one global page would let a brief that+ // matches many non-castable items (ideas/concepts/custom types) fill the page+ // before any castable rows are reached, starving the cast candidates (codex+ // review). Per-type queries guarantee each castable type gets a fair page; one+ // failing type degrades to the rest rather than the whole search.+ const perType = await Promise.all(+ castable.map((type) => hybridSearchIngredients(text, embedding, { limit, type }).catch(() => [])),+ );+ // Types partition ingredient ids, but dedupe defensively (keep the best score).+ const byId = new Map();+ for (const hit of perType.flat()) {+ const id = hit?.ingredient?.id;+ if (!id) continue;+ const prev = byId.get(id);+ if (!prev || (hit.rrfScore || 0) > (prev.rrfScore || 0)) byId.set(id, hit);+ }+ return Array.from(byId.values())+ .sort((a, b) => (b.rrfScore || 0) - (a.rrfScore || 0))+ .slice(0, limit);}/**diff --git a/server/services/creativeDirector/autoCast.test.js b/server/services/creativeDirector/autoCast.test.jsindex 9e1f1dad6f..4a8e11470e 100644--- a/server/services/creativeDirector/autoCast.test.js+++ b/server/services/creativeDirector/autoCast.test.js@@ -33,6 +33,13 @@ const hit = (id, type, name, rrfScore = 0.5, searchMethod = 'hybrid') => ({searchMethod,});+// suggestCastForBrief now queries hybridSearchIngredients once per castable type,+// so the mock must honor the `type` filter (the real query does) — return only+// the rows whose ingredient.type matches the requested type.+const mockSearch = (rows) =>+ hybridSearchIngredients.mockImplementation(async (_q, _emb, { type } = {}) =>+ rows.filter((r) => !type || r.ingredient.type === type));+beforeEach(() => {vi.clearAllMocks();generateQueryEmbedding.mockResolvedValue([0.1, 0.2, 0.3]);@@ -68,7 +75,7 @@ describe('suggestCastForBrief', () => {});it('filters hits to the castable types and slices to the limit', async () => {- hybridSearchIngredients.mockResolvedValue([+ mockSearch([hit('c1', 'character', 'Mara'),hit('i1', 'idea', 'A loose notion'), // not castable by default → droppedhit('p1', 'place', 'The Spire'),@@ -79,14 +86,14 @@ describe('suggestCastForBrief', () => {});it('respects an explicit types override', async () => {- hybridSearchIngredients.mockResolvedValue([hit('c1', 'character', 'Mara'), hit('i1', 'idea', 'Notion')]);+ mockSearch([hit('c1', 'character', 'Mara'), hit('i1', 'idea', 'Notion')]);const out = await suggestCastForBrief({ brief: 'x', types: ['idea'] });expect(out.map((h) => h.ingredient.id)).toEqual(['i1']);});it('degrades to FTS-only when the embedding provider fails', async () => {generateQueryEmbedding.mockRejectedValue(new Error('no provider'));- hybridSearchIngredients.mockResolvedValue([hit('c1', 'character', 'Mara')]);+ mockSearch([hit('c1', 'character', 'Mara')]);const out = await suggestCastForBrief({ brief: 'rain noir' });expect(out).toHaveLength(1);// embedding arg is null when the provider failed@@ -124,7 +131,7 @@ describe('applyAutoCastToProject', () => {id: 'p1', name: 'Neon Run', styleSpec: 'rain noir', userStory: null,cast: [{ ingredientId: 'c1', name: 'Mara', type: 'character', role: 'cast' }],});- hybridSearchIngredients.mockResolvedValue([+ mockSearch([hit('c1', 'character', 'Mara'), // already cast → skippedhit('p1', 'place', 'The Spire'), // fresh → added]);@@ -148,7 +155,7 @@ describe('applyAutoCastToProject', () => {id: 'p1', name: 'Neon Run', styleSpec: 'rain noir',cast: [{ ingredientId: 'c1', name: 'Mara', type: 'character', role: 'cast' }],});- hybridSearchIngredients.mockResolvedValue([hit('c1', 'character', 'Mara')]);+ mockSearch([hit('c1', 'character', 'Mara')]);const result = await applyAutoCastToProject('p1', {});expect(result.added).toEqual([]);expect(updateProject).not.toHaveBeenCalled();@@ -157,7 +164,7 @@ describe('applyAutoCastToProject', () => {it('uses an explicit brief over the project-derived one', async () => {getProject.mockResolvedValue({ id: 'p1', name: 'Neon Run', styleSpec: 'rain noir', cast: [] });- hybridSearchIngredients.mockResolvedValue([]);+ mockSearch([]);await applyAutoCastToProject('p1', { brief: 'sunlit meadow' });expect(hybridSearchIngredients).toHaveBeenCalledWith('sunlit meadow', expect.anything(), expect.any(Object));});@@ -165,7 +172,7 @@ describe('applyAutoCastToProject', () => {it('caps the merged cast at 50 members', async () => {const existing = Array.from({ length: 49 }, (_, i) => ({ ingredientId: `e${i}`, name: `E${i}`, type: 'character', role: 'cast' }));getProject.mockResolvedValue({ id: 'p1', name: 'Neon Run', styleSpec: 'rain noir', cast: existing });- hybridSearchIngredients.mockResolvedValue([+ mockSearch([hit('n1', 'character', 'N1'), hit('n2', 'character', 'N2'), hit('n3', 'character', 'N3'),]);updateProject.mockImplementation(async (_id, patch) => ({ id: 'p1', ...patch }));