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 (claude, codex): live tags + prefill-race guard for image-gen
Adam Eivy488a1d27e905
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsxindex 7ec0492b34..7760e08fd3 100644--- a/client/src/pages/CatalogIngredient.jsx+++ b/client/src/pages/CatalogIngredient.jsx@@ -355,10 +355,10 @@ export default function CatalogIngredient() {const isUserType = typeDef.system === false;const badgeClass = CATALOG_BADGE_BY_ID[record.type] || 'bg-gray-500/20 text-gray-300 border-gray-500/40';// Prompt source for the Media panel's "Generate" affordance — derived from the- // currently-edited payload (+ tags) so tweaks to the description feed the next- // render's default prompt. The user can still edit the composed prompt before- // generating (#1809).- const genDescription = buildGenerationPromptSeed(payload, typeDef, record.tags);+ // currently-edited payload + the live `tags` state (NOT record.tags) so unsaved+ // tweaks to the description or tags feed the next render's default prompt. The+ // user can still edit the composed prompt before generating (#1809).+ const genDescription = buildGenerationPromptSeed(payload, typeDef, tags);// Group refs by kind for the "Appears in" panel. Tolerates either an array// of `{ refKind, refId, role }` or a server-grouped shape.@@ -910,9 +910,13 @@ function GenerateImageControl({ ingredientId, name, description, universeId, onCuniverse,});if (!mountedRef.current) return;+ // The textarea is editable during the (awaited) universe fetch, so the user+ // may have started typing before it resolved — apply the composed prefill+ // only when the field is still empty, via a functional updater that reads+ // the latest state (the closure's `prompt` is stale across the await).// Trim a dangling "Name:" when the ingredient had no visual description yet.- setPrompt((styled.prompt || name || '').replace(/:\s*$/, ''));- setNegativePrompt(styled.negativePrompt || '');+ setPrompt((cur) => (cur.trim() ? cur : (styled.prompt || name || '').replace(/:\s*$/, '')));+ setNegativePrompt((cur) => (cur.trim() ? cur : (styled.negativePrompt || '')));setPrefilling(false);};diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsxindex de2692eaf9..7594697536 100644--- a/client/src/pages/CatalogIngredient.test.jsx+++ b/client/src/pages/CatalogIngredient.test.jsx@@ -285,6 +285,62 @@ describe('CatalogIngredient — character sheet', () => {fireEvent.click(screen.getByText('Identity'));await waitFor(() => expect(screen.queryByDisplayValue('she/her')).toBeNull());});++ // The universe style-preset layering is the headline "stays on-model" feature+ // — pin that the linked universe is fetched by its refId and its embrace/avoid+ // tokens reach the composed prompt + negative, not just the null path.+ it('layers the linked universe style preset onto the composed prompt and negative', async () => {+ const { getUniverse } = await import('../services/apiUniverseBuilder');+ const { generateImage } = await import('../services/apiSystem');+ getUniverse.mockResolvedValue({+ influences: { embrace: ['neon noir', 'rain-slick streets'], avoid: ['cartoon', 'flat colors'] },+ });+ // No clearMocks config — clear prior tests' calls so calls[0] is this render's.+ generateImage.mockClear();+ generateImage.mockResolvedValue({ jobId: 'job-uni' });+ renderPage();+ await waitFor(() => expect(screen.getByDisplayValue('Sharp eyes, ink-stained cuffs.')).toBeTruthy());++ fireEvent.click(screen.getByRole('button', { name: /^Generate$/i }));+ const promptBox = await screen.findByPlaceholderText(/Describe the image to render/i);+ // Preset embrace tokens prepend the subject prompt (diffusion weights earliest+ // tokens heaviest) — see composeStyledPrompt.+ await waitFor(() => expect(promptBox.value).toMatch(/neon noir/));+ expect(promptBox.value).toMatch(/Ada Lovelace/);+ // Fetched by the ingredient's universe refId, silently (no error toast).+ expect(getUniverse).toHaveBeenCalledWith('u-1', { silent: true });++ fireEvent.click(screen.getByRole('button', { name: /^Render$/i }));+ await waitFor(() => expect(generateImage).toHaveBeenCalled());+ const [payload] = generateImage.mock.calls[0];+ expect(payload.prompt).toMatch(/neon noir/);+ // Universe avoid tokens become the render's negative prompt.+ expect(payload.negativePrompt).toMatch(/cartoon/);+ getUniverse.mockResolvedValue(null); // restore default for any later test+ });++ // Regression: the textarea is editable during the awaited universe fetch, so a+ // user typing before it resolves must NOT have their input clobbered by the+ // async prefill (codex review). Deferred getUniverse controls the race window.+ it('does not overwrite a prompt the user typed during the universe prefill', async () => {+ const { getUniverse } = await import('../services/apiUniverseBuilder');+ let resolveUniverse;+ getUniverse.mockImplementation(() => new Promise((res) => { resolveUniverse = res; }));+ renderPage();+ await waitFor(() => expect(screen.getByDisplayValue('Sharp eyes, ink-stained cuffs.')).toBeTruthy());++ fireEvent.click(screen.getByRole('button', { name: /^Generate$/i }));+ const promptBox = await screen.findByPlaceholderText(/Describe the image to render/i);+ // User types before the universe fetch resolves.+ fireEvent.change(promptBox, { target: { value: 'my hand-written prompt' } });+ // Now the fetch resolves with a universe whose preset would otherwise overwrite.+ resolveUniverse({ influences: { embrace: ['neon noir'], avoid: [] } });+ // The user's text survives — the prefill is skipped because the field is dirty.+ await waitFor(() => expect(screen.getByRole('button', { name: /^Render$/i })).toHaveProperty('disabled', false));+ expect(promptBox.value).toBe('my hand-written prompt');+ expect(promptBox.value).not.toMatch(/neon noir/);+ getUniverse.mockResolvedValue(null); // restore default+ });});describe('buildGenerationPromptSeed', () => {