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: organize music video page cards newest first
Adam Eivyab4863596e32
diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 33cb967d94..643dbf671f 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -64,7 +64,7 @@ grep -i "what you want to do" client/src/lib/README.md| `musicVideoLayers.js` | Music-video per-scene visual layers (#8985), re-exported from `server/lib/musicVideoLayers.js`: `MUSIC_VIDEO_VISUAL_LAYERS`, `MUSIC_VIDEO_STILL_MOVES`, `sceneVisualLayer(scene, { layered })`, `sceneHasAuthoredSpan`, `sceneRenderReady(scene, { layered })`. Used by `components/musicVideo/SceneCard.jsx`, `ProjectActionGroups.jsx` and `hooks/useMusicVideoSceneMedia.js`. || `musicVideoTakes.js` | Music-video scene takes view helpers (#8965): `sceneTakeList(scene, kind)` lists a scene's image/video takes with an un-materialized pre-takes selection appended as a read-only `legacy` take; `takePreviewKey`, `takeThumbUrl`, `takeProvenance`; `TAKE_SLOT` maps a take kind to its selection field. Used by `components/musicVideo/SceneTakeStrip.jsx` and `pages/MusicVideo.jsx`. || `musicVideoShotTiming.js` | Re-export of `server/lib/musicVideoShotTiming.js` (#8977) — shot modes, the verified source-audio lip-sync capability table, `performanceBlockedReason`, `planPerformanceRepair` (measured accepted-prefix boundary, suffix interval and next spend), `planPerformanceWindow`, `grokCoverage`, `approximateMotionCues`, `shotSplitLimit` (when a scene offers a lyric-boundary split), `falSceneTake` (a fal take's model, length, resolution and estimated cost). Used by `hooks/useMusicVideoSceneMedia.js` and `components/musicVideo/SceneCard.jsx`. |-| `musicVideoStages.js` | Music Video page stage model: `MUSIC_VIDEO_STAGES` (setup → cast-sets → board → produce → compose → review), `resolveStageParam(value)` for the `:stage` route param, `deriveStages(project)` (per-stage `done`/`active`/`blocked`/`todo` + `current`, the first incomplete stage; a live production run pins Produce), `deriveNextAction(project, ctx)` (the one primary action the sticky header offers — approve Cast & Sets, stop/resume production, render final, …), `projectSpend(project)` (paid generation used vs. cap), `projectShotSummary(project)` (document shots or scene counts), `stageChecklist(stageId, project, readiness)` (what one stage tab still needs, with the open approval's reason and a scroll anchor), `projectServicesSummary(project)` (the saved image/video render services), and `currentProductionRun`; `productionReviewStopGuidance` separates current approval blockers from historical run stops. Used by `components/musicVideo/MusicVideoLayout.jsx` and `pages/MusicVideo.jsx`. |+| `musicVideoStages.js` | Music Video page stage model: `MUSIC_VIDEO_STAGES` (setup → cast-sets → board → produce → compose → review), `resolveStageParam(value)` for the `:stage` route param, `deriveStages(project)` (per-stage `done`/`active`/`blocked`/`todo` + `current`, the first incomplete stage; a live production run pins Produce), `deriveNextAction(project, ctx)` (the one primary action the sticky header offers — approve Cast & Sets, stop/resume production, render final, …), `projectSpend(project)` (paid generation used vs. cap), `projectShotSummary(project)` (document shots or scene counts), `stageChecklist(stageId, project, readiness)` (what one stage tab still needs, with the open approval's reason and a scroll anchor), `projectServicesSummary(project)` (the saved image/video render services), `compareMusicVideoProjectsNewestFirst(a, b)` (sort projects newest created / updated first for project cards and pickers), and `currentProductionRun`; `productionReviewStopGuidance` separates current approval blockers from historical run stops. Used by `components/musicVideo/MusicVideoLayout.jsx` and `pages/MusicVideo.jsx`. || `musicVideoAttention.js` | Music Video "Needs attention" model (#9940): `deriveAttentionItems(project, live)` returns the banner rows for server-held states a client-orchestrated workflow can strand — an open/rendering revision, an interrupted Cast & Sets stage, a running auto-review waiting on its revised sections, a final render nobody is watching — derived from the persisted record so they survive a reload (healthy work this tab can see progressing is not flagged); `openRevisionOf(project)`; `ATTENTION_ANCHOR_ID` + `revealAttention()` scroll a refusal toast to the banner. Used by `components/musicVideo/NeedsAttentionBanner.jsx` and `pages/MusicVideo.jsx`. || `musicVideoPreview.js` | Pick the representative produced asset for a Music Video project card (`selectMusicVideoPreview`: final video → latest excerpt → latest rendered scene clip → latest scene reference frame → visual spec reference) for the main project grid. Pure, computed off the project record, with image path and fallback helpers (`musicVideoImageSrc`, `musicVideoImageFallback`). || `musicVideoUniverseRefs.js` | `pullUniverseCanonReferences(universe, existingReferences)` (#8978) maps a linked universe's characters/places/objects to visual-spec references (character/set/prop roles), skipping images already present and capping at `MUSIC_VIDEO_MAX_REFERENCES` (24, mirrors the server schema). Returns `{ next, added, skipped }`; the caller persists `next` via the ordinary visualSpec PATCH. Used by `components/musicVideo/VisualSpecPanel.jsx`. (The style snapshots are derived server-side, #9105.) |diff --git a/client/src/lib/musicVideoStages.js b/client/src/lib/musicVideoStages.jsindex db387ac1cf..c73221359c 100644--- a/client/src/lib/musicVideoStages.js+++ b/client/src/lib/musicVideoStages.js@@ -433,3 +433,22 @@ export function stageChecklist(stageId, project, readiness = project?.productionreturn [];}}++/**+ * Sort comparator to organize Music Video projects so the newest one is first.+ * Compares `createdAt` descending (newest created first), falling back to+ * `updatedAt` descending, and preserves relative order if neither is set.+ */+export function compareMusicVideoProjectsNewestFirst(a, b) {+ const aTime = Date.parse(a?.createdAt || a?.updatedAt) || 0;+ const bTime = Date.parse(b?.createdAt || b?.updatedAt) || 0;+ if (aTime !== bTime) {+ return bTime - aTime;+ }+ const aUpdated = Date.parse(a?.updatedAt) || 0;+ const bUpdated = Date.parse(b?.updatedAt) || 0;+ if (aUpdated !== bUpdated) {+ return bUpdated - aUpdated;+ }+ return 0;+}diff --git a/client/src/lib/musicVideoStages.test.js b/client/src/lib/musicVideoStages.test.jsindex 1c5da85b3e..a695d98d3f 100644--- a/client/src/lib/musicVideoStages.test.js+++ b/client/src/lib/musicVideoStages.test.js@@ -1,6 +1,6 @@import { describe, it, expect } from 'vitest';import {- MUSIC_VIDEO_STAGES, currentProductionRun, deriveNextAction, deriveStages, projectSpend, listPreviewSources, describeProjectStatus, resolveStageParam, stageChecklist,+ MUSIC_VIDEO_STAGES, currentProductionRun, deriveNextAction, deriveStages, projectSpend, listPreviewSources, describeProjectStatus, resolveStageParam, stageChecklist, compareMusicVideoProjectsNewestFirst,} from './musicVideoStages.js';const APPROVED = { art: { approved: true }, storyboard: { approved: true }, proof: { approved: true }, readyForProduction: true };@@ -289,3 +289,28 @@ describe('stageChecklist', () => {expect(stageChecklist('compose', castProject({ composition: { mode: 'composed', textCues: [] } }), APPROVED).map((i) => i.done)).toEqual([true, false]);});});++describe('compareMusicVideoProjectsNewestFirst', () => {+ it('sorts projects by createdAt descending so newest is first', () => {+ const p1 = { id: 'p1', createdAt: '2026-09-01T00:00:00.000Z' };+ const p2 = { id: 'p2', createdAt: '2026-10-01T00:00:00.000Z' };+ const p3 = { id: 'p3', createdAt: '2026-09-15T00:00:00.000Z' };+ const sorted = [p1, p2, p3].sort(compareMusicVideoProjectsNewestFirst);+ expect(sorted.map((p) => p.id)).toEqual(['p2', 'p3', 'p1']);+ });++ it('falls back to updatedAt descending when createdAt is absent or identical', () => {+ const p1 = { id: 'p1', createdAt: '2026-09-01T00:00:00.000Z', updatedAt: '2026-09-01T00:00:00.000Z' };+ const p2 = { id: 'p2', createdAt: '2026-09-01T00:00:00.000Z', updatedAt: '2026-09-02T00:00:00.000Z' };+ const pNoCreated = { id: 'p3', updatedAt: '2026-09-03T00:00:00.000Z' };+ const sorted = [p1, p2, pNoCreated].sort(compareMusicVideoProjectsNewestFirst);+ expect(sorted.map((p) => p.id)).toEqual(['p3', 'p2', 'p1']);+ });++ it('preserves order when neither project has timestamps', () => {+ const p1 = { id: 'p1', name: 'First' };+ const p2 = { id: 'p2', name: 'Second' };+ const sorted = [p1, p2].sort(compareMusicVideoProjectsNewestFirst);+ expect(sorted.map((p) => p.id)).toEqual(['p1', 'p2']);+ });+});diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsxindex 66ac072226..a1ec966898 100644--- a/client/src/pages/MusicVideo.jsx+++ b/client/src/pages/MusicVideo.jsx@@ -83,7 +83,7 @@ import { videoPosterForJob } from '../lib/creativeDirectorPreview.js';import { sceneTakeList } from '../lib/musicVideoTakes.js';import { deriveAttentionItems } from '../lib/musicVideoAttention.js';import {- productionReviewStopGuidance, approvalSummary, deriveNextAction, deriveStages, projectShotSummary, describeProjectStatus, listPreviewSources, projectSpend, resolveStageParam, stageChecklist,+ productionReviewStopGuidance, approvalSummary, deriveNextAction, deriveStages, projectShotSummary, describeProjectStatus, listPreviewSources, projectSpend, resolveStageParam, stageChecklist, compareMusicVideoProjectsNewestFirst,} from '../lib/musicVideoStages.js';import { AUTONOMOUS_STATUS_LABELS, AUTONOMOUS_VIEWABLE_STAGES } from '../lib/musicVideoAutonomous.js';@@ -180,6 +180,10 @@ export default function MusicVideo() {const renaming = !!selected && renamingId === selected.id;const [renameDraft, setRenameDraft] = useState('');const replaceProject = (next) => setProjects((prev) => prev.map((p) => (p.id === next.id ? next : p)));+ const sortedProjects = useMemo(+ () => [...projects].sort(compareMusicVideoProjectsNewestFirst),+ [projects],+ );const productionReview = useMusicVideoProductionReview({ project: selected, replaceProject });const progress = useMemo(() => deriveStages(selected, productionReview.readiness), [selected, productionReview.readiness]);const [openedStage, setOpenedStage] = useState({ id: null, stage: null });@@ -309,7 +313,8 @@ export default function MusicVideo() {setLoading(true);try {const data = await listMusicVideoProjects({ silent: true });- setProjects(data || []);+ const sorted = Array.isArray(data) ? [...data].sort(compareMusicVideoProjectsNewestFirst) : [];+ setProjects(sorted);setProjectsError(null);} catch (err) {setProjectsError(err?.message || 'Failed to load music video projects');@@ -364,7 +369,7 @@ export default function MusicVideo() {...(form.mode === 'autonomous' ? { automation: automationFromDraft(form.automation) } : {}),}, { silent: true }).then((proj) => {- setProjects((prev) => [...prev, proj]);+ setProjects((prev) => [proj, ...prev]);selectProject(proj.id);setForm(emptyCreateForm());setCreateOpen(false);@@ -409,7 +414,7 @@ export default function MusicVideo() {setCloningId(target.id);cloneMusicVideoProject(target.id, options, { silent: true }).then((project) => {- setProjects((prev) => [...prev, project]);+ setProjects((prev) => [project, ...prev]);navigate(`/music-video/${project.id}${songRevision === true ? "/setup" : ""}`);toast.success(`Created ${project.name}`);})@@ -581,7 +586,7 @@ export default function MusicVideo() {.then((target) => updateMusicVideoProject(target.id, patch, { silent: true }).then((proj) => ({ proj, forked: target !== selected }))).then(({ proj, forked }) => {if (forked) {- setProjects((prev) => [...prev, proj]);+ setProjects((prev) => [proj, ...prev]);navigate(`/music-video/${proj.id}/setup`);} else replaceProject(proj);if (cleared.length > 0) toast.success('Track changed — re-run Analyze and Align words');@@ -1047,7 +1052,7 @@ export default function MusicVideo() {className="min-w-0 w-full sm:w-72 bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm disabled:opacity-50"><option value="">{loading ? 'Loading projects…' : 'Select a project…'}</option>- {projects.map((project) => (+ {sortedProjects.map((project) => (<option key={project.id} value={project.id}>{project.name} · {projectShotSummary(project)} · {project.status}</option>@@ -1171,7 +1176,7 @@ export default function MusicVideo() {open={autonomousOpen}onClose={() => setAutonomousOpen(false)}onStarted={(proj) => {- setProjects((prev) => [...prev, proj]);+ setProjects((prev) => [proj, ...prev]);selectProject(proj.id);setAutonomousOpen(false);}}@@ -1219,7 +1224,7 @@ export default function MusicVideo() {</h2></div><div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4" data-testid="mv-project-grid">- {projects.map((project) => (+ {sortedProjects.map((project) => (<MusicVideoProjectCardkey={project.id}project={project}diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsxindex 4b16c1bff4..a47a004aa7 100644--- a/client/src/pages/MusicVideo.test.jsx+++ b/client/src/pages/MusicVideo.test.jsx@@ -2636,6 +2636,22 @@ describe('MusicVideo main page project cards', () => {});expect(deleteMusicVideoProject).toHaveBeenCalledWith(PROJECT_WITH_CLIP.id, { silent: true });});++ it('organizes project cards with the newest one first', async () => {+ const older = { ...PROJECT_WITH_CLIP, id: 'mv-old', name: 'Older Video', createdAt: '2026-09-01T00:00:00.000Z' };+ const middle = { ...PROJECT_NO_CLIP, id: 'mv-mid', name: 'Middle Video', createdAt: '2026-09-15T00:00:00.000Z' };+ const newest = { ...PROJECT_WITH_CLIP, id: 'mv-new', name: 'Newest Video', createdAt: '2026-10-01T00:00:00.000Z' };++ listMusicVideoProjects.mockResolvedValueOnce([older, middle, newest]);+ renderMV();++ const grid = await screen.findByTestId('mv-project-grid');+ const cards = within(grid).getAllByTestId(/^mv-project-card-/);+ expect(cards).toHaveLength(3);+ expect(cards[0]).toHaveAttribute('data-testid', 'mv-project-card-mv-new');+ expect(cards[1]).toHaveAttribute('data-testid', 'mv-project-card-mv-mid');+ expect(cards[2]).toHaveAttribute('data-testid', 'mv-project-card-mv-old');+ });});