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
Merge origin/main into claude/autopilot-from-existing-song-hcitwp
Claude55edbbd29ab3
diff --cc client/src/lib/musicVideoStages.jsindex 26c9bf1c59,3600ef99cd..5fc5b3b486--- a/client/src/lib/musicVideoStages.js+++ b/client/src/lib/musicVideoStages.js@@@ -184,9 -184,69 +184,69 @@@ export function listPreviewSources(proj// A stopped run can be resumed as is; the others need the director first.const PRODUCTION_RUN_LABELS = {running: 'Production running', stopped: 'Production paused', blocked: 'Production blocked',- 'limit-reached': 'Production at its limit', 'needs-replan': 'Production needs a replan',+ 'limit-reached': 'Production at its limit', 'needs-replan': 'Production needs a replan', 'awaiting-video': 'Production stills done',};+ /**+ * One reading of the autonomous run for the header chip, the busy/resume action+ * and the Song checklist: `running`, `awaiting` (a checkpoint waits on the+ * director), `paused` (interrupted, stopped or needs attention), `failed`, or+ * `inactive` (none, finished or cancelled). While running, `step` is the current+ * step's label: the lyrics or song step, else the checkpoint stage's name.+ */+ function autonomousRunPhase(auto) {+ if (!auto || auto.status === 'completed' || auto.status === 'canceled') return { phase: 'inactive', step: null };+ if (auto.status === 'awaiting-approval') return { phase: 'awaiting', step: null };+ if (auto.status === 'running' && !auto.interrupted) {+ const step = auto.stages?.[auto.stage]?.step;+ return { phase: 'running', step: (auto.stage === 'lyrics' && AUTONOMOUS_LYRICS_STEP_LABELS[step])+ || (auto.stage === 'song' && AUTONOMOUS_SONG_STEP_LABELS[step])+ || AUTONOMOUS_CHECKPOINT_LABELS[auto.stage] || null };+ }+ return { phase: auto.status === 'failed' && !auto.interrupted ? 'failed' : 'paused', step: null };+ }++ const AUTONOMOUS_SONG_DETAILS = {+ running: 'The autonomous run is making the song.',+ awaiting: 'The autonomous run is waiting for your approval.',+ paused: 'The autonomous run is paused. Resume it to make the song.',+ };++ /** The Cast & Sets sheet's state: `absent`, `building`, `stopped`, `review` (check-in open) or `settled`. */+ function castSetsPhase(cast) {+ if (!cast) return 'absent';+ if (cast.status === 'review') return 'review';+ if (cast.interrupted || cast.status === 'failed') return 'stopped';+ return CAST_WORKING.has(cast.status) ? 'building' : 'settled';+ }++ /**+ * Scene footage gates Produce: a footage mode needs at least one scene and every+ * scene render-ready; modes that draw their own picture skip the gate.+ */+ function footageReady(project) {+ if (FOOTAGE_OPTIONAL_MODES.has(project?.composition?.mode || 'concat')) return true;+ const scenes = project?.scenes || [];+ const layered = isLayeredComposition(project);+ return scenes.length > 0 && scenes.every((scene) => sceneRenderReady(scene, { layered }));+ }++ /**+ * Whether the header sends the director to an approval panel: the project has a+ * track and analysis, something is left to approve (or a pilot proof is parked),+ * and nothing else owns the header (a render, kickoff, running production, the+ * Cast & Sets build, or a stage action of its own).+ */+ function shouldJumpToReview(project, { run, art, board, pilotParked, busy, ownAction }) {+ return !busy && !ownAction && !finishedOutside(project) && projectHasAudio(project) && !!project.audioAnalysis+ && !CAST_WORKING.has(project.castAndSets?.status) && (art || board || pilotParked) && run?.status !== 'running';+ }++ const autonomousChipLabel = (auto, { phase, step }) => {+ if (phase === 'running') return step ? `Autonomous run: ${step.toLowerCase()}` : 'Autonomous run running';+ return `Autonomous run ${auto.interrupted ? 'interrupted' : (AUTONOMOUS_STATUS_LABELS[auto.status] || auto.status).toLowerCase()}`;+ };+/*** What the header's Autopilot button says: the autonomous run's current step or* state, else a live or parked production run, else just "Autopilot". Tones are@@@ -368,6 -415,51 +415,51 @@@ export function deriveStages(project, rreturn { stages, current };}+ // The approval panel the header sends the director to: unwritten art direction is written on the step, not approved.+ function reviewProductionAction({ art, board, artUnwritten }) {+ if (artUnwritten) return { id: 'review-production', kind: 'goto', stage: 'cast-sets', anchor: ART_DIRECTION_ANCHOR, label: 'Write art direction', shortLabel: 'Write art' };+ return { id: 'review-production', kind: 'goto', stage: art ? 'cast-sets' : board ? 'board' : 'produce',+ anchor: art ? 'mv-review-art' : board ? 'mv-review-storyboard' : 'mv-review-proof',+ label: art ? 'Review art direction' : board ? 'Review timed storyboard' : 'Review pilot proof',+ shortLabel: art ? 'Review art' : board ? 'Review storyboard' : 'Review proof' };+ }++ // A live or parked production run offers Stop while it works, else Resume.+ function productionRunAction(run) {+ if (run.status === 'running' && !run.interrupted) return { id: 'stop-production', kind: 'run', label: 'Stop production', shortLabel: 'Stop', runId: run.id };+ const replan = run.status === 'needs-replan';- return { id: 'resume-production', kind: 'run', runId: run.id, acceptBasis: replan, label: replan ? 'Resume with new setup' : 'Resume production', shortLabel: 'Resume' };++ return { id: 'resume-production', kind: 'run', runId: run.id, acceptBasis: replan, label: replan ? 'Resume with new setup' : run.status === 'awaiting-video' ? 'Make the clips' : 'Resume production', shortLabel: 'Resume' };+ }++ // The header action for an autonomous run that still owns the project, or null once it is finished or cancelled.+ function autonomousNextAction(auto) {+ const { phase, step } = autonomousRunPhase(auto);+ if (phase === 'running') {+ const text = step || 'Autonomous run running';+ const busyLabel = text.endsWith('…') ? text : `${text}…`;+ return { id: 'busy', kind: 'run', label: busyLabel, shortLabel: busyLabel, disabled: true };+ }+ if (phase === 'awaiting') {+ const target = AUTONOMOUS_CHECKPOINT_LABELS[auto.awaiting] || auto.awaiting || 'checkpoint';+ // The checkpoint editor is in Project settings › Autopilot; the page opens it.+ return { id: 'review-autonomous', kind: 'open', label: `Review ${target}`, shortLabel: 'Review' };+ }+ if (phase === 'paused') return { id: 'resume-autonomous', kind: 'run', label: 'Resume autonomous run', shortLabel: 'Resume' };+ if (phase === 'failed') return { id: 'retry-autonomous', kind: 'run', label: 'Retry autonomous run', shortLabel: 'Retry' };+ return null;+ }++ // Publish: build the kit, then one platform at a time, never "publish everything": the next platform+ // not yet posted, so a click can't repeat a post that already went out.+ function publishNextAction(project, publish) {+ if (!project.publishKit?.builtAt) return { id: 'goto-publish', kind: 'goto', stage: 'publish', label: 'Build the publishing kit', shortLabel: 'Kit' };+ const { rows, total, posted } = publishPlatformProgress(project, publish);+ const next = rows.find((row) => row.state !== 'posted');+ return next+ ? { id: 'goto-publish', kind: 'goto', stage: 'publish', anchor: publishRowAnchor(next.target), label: `Next: post to ${next.label} · ${total - posted} left`, shortLabel: next.label }+ : { id: 'goto-publish', kind: 'goto', stage: 'publish', anchor: PUBLISH_ANCHOR, label: total ? 'All posted' : 'Open publishing', shortLabel: 'Publish' };+ }+/*** The single primary action the sticky header offers. `kind: 'run'` calls a* handler the page owns (keyed by `id`); `kind: 'open'` opens a Projectdiff --cc server/services/musicVideo/production.jsindex 3d04e32d67,b740494b53..6e41deda80--- a/server/services/musicVideo/production.js+++ b/server/services/musicVideo/production.js@@@ -393,6 -389,88 +393,88 @@@ function liveSlotJob(jobs, projectId, sconst slotSteps = (run, sceneId, stepKind, revisionId = null) => run.steps.filter((s) => s.sceneId === sceneId && s.kind === stepKind && (s.revisionId || null) === revisionId);+ /**+ * The attached full-song review's verdict on the run, or null when no review+ * is attached. A passing review still needs its dependencies unchanged; a+ * code-first run then renders the reviewed document before completing.+ */+ function reviewRunDisposition(project, run) {+ if (!run.reviewRunId) return null;+ const review = projectAutoReviews(project).find((r) => r.id === run.reviewRunId);+ if (!review) return { type: 'halt', status: 'needs-human', reason: 'The review run is gone — watch the draft yourself' };+ if (review.status === 'running') {+ const attempt = review.attempts?.[review.attempts.length - 1];+ if (run.authoring && attempt?.review?.verdict === 'revise') return { type: 'revise-document', reviewRunId: review.id, attemptN: attempt.n };+ return { type: 'wait', on: 'review' };+ }+ if (review.status === 'passed') {+ const evidence = review.attempts?.at(-1)?.review?.dependencies;+ if (musicVideoDependencyChanges(project, evidence).length) return { type: 'halt', status: 'needs-human', reason: 'The passing review has changed or unrecorded dependencies — rebuild and review the current draft' };+ if (!run.authoring) return { type: 'halt', status: 'completed', reason: null };+ if (run.documentCheckpoint?.directory !== project.composition?.document?.directory) return { type: 'halt', status: 'needs-replan', reason: 'The selected document changed after review — start a fresh run' };+ if (!run.finalRender) return { type: 'render-document' };+ if (run.finalRender.status === 'completed') return { type: 'halt', status: 'completed', reason: null };+ if (run.finalRender.status === 'failed') return { type: 'halt', status: 'blocked', reason: run.finalRender.error || 'The final document render failed — resume to retry' };+ return { type: 'wait', on: 'final-render' };+ }+ if (review.status === 'stopped' || review.status === 'limit-reached') {+ return { type: 'halt', status: review.status === 'limit-reached' ? 'limit-reached' : 'stopped', reason: `The review paused: ${review.stopReason || review.status}` };+ }+ return { type: 'halt', status: 'needs-human', reason: review.stopReason || `The review ended ${review.status}` };+ }++ /**+ * A pilot review that must hold the run before any more generation: one still+ * running, paused, or a current failing verdict. Returns null when none blocks.+ * Opening a pilot's review is NOT decided here — that waits until its media+ * exists, after generation (see nextProductionStep).+ */+ function blockingPilotReview(project, run, pendingPilots) {+ for (const pilot of pendingPilots) {+ const review = projectAutoReviews(project).find((r) => r.id === pilot.reviewRunId);+ if (review?.status === 'running') return { type: 'wait', on: 'pilot-review' };+ if (review && ['stopped', 'limit-reached'].includes(review.status)) return { type: 'halt', status: review.status, reason: review.stopReason || 'Pilot review paused; resume to continue' };+ const result = review?.attempts?.at(-1)?.review;+ const changes = result && musicVideoDependencyChanges(project, result.dependencies);+ if (result && (changes.some((change) => change.role === 'unknown')+ || (pilot.inputBasis === pilotInputBasis(project, pilot.sceneId) && !changes.length))) {+ if (result.verdict === 'inconclusive' && result.reviewedAt < run.resumedAt) continue;+ const exhausted = ['PRODUCTION_REVIEW_LIMIT', 'PRODUCTION_BUDGET_EXHAUSTED'].includes(result.providerErrorCode);+ const scene = (project.scenes || []).find((s) => s.sceneId === pilot.sceneId);+ return { type: 'halt', status: exhausted ? 'limit-reached' : 'blocked', reason: `Pilot ${pilot.sceneId}: ${result.reason || result.verdict}. ${pilotRepair(result, scene, project).reason}` };+ }+ }+ return null;+ }++ /**+ * The next frame/clip slot to generate (`dispatch`), a `halt` before a charge+ * that should not repeat, `{ waiting: true }` while slots are in flight, or+ * null when every target slot is filled. While pilots are pending, only their+ * scenes are considered.+ */+ function nextOpenGeneration(project, run, jobs, { pendingPilots, targets }) {+ let waiting = false;- for (const stepKind of ['frame', 'clip']) {++ for (const stepKind of run.stopBefore === 'clips' ? ['frame'] : ['frame', 'clip']) {+ for (const scene of targets[stepKind]) {+ if (pendingPilots.length && !pendingPilots.some((pilot) => pilot.sceneId === scene.sceneId)) continue;+ if (scene[SLOT[stepKind]]) continue;+ // A clip is generated from the scene's frame; wait for it.+ if (stepKind === 'clip' && !scene.referenceImageId) { waiting = true; continue; }+ const steps = slotSteps(run, scene.sceneId, stepKind);+ if (steps.some((s) => LIVE_STEP.has(s.status)) || liveSlotJob(jobs, project.id, scene.sceneId, stepKind)) { waiting = true; continue; }+ const refused = terminalRefusal(project, run, scene.sceneId, stepKind);+ if (refused) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" has a terminal ${stepKind} refusal (${refused.errorCode}). Change its inputs or resume with another supported route; Resume will not repeat it.` };+ // A paid failure is not evidence that the same operation will work next+ // time. Pause before another charge; explicit Resume permits a transient retry.+ const failed = steps.find((s) => s.status === 'failed' && !(run.retryAcknowledged || []).includes(s.key));+ if (failed) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" failed to generate its ${stepKind}. Inspect the failure and repair its inputs, or resume explicitly to retry.` };+ return { type: 'dispatch', kind: stepKind, sceneId: scene.sceneId };+ }+ }+ return waiting ? { waiting: true } : null;+ }+/*** Pure: what the run should do next, from the record and the queue alone:* `cast-and-sets` — the board is empty and no Cast & Sets check-in exists:@@@ -471,26 -517,9 +521,10 @@@ export function nextProductionStep(projconst gate = castAndSetsGate(project, run);if (gate) return { type: 'halt', status: 'blocked', reason: 'This selected performance shot needs the reviewed Cast & Sets references. Build and approve that check-in, then resume; production will not start an unbudgeted image batch.' };}- let waiting = false;- for (const stepKind of run.stopBefore === 'clips' ? ['frame'] : ['frame', 'clip']) {- for (const scene of targets[stepKind]) {- if (pendingPilots.length && !pendingPilots.some((pilot) => pilot.sceneId === scene.sceneId)) continue;- if (scene[SLOT[stepKind]]) continue;- // A clip is generated from the scene's frame; wait for it.- if (stepKind === 'clip' && !scene.referenceImageId) { waiting = true; continue; }- const steps = slotSteps(run, scene.sceneId, stepKind);- if (steps.some((s) => LIVE_STEP.has(s.status)) || liveSlotJob(jobs, project.id, scene.sceneId, stepKind)) { waiting = true; continue; }- const refused = terminalRefusal(project, run, scene.sceneId, stepKind);- if (refused) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" has a terminal ${stepKind} refusal (${refused.errorCode}). Change its inputs or resume with another supported route; Resume will not repeat it.` };- // A paid failure is not evidence that the same operation will work next- // time. Pause before another charge; explicit Resume permits a transient retry.- const failed = steps.find((s) => s.status === 'failed' && !(run.retryAcknowledged || []).includes(s.key));- if (failed) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" failed to generate its ${stepKind}. Inspect the failure and repair its inputs, or resume explicitly to retry.` };- return { type: 'dispatch', kind: stepKind, sceneId: scene.sceneId };- }- }- if (waiting) return { type: 'wait', on: 'generation' };+ const generation = nextOpenGeneration(project, run, jobs, { pendingPilots, targets });+ if (generation?.waiting) return { type: 'wait', on: 'generation' };+ if (generation) return generation;+ if (run.stopBefore === 'clips') return { type: 'halt', status: 'awaiting-video', reason: 'Every shot has its still. Resume to make the clips.' };if (pendingPilots.length) {const pilot = pendingPilots[0];const scene = scenes.find((s) => s.sceneId === pilot.sceneId);