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

Search Swap by the prompt each still and clip was made from (#11493)

[._.]/5b22d7888661
diff --git a/client/src/components/musicVideo/SceneTakePicker.jsx b/client/src/components/musicVideo/SceneTakePicker.jsx
index 795bcfea9a..6278d69419 100644
--- a/client/src/components/musicVideo/SceneTakePicker.jsx
+++ b/client/src/components/musicVideo/SceneTakePicker.jsx
@@ -3,7 +3,7 @@ import { X, Search, Film, Activity, Star, Ban, Trash2 } from 'lucide-react';
import Modal from '../ui/Modal.jsx';
import TabPills from '../ui/TabPills.jsx';
import InfiniteScrollFooter from '../ui/InfiniteScrollFooter.jsx';
-import { deleteMusicVideoPoolAssets, getMusicVideoMediaPool, markMusicVideoPoolAssets } from '../../services/apiMusicVideo.js';
+import { deleteMusicVideoPoolAssets, getMusicVideoMediaPool, markMusicVideoPoolAssets, searchMusicVideoMediaPool } from '../../services/apiMusicVideo.js';
import { takeThumbUrl, takeClipUrl } from '../../lib/musicVideoTakes.js';
import { formatCount } from '../../utils/formatters.js';
@@ -45,11 +45,15 @@ const usedLabel = (item, shotNumbers) => {
const CHIP = 'min-h-[44px] rounded border px-2 text-xs sm:min-h-[28px]';
const ACTION = 'inline-flex min-h-[44px] items-center gap-1 rounded border border-port-border px-3 text-xs disabled:opacity-50 sm:min-h-[32px]';
-/** Items of one kind matching a search over their prompt, or a shot number ("12" or "#12"). */
-export function filterPool(items, { kind, query, shotNumbers }) {
+/**
+ * Items of one kind matching a search over their prompt, or a shot number ("12" or "#12").
+ * `matches` holds the keys the server's prompt search found (the prompt each file was made from).
+ */
+export function filterPool(items, { kind, query, shotNumbers, matches = null }) {
const needle = query.trim().toLowerCase().replace(/^#/, '');
return items.filter((item) => item.kind === kind && (!needle
|| String(item.prompt || '').toLowerCase().includes(needle)
+ || matches?.has(poolKey(item))
|| (item.sceneId && String(shotNumbers.get(item.sceneId) ?? '') === needle)));
}
@@ -76,6 +80,7 @@ export default function SceneTakePicker({ open, onClose, projectId, scene, kind,
const [markFilter, setMarkFilter] = useState('all');
const [confirmDelete, setConfirmDelete] = useState(null);
const [working, setWorking] = useState(false);
+ const [matches, setMatches] = useState(null);
// The shot's frame in the other slot always sits on This shot, so the picker opens there when it has one.
const hasOwnFrame = !!otherFrameItem(scene, kind);
@@ -96,12 +101,27 @@ export default function SceneTakePicker({ open, onClose, projectId, scene, kind,
return () => { active = false; };
}, [open, projectId, scene.sceneId, kind, hasOwnFrame]);
+ // Typing searches the prompts each still and clip was made from, after a short pause.
+ useEffect(() => {
+ const q = query.trim();
+ setMatches(null);
+ if (!open || !q) return undefined;
+ let active = true;
+ const timer = setTimeout(() => {
+ searchMusicVideoMediaPool(projectId, q, { silent: true })
+ .then((res) => { if (active) setMatches(new Set((res.items || []).map(poolKey))); })
+ // A failed search leaves the matches on the prompts already shown here.
+ .catch(() => { if (active) setMatches(new Set()); });
+ }, 300);
+ return () => { active = false; clearTimeout(timer); };
+ }, [open, projectId, query]);
+
const own = pool ? otherFrameItem(scene, kind) : null;
// What already fills this slot isn't offered back; a frame other shots use is, marked with where it's used.
const current = scene[SLOT_FIELD[kind]];
const offered = pool ? pool.filter((item) => (!own || poolKey(item) !== poolKey(own)) && !(item.kind === POOL_KIND[kind] && item.assetId === current)) : [];
const ofKind = pool ? filterPool([...(own ? [own] : []), ...offered],
- { kind: POOL_KIND[kind], query, shotNumbers }) : [];
+ { kind: POOL_KIND[kind], query, shotNumbers, matches }) : [];
const counts = { shot: 0, others: 0, floor: 0 };
for (const item of ofKind) counts[poolGroup(item, scene.sceneId)] += 1;
const activeGroup = group;
@@ -215,7 +235,7 @@ export default function SceneTakePicker({ open, onClose, projectId, scene, kind,
{error && <p role="alert" className="text-xs text-port-error">{error}</p>}
{!pool && !error && <p className="flex items-center gap-2 text-xs text-port-text-muted"><Activity size={14} className="animate-spin" />Gathering every {itemNoun} made for this video…</p>}
{pool && items.length === 0 && (
- <p className="text-xs text-port-text-muted">{query ? `No ${itemNoun}s match.` : `No ${itemNoun}s here.`}</p>
+ <p className="text-xs text-port-text-muted">{query ? (matches ? `No ${itemNoun}s match.` : 'Searching prompts…') : `No ${itemNoun}s here.`}</p>
)}
<ul className="grid grid-cols-3 gap-2 sm:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8" aria-label={`${itemNoun[0].toUpperCase()}${itemNoun.slice(1)}s`}>
{items.slice(0, shown).map((item) => {
diff --git a/client/src/components/musicVideo/SceneTakePicker.test.jsx b/client/src/components/musicVideo/SceneTakePicker.test.jsx
index 2c0e6bb352..5caa5fe436 100644
--- a/client/src/components/musicVideo/SceneTakePicker.test.jsx
+++ b/client/src/components/musicVideo/SceneTakePicker.test.jsx
@@ -6,12 +6,14 @@ const pool = [
{ kind: 'image', assetId: 'other.png', sceneId: 's12', prompt: 'Splicer close-up', clipIds: ['clip-12'] },
{ kind: 'image', assetId: 'floor.png', sceneId: null, prompt: 'Reel on the floor', clipIds: [] },
{ kind: 'image', assetId: 'blurry.png', sceneId: null, prompt: 'Out of focus', clipIds: [], mark: 'bad' },
+ { kind: 'image', assetId: 'bird.png', sceneId: null, prompt: null, clipIds: [] },
{ kind: 'video', assetId: 'clip-12', sceneId: 's12', sourceImageId: 'other.png' },
];
vi.mock('../../services/apiMusicVideo.js', () => ({
getMusicVideoMediaPool: vi.fn(async () => ({ items: pool })),
markMusicVideoPoolAssets: vi.fn(async () => ({})),
deleteMusicVideoPoolAssets: vi.fn(async () => ({ deleted: 1 })),
+ searchMusicVideoMediaPool: vi.fn(async () => ({ items: [] })),
}));
const { default: SceneTakePicker } = await import('./SceneTakePicker.jsx');
const api = await import('../../services/apiMusicVideo.js');
@@ -38,6 +40,16 @@ describe('Swap from unused', () => {
expect(screen.getAllByRole('listitem')).toHaveLength(1);
});
+ // Uniquely catches Swap's search missing a still whose prompt only the file itself carries (no take left to hold it).
+ it('finds a floor still by the prompt it was made from', async () => {
+ api.searchMusicVideoMediaPool.mockResolvedValueOnce({ items: [{ kind: 'image', assetId: 'bird.png' }] });
+ render(<SceneTakePicker open projectId="mv-1" scene={{ sceneId: 's8' }} kind="image" onPlace={vi.fn()} shotNumbers={new Map([['s8', 8]])} />);
+ fireEvent.click(await screen.findByRole('tab', { name: /Floor/ }));
+ fireEvent.change(screen.getByLabelText('Search prompts or shot number'), { target: { value: 'Falcon' } });
+ await waitFor(() => expect(api.searchMusicVideoMediaPool).toHaveBeenCalledWith('mv-1', 'Falcon', { silent: true }));
+ await waitFor(() => expect(screen.getAllByRole('listitem')).toHaveLength(1));
+ });
+
// Uniquely catches a mark that never reaches the server, a Bad filter that misses a mark, or a delete that skips its confirm.
it('marks a floor still as an ingredient, and deletes the bad ones after a confirm', async () => {
render(<SceneTakePicker open projectId="mv-1" scene={{ sceneId: 's8' }} kind="image" onPlace={vi.fn()} shotNumbers={new Map([['s8', 8]])} />);
diff --git a/client/src/services/apiMusicVideo.js b/client/src/services/apiMusicVideo.js
index d560ddbba9..f51f211ce2 100644
--- a/client/src/services/apiMusicVideo.js
+++ b/client/src/services/apiMusicVideo.js
@@ -178,6 +178,9 @@ export const selectMusicVideoSceneTake = (id, sceneId, takeId, options = {}) =>
request(`${takesPath(id, sceneId)}/${encodeURIComponent(takeId)}/select`, { method: 'POST', ...options });
// The project's unused stills and clips (the shot card's "Swap from unused") → { collectionId, items }.
export const getMusicVideoMediaPool = (id, options = {}) => request(`/music-video/${encodeURIComponent(id)}/media-pool`, options);
+/** Swap's prompt search: `{ items: [{ kind, assetId }] }`, the pool items whose prompts hold every word. */
+export const searchMusicVideoMediaPool = (id, q, options = {}) =>
+ request(`/music-video/${encodeURIComponent(id)}/media-pool/search?q=${encodeURIComponent(q)}`, options);
/** The cutting room floor outro's tally for a video: `{ stats }`. */
export const getMusicVideoOutroStats = (id, options = {}) => request(`/music-video/${encodeURIComponent(id)}/stats-outro`, options);
// Asset manager: mark unused pool items ★ 'ingredient' / ✕ 'bad' (null clears) → { assetMarks }.
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index 64930a62fd..a5328f15e8 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -332,6 +332,11 @@ const musicVideoPoolAssetSchema = z.object({
if (!parsed.success) ctx.addIssue({ code: 'custom', path: ['assetId'], message: parsed.error.issues[0].message });
});
+/** A search over a video's media pool by the prompts its stills and clips were made from. */
+export const musicVideoPoolSearchQuerySchema = z.object({
+ q: z.string().trim().min(1).max(200),
+}).strict();
+
/** ★ ingredient (good, not placed) or ✕ bad (to clean up); null clears the mark. */
export const musicVideoPoolMarkSchema = z.object({
items: z.array(musicVideoPoolAssetSchema).min(1).max(500),
diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.js
index 610ac5caa0..8afbc68757 100644
--- a/server/routes/musicVideo.js
+++ b/server/routes/musicVideo.js
@@ -12,7 +12,7 @@ import { existsSync } from 'fs';
import { unlink } from 'fs/promises';
import { pipeline } from 'stream/promises';
import { Router } from 'express';
-import { musicVideoSongStyleSunoSchema, musicVideoProjectListQuerySchema, musicVideoFinishedOutsideSchema, musicVideoProductionDraftSchema, musicVideoProductionApprovalSchema, musicVideoShotLockSchema, musicVideoProductionProofSchema, musicVideoProductionImportSchema, musicVideoContinueShotSchema, musicVideoPoolUseSchema, musicVideoPoolMarkSchema, musicVideoPoolDeleteSchema, musicVideoProductionFeedbackSchema, musicVideoProductionFeedbackResolutionSchema, musicVideoLyricAnchorSyncSchema, musicVideoProductionReviseSchema, musicVideoProductionRevertSchema } from '../lib/musicVideoValidation.js';
+import { musicVideoSongStyleSunoSchema, musicVideoProjectListQuerySchema, musicVideoFinishedOutsideSchema, musicVideoProductionDraftSchema, musicVideoProductionApprovalSchema, musicVideoShotLockSchema, musicVideoProductionProofSchema, musicVideoProductionImportSchema, musicVideoContinueShotSchema, musicVideoPoolUseSchema, musicVideoPoolMarkSchema, musicVideoPoolSearchQuerySchema, musicVideoPoolDeleteSchema, musicVideoProductionFeedbackSchema, musicVideoProductionFeedbackResolutionSchema, musicVideoLyricAnchorSyncSchema, musicVideoProductionReviseSchema, musicVideoProductionRevertSchema } from '../lib/musicVideoValidation.js';
import { productionReadiness } from '../services/musicVideo/productionReview.js';
import { finishedOutsideBlocker } from '../lib/musicVideoFinishedOutside.js';
import { getProductionReview, saveProductionDraft, prepareProductionReview, approveProductionReview, lockProductionShots, renderProductionProof, requireProductionReviewer, importProductionPlanning, bindProductionShot, addProductionFeedback, closeProductionFeedback, syncLyricAnchors, reviseProductionFromFeedback, revertProductionInput } from '../services/musicVideo/productionReviewService.js';
@@ -1558,6 +1558,15 @@ router.get('/:id/media-pool', asyncHandler(async (req, res) => {
res.json(await getMusicVideoMediaPool(project));
}));
+// Swap's search: the pool items whose prompts (the shot's text and the prompt each file was made from) hold the words.
+router.get('/:id/media-pool/search', asyncHandler(async (req, res) => {
+ const { q } = validateRequest(musicVideoPoolSearchQuerySchema, req.query);
+ const project = await getProject(req.params.id);
+ if (!project) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });
+ const { searchMusicVideoMediaPool } = await import('../services/musicVideo/mediaPool.js');
+ res.json({ items: await searchMusicVideoMediaPool(project, q) });
+}));
+
// The cutting room floor outro's tally: what was made, kept and turned down for this video.
router.get('/:id/stats-outro', asyncHandler(async (req, res) => {
const project = await getProject(req.params.id);
diff --git a/server/routes/musicVideoTakes.test.js b/server/routes/musicVideoTakes.test.js
index 4001272bf9..5a7a77843f 100644
--- a/server/routes/musicVideoTakes.test.js
+++ b/server/routes/musicVideoTakes.test.js
@@ -395,6 +395,25 @@ describe('renders made for a video with no shot', () => {
});
});
+describe('Swap\'s prompt search', () => {
+ // Uniquely catches a still on the floor (no take left to carry its prompt) or a clip missing from a search for words in its prompt.
+ it('matches every word against each file\'s own prompt, ignoring case', async () => {
+ for (const name of ['falcon.png', 'street.png']) seedImage(name);
+ writeFileSync(join(ROOT(), 'images', 'falcon.metadata.json'), JSON.stringify({ prompt: 'A Falcon tattoo on her forearm, grainy 16mm' }));
+ writeFileSync(join(ROOT(), 'images', 'street.metadata.json'), JSON.stringify({ prompt: 'A wet street at night' }));
+ seedVideoHistory([{ id: 'falcon-clip', filename: 'falcon-clip.mp4', prompt: 'The falcon tattoo flexes as she grips the wheel' }]);
+ await addTake(sceneB.sceneId, { kind: 'image', assetId: 'falcon.png', source: 'generated' });
+ await addTake(sceneB.sceneId, { kind: 'image', assetId: 'street.png', source: 'generated' });
+ await addTake(sceneB.sceneId, { kind: 'video', assetId: 'falcon-clip', source: 'generated' });
+ // Cut shot B: its files land on the floor, where only the files themselves still name a prompt.
+ await request(app).delete(`${base()}/scenes/${sceneB.sceneId}`);
+ const search = (q) => request(app).get(`${base()}/media-pool/search?q=${encodeURIComponent(q)}`);
+ expect((await search('FALCON tattoo')).body.items).toEqual(expect.arrayContaining([{ kind: 'image', assetId: 'falcon.png' }, { kind: 'video', assetId: 'falcon-clip' }]));
+ expect((await search('falcon street')).body.items).toEqual([]);
+ expect((await search('')).status).toBe(400);
+ });
+});
+
describe('the shot asset manager', () => {
// Uniquely catches a take rejected from one shot reading as bad in Swap, where another shot may want it.
it('lists a take rejected from its shot as not bad until the director marks it', async () => {
diff --git a/server/services/musicVideo/mediaPool.js b/server/services/musicVideo/mediaPool.js
index e5be549f23..3243a8bcf1 100644
--- a/server/services/musicVideo/mediaPool.js
+++ b/server/services/musicVideo/mediaPool.js
@@ -230,6 +230,26 @@ export async function getMusicVideoMediaPool(project) {
return { collectionId: collection?.id || null, items };
}
+/**
+ * The pool items (`{ kind, assetId }`) whose prompts hold every word of `query`, case-insensitively:
+ * the take's prompt, the prompt saved beside a still (its image sidecar) and a clip's history prompt.
+ * Swap searches here because a still on the floor has no take left to carry its prompt.
+ */
+export async function searchMusicVideoMediaPool(project, query) {
+ const words = String(query).toLowerCase().split(/\s+/).filter(Boolean);
+ if (!words.length) return [];
+ const [{ items }, { loadHistory }, { readImageSidecar }] = await Promise.all([
+ getMusicVideoMediaPool(project), import('../videoGen/history.js'), import('../imageGen/local.js'),
+ ]);
+ const history = new Map((await loadHistory()).filter((entry) => entry?.id).map((entry) => [entry.id, entry]));
+ const sidecarPrompt = (assetId) => readImageSidecar(assetId)
+ .then(({ metadata }) => (typeof metadata?.prompt === 'string' ? metadata.prompt : '')).catch(() => '');
+ const texts = await Promise.all(items.map(async (item) => [item.prompt || '',
+ item.kind === 'video' ? history.get(item.assetId)?.prompt || '' : await sidecarPrompt(item.assetId)].join('\n').toLowerCase()));
+ return items.filter((_, index) => words.every((word) => texts[index].includes(word)))
+ .map(({ kind, assetId }) => ({ kind, assetId }));
+}
+
/**
* After stills or clips (`<image|video>:<ref>` keys) are deleted from the
* media library: forget them on every music video that held them (unused