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

fix: share timeline fade fitting between preview and export

[._.]/ Adam Eivy4e891742f32a
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 11bde600af..5b0a308245 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -242,7 +242,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `universeGraphLayout.js` | 2D positioning for the Universe Builder graph canvas: `seedPositions` (deterministic phyllotaxis), `stepLayout`/`settleLayout` (force sim with per-kind collision radius), `applyAnchors` (radial rings by kind, timeline lanes by first appearance), `computeFit`, `toScreen`/`toWorld`, `hitTest`, `radiusFor`, `GRAPH_LAYOUTS`. Distinct from `graphSimulation.js`, which settles the Brain/CoS graphs in 3D with no anchors, collision or screen fit. |
| `universeGraphPoster.js` | Print-ready infographic posters drawn from an `indexGraph` result: `POSTER_LAYOUTS` (cast roster, character dossier, place atlas, timeline strip, relationship web), `POSTER_SIZES`, `POSTER_THEMES`, `posterDimensions`, and `renderPoster(canvas, opts)` — the same call drives the on-screen preview (scale 1) and the 2× PNG download, so they can't diverge. |
| `universeBuilderCounts.js` | Pure prompt-count helpers for the Universe Builder render buttons (#2374), mirroring the server's compile/skip rules so inline counts match what `/render` will enqueue: `totalVariationCount`, `canonEntryHasContent`, `countCanonWithContent`, `renderPromptCount`, `scopedPromptCount`. The server `compilePrompts`/`synthesizeCanonPrompt` copy is authoritative — keep in sync. |
-| `videoTimelineModel.js` | Pure model helpers for the layered video timeline, mirroring `server/services/videoTimeline/segments.js` so the browser preview and the ffmpeg export make the same cut/geometry/mix decisions: `segmentDuration`/`timelineDuration`/`findSegmentAt` (project-time ↔ segment mapping), `fadeMultiplier` (linear, matching ffmpeg's default `tri` curve), `overlayOpacityAt`, `audioTrackStateAt`, `segmentVolumeAt` (clipVolume × segment volume × fade — the product the export writes into each segment audio chain, so the preview auditions the mix that renders), `assetUrl(assetKind, assetFile)`, the edit clamps `clampTrim` (keeps ≥ 1 frame, matching the server's CLIP_TOO_SHORT floor) and `fitFadePatch` (shrinks an over-long fade pair proportionally instead of letting the PATCH 400), the index summary `projectSummary(project, thumbnailFor)` (block count / duration / card thumbnail — reads the `segments` lane, NEVER the derived `clips` mirror, which omits stills), and the save helpers `stripKey`/`withKeys`/`timelinePatch`. Change a rule here and in the server module in the same commit. |
+| `videoTimelineModel.js` | Pure model helpers for the layered video timeline, mirroring `server/services/videoTimeline/segments.js` so the browser preview and the ffmpeg export make the same cut/geometry/mix decisions: `segmentDuration`/`timelineDuration`/`findSegmentAt` (project-time ↔ segment mapping), `fadeMultiplier` (linear, matching ffmpeg's default `tri` curve), `overlayOpacityAt`, `audioTrackStateAt`, `segmentVolumeAt` (clipVolume × segment volume × fade — the product the export writes into each segment audio chain, so the preview auditions the mix that renders), `assetUrl(assetKind, assetFile)`, the edit clamps `clampTrim` (keeps ≥ 1 frame, matching the server's CLIP_TOO_SHORT floor) and `fitFadePatch` (shrinks an over-long fade pair proportionally instead of letting the PATCH 400), the index summary `projectSummary(project, thumbnailFor)` (block count / duration / card thumbnail — reads the `segments` lane, NEVER the derived `clips` mirror, which omits stills), and the save helpers `stripKey`/`withKeys`/`timelinePatch`. Change a rule here and in the server module in the same commit. Fade fitting re-exports the shared `server/lib/videoTimelineFades.js` leaf. |
| `wrSceneCursor.js` | Resolve which script scene the editor caret sits in (`sceneAtCursor`, `sceneAnchorIndex`) — inverse of WorkEditor's jump-to-scene text search; drives the live render preview's "scene at cursor" target. |
| `writingGuide.js` | Canonical Writers Room reference data + craft principles rendered by the Guide page (`/writers-room/guide`): `WRITING_LENGTH_TARGETS` (microfiction→novel word/char bands), `BOOK_LENGTH_ESTIMATES` (page-based), `WRITING_PRINCIPLES`, `PLANNED_ANALYSES` (e.g. the emotional-roadmap evaluator), and `classifyByWordCount(n)` for labelling a draft's length. Future word-count gauges / length checks read from here so targets don't drift from the docs. |
| `universeMarkdownFilename.js` | `slugifyUniverseName` / `universeMarkdownFilename` — client-side safe filename helpers for Universe Markdown world-bible downloads, kept in step with the server attachment name. |
diff --git a/client/src/lib/videoTimelineModel.js b/client/src/lib/videoTimelineModel.js
index 694563bd08..eddcb4bc7b 100644
--- a/client/src/lib/videoTimelineModel.js
+++ b/client/src/lib/videoTimelineModel.js
@@ -5,13 +5,17 @@
* the ffmpeg export make the SAME cut, geometry, and mix decisions — the whole
* point of the lane model is that what the editor shows is what renders. When
* a rule changes on one side (fade curve, overlay placement, asset kinds),
- * change it on the other in the same commit.
+ * change it on the other in the same commit. Fade fitting is shared through
+ * server/lib/videoTimelineFades.js rather than mirrored.
*
* No React, no I/O — safe to import from the page, its child components, and
* tests alike.
*/
import { clamp } from '../utils/formatters';
+import { fitFades } from '../../../server/lib/videoTimelineFades.js';
+
+export { fitFades } from '../../../server/lib/videoTimelineFades.js';
export const IMAGE_ASSET_KINDS = ['images', 'video-thumbnails'];
export const AUDIO_ASSET_KINDS = ['audio', 'music'];
@@ -75,21 +79,6 @@ export const fadeMultiplier = (fadeInSec, fadeOutSec, duration, within) => {
return Math.min(1, Math.max(0, m));
};
-/**
- * Shrink a fade pair that no longer fits `duration`, scaling both
- * proportionally so the author's balance survives. Mirrors `fitFades` in
- * server/services/videoTimeline/segments.js — the export and the preview must
- * compress an over-long pair the same way or they ramp differently.
- */
-export function fitFades(fadeInSec, fadeOutSec, duration) {
- const fin = Math.max(0, Number(fadeInSec) || 0);
- const fout = Math.max(0, Number(fadeOutSec) || 0);
- const span = fin + fout;
- if (span <= duration || span === 0) return { fadeInSec: fin, fadeOutSec: fout };
- const scale = Math.max(0, duration) / span;
- return { fadeInSec: fin * scale, fadeOutSec: fout * scale };
-}
-
/**
* Effective opacity of an overlay at project-time `t` — 0 outside its window,
* its configured opacity inside, scaled by whichever alpha fade is active.
@@ -183,8 +172,8 @@ export const withKeys = (entries, prefix) => (entries || []).map((e, idx) => ({
/**
* Shrink a fade pair that no longer fits its own duration, scaling both
- * proportionally so the author's balance survives. Mirrors the server's
- * `fitFades` (`server/services/videoTimeline/local.js`) — ffmpeg's `fade`
+ * proportionally so the author's balance survives. Uses the shared
+ * `fitFades` (`server/lib/videoTimelineFades.js`) — ffmpeg's `fade`
* renders the whole segment black when its start time goes negative, and the
* persist-time validator rejects an over-long pair outright, so the editor
* shrinks rather than letting the PATCH 400 mid-edit.
diff --git a/client/src/lib/videoTimelineModel.test.js b/client/src/lib/videoTimelineModel.test.js
index caa94e10fa..09ba82a2c1 100644
--- a/client/src/lib/videoTimelineModel.test.js
+++ b/client/src/lib/videoTimelineModel.test.js
@@ -1,6 +1,8 @@
// @vitest-environment node
import { describe, it, expect } from 'vitest';
+import { fitFades as sharedFitFades } from '../../../server/lib/videoTimelineFades.js';
+import { fitFades as previewFitFades } from './videoTimelineModel.js';
import {
assetUrl,
segmentDuration,
@@ -336,3 +338,9 @@ describe('overlay fade parity when the timeline clamps the window', () => {
expect(overlayOpacityAt(overlay, 7.5, 30)).toBe(0);
});
});
+
+describe('shared timeline fade contract', () => {
+ it('uses the export fade implementation for preview and trim edits', () => {
+ expect(previewFitFades).toBe(sharedFitFades);
+ });
+});
diff --git a/server/lib/README.md b/server/lib/README.md
index 35a5732389..2ded4ea349 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -625,3 +625,5 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and
| `creativeDirectorVideoCompiler.js` | `compileVideoArtifact` and `validateVideoShot` — pure timed-shot/source-reference compilation and pinned-backend compatibility shared by Creative Director project mutations and Video execution preflight. Storage, history and approval remain with their existing owners. |
| `providerTypes.js` | Pure shared `isCliProvider`, `isTuiProvider`, `isApiProvider`, `isProcessProvider`, and type-gated `isClaudeHarnessProvider` predicates. |
+
+| `videoTimelineFades.js` | Browser-safe `fitFades()` proportionally fits a fade pair to its visible duration. Shared by timeline normalization/export and the editor preview/trim controls; legacy import paths re-export it. |
diff --git a/server/lib/index.js b/server/lib/index.js
index 00d25258c2..b01d60dd67 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -606,3 +606,4 @@ export * from './creativeDirectorVideoReview.js';
export * from './creativeDirectorVideoCompiler.js';
export * from './providerTypes.js';
export * from './notificationTypes.js';
+export * from './videoTimelineFades.js';
diff --git a/server/lib/videoTimelineFades.js b/server/lib/videoTimelineFades.js
new file mode 100644
index 0000000000..4d7129b93e
--- /dev/null
+++ b/server/lib/videoTimelineFades.js
@@ -0,0 +1,17 @@
+/**
+ * Shrink a fade pair that no longer fits `duration`, scaling both
+ * proportionally so the author's balance survives. Non-throwing twin of
+ * `clampFades` in services/videoTimeline/segments.js: that one rejects an
+ * over-long pair at persist time, this one repairs a pair that a later change
+ * made too long (a probe-shortened bed, a
+ * legacy trim). ffmpeg's `fade` renders the whole segment black when its start
+ * time goes negative, so an unfitted pair is not a cosmetic problem.
+ */
+export function fitFades(fadeInSec, fadeOutSec, duration) {
+ const fin = Math.max(0, Number(fadeInSec) || 0);
+ const fout = Math.max(0, Number(fadeOutSec) || 0);
+ const span = fin + fout;
+ if (span <= duration || span === 0) return { fadeInSec: fin, fadeOutSec: fout };
+ const scale = Math.max(0, duration) / span;
+ return { fadeInSec: fin * scale, fadeOutSec: fout * scale };
+}
diff --git a/server/services/videoTimeline/segments.js b/server/services/videoTimeline/segments.js
index 888f712bdc..da15004c47 100644
--- a/server/services/videoTimeline/segments.js
+++ b/server/services/videoTimeline/segments.js
@@ -32,6 +32,9 @@ import { existsSync } from 'fs';
import { join, resolve as resolvePath, sep } from 'path';
import { PATHS, isTopLevelEntryName } from '../../lib/fileUtils.js';
import { ServerError } from '../../lib/errorHandler.js';
+import { fitFades } from '../../lib/videoTimelineFades.js';
+
+export { fitFades } from '../../lib/videoTimelineFades.js';
export const TIMELINE_SCHEMA_VERSION = 2;
@@ -50,22 +53,6 @@ export const AUDIO_ASSET_KINDS = ['audio', 'music'];
export const MAX_SEGMENTS = 200;
export const MAX_OVERLAYS = 50;
export const MAX_AUDIO_TRACKS = 20;
-/**
- * Shrink a fade pair that no longer fits `duration`, scaling both
- * proportionally so the author's balance survives. Non-throwing twin of
- * `clampFades`: that one rejects an over-long pair at persist time, this one
- * repairs a pair that a LATER change made too long (a probe-shortened bed, a
- * legacy trim). ffmpeg's `fade` renders the whole segment black when its start
- * time goes negative, so an unfitted pair is not a cosmetic problem.
- */
-export function fitFades(fadeInSec, fadeOutSec, duration) {
- const fin = Math.max(0, Number(fadeInSec) || 0);
- const fout = Math.max(0, Number(fadeOutSec) || 0);
- const span = fin + fout;
- if (span <= duration || span === 0) return { fadeInSec: fin, fadeOutSec: fout };
- const scale = Math.max(0, duration) / span;
- return { fadeInSec: fin * scale, fadeOutSec: fout * scale };
-}
export const MAX_FADE_SEC = 30;
export const MAX_STILL_SEC = 600;
diff --git a/server/services/videoTimeline/segments.test.js b/server/services/videoTimeline/segments.test.js
index a8f20a1517..98178a3b9e 100644
--- a/server/services/videoTimeline/segments.test.js
+++ b/server/services/videoTimeline/segments.test.js
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest';
+import { fitFades as sharedFitFades } from '../../lib/videoTimelineFades.js';
import {
TIMELINE_SCHEMA_VERSION,
normalizeProject,
@@ -244,6 +245,10 @@ describe('assetPathFor — a valid gallery basename must stay usable', () => {
});
describe('fitFades', () => {
+ it('preserves the legacy export as the shared fade implementation', () => {
+ expect(fitFades).toBe(sharedFitFades);
+ });
+
it('leaves a fitting pair alone', () => {
expect(fitFades(1, 1, 4)).toEqual({ fadeInSec: 1, fadeOutSec: 1 });
});