@open-take/compositor 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,8 @@ import {
10
10
  isDragging,
11
11
  gradientEndpoints,
12
12
  smoother,
13
+ carryWindow,
14
+ ghostCardLines,
13
15
  } from "../math";
14
16
  import comp from "./.composition.json";
15
17
 
@@ -112,19 +114,25 @@ export default makeScene2D("take", function* (view) {
112
114
  </Rect>
113
115
 
114
116
  {/* click ripples — pointer-landing beats only (scroll/press have no
115
- spatial click point, so they get no ripple) */}
117
+ spatial click point). A dropFiles ripples at its DROP point on
118
+ RELEASE — not at the off-content carry entry — and stays on even when
119
+ the ghost card is disabled (parity with the editor preview). */}
116
120
  {comp.events
117
121
  .filter((e) => e.kind !== "scroll" && e.kind !== "press")
118
122
  .map((e, index) => {
119
123
  const ms = comp.cursor.rippleMs / 1000;
124
+ const at =
125
+ e.kind === "dropFiles"
126
+ ? { t0: carryWindow(e, comp).t1, p: e.to ?? e.point }
127
+ : { t0: e.tMs / 1000, p: e.point };
120
128
  const prog = () => {
121
- const dt = t() - e.tMs / 1000;
129
+ const dt = t() - at.t0;
122
130
  return dt >= 0 && dt <= ms ? dt / ms : -1;
123
131
  };
124
132
  return (
125
133
  <Circle
126
134
  key={`${e.kind}-${e.tMs}-${index}`}
127
- position={[lx(e.point.x), ly(e.point.y)]}
135
+ position={[lx(at.p.x), ly(at.p.y)]}
128
136
  size={() => {
129
137
  const p = prog();
130
138
  return p < 0 ? 0 : (12 + 60 * smoother(p)) * 2;
@@ -139,6 +147,81 @@ export default makeScene2D("take", function* (view) {
139
147
  );
140
148
  })}
141
149
 
150
+ {/* file ghost card — a macOS-style translucent file card riding the
151
+ cursor through a dropFiles carry, popping/fading on release. Drawn
152
+ UNDER the cursor node so the pointer stays on top. Mirrored in the
153
+ editor preview (preview.ts) — keep cosmetics in step. */}
154
+ {comp.events
155
+ .filter((e) => e.kind === "dropFiles" && e.ghostCard?.enabled !== false)
156
+ .map((e, index) => {
157
+ const gk = vW / 1920; // card is authored for a 1920-wide video
158
+ const gc = e.ghostCard ?? {};
159
+ const off = gc.offset ?? { x: 26 * gk, y: 30 * gk };
160
+ const win = carryWindow(e, comp);
161
+ const releaseS = (gc.releaseMs ?? 280) / 1000;
162
+ const fadeS = 0.15;
163
+ const lines = ghostCardLines(e.files ?? []);
164
+ const vis = () => {
165
+ const tt = t();
166
+ if (tt < win.t0 - fadeS || tt > win.t1 + releaseS) return 0;
167
+ if (tt < win.t0) return (tt - (win.t0 - fadeS)) / fadeS;
168
+ if (tt <= win.t1) return 1;
169
+ return 1 - (tt - win.t1) / releaseS;
170
+ };
171
+ // the release pop: a slight grow as the card lets go of the file
172
+ const pop = () => {
173
+ const tt = t();
174
+ const z =
175
+ tt <= win.t1 ? 1 : 1 + 0.08 * smoother(Math.min(1, (tt - win.t1) / releaseS));
176
+ return [z, z];
177
+ };
178
+ return (
179
+ <Node key={`ghostCard-${e.tMs}-${index}`}>
180
+ <Node
181
+ position={() => {
182
+ const c = cursorPos(t(), legs, comp);
183
+ return [lx(c.x) + off.x, ly(c.y) + off.y];
184
+ }}
185
+ opacity={vis}
186
+ scale={pop}
187
+ >
188
+ <Rect
189
+ layout
190
+ direction={"column"}
191
+ alignItems={"start"}
192
+ padding={[11 * gk, 16 * gk]}
193
+ gap={3 * gk}
194
+ radius={10 * gk}
195
+ offset={[-1, -1]}
196
+ fill={"rgba(24,24,27,0.86)"}
197
+ stroke={"rgba(255,255,255,0.22)"}
198
+ lineWidth={1}
199
+ shadowColor={"rgba(0,0,0,0.45)"}
200
+ shadowBlur={26 * gk}
201
+ shadowOffset={[0, 8 * gk]}
202
+ >
203
+ <Txt
204
+ text={lines.title}
205
+ fontFamily={"ui-monospace, 'SF Mono', Menlo, Consolas, monospace"}
206
+ fontSize={21 * gk}
207
+ fontWeight={600}
208
+ fill={"rgba(255,255,255,0.95)"}
209
+ />
210
+ {lines.meta ? (
211
+ <Txt
212
+ text={lines.meta}
213
+ fontFamily={"system-ui, -apple-system, 'Segoe UI', 'Noto Sans', sans-serif"}
214
+ fontSize={16 * gk}
215
+ fontWeight={500}
216
+ fill={"rgba(255,255,255,0.55)"}
217
+ />
218
+ ) : null}
219
+ </Rect>
220
+ </Node>
221
+ </Node>
222
+ );
223
+ })}
224
+
142
225
  {/* synthetic cursor on ground-truth waypoints */}
143
226
  <Node
144
227
  position={() => {
package/src/types.ts CHANGED
@@ -102,13 +102,33 @@ export type CapturePress = CaptureEventBase & {
102
102
  durationMs: number;
103
103
  };
104
104
 
105
+ /** A file drag-and-drop (OS-level, synthesized via CDP Input.dispatchDragEvent
106
+ * with real file paths): the cursor carries the file(s) from the anchor
107
+ * (`x,y`) along `path` to `to`, where the drop lands and the page receives
108
+ * actual Files. The compositor draws a "file ghost card" riding the cursor
109
+ * for this beat — the recording itself shows only the page's reaction. */
110
+ export type CaptureDropFiles = CaptureEventBase & {
111
+ kind: "dropFiles";
112
+ /** drop point, viewport CSS px */
113
+ to: { x: number; y: number };
114
+ /** full polyline incl. ends, viewport CSS px */
115
+ path?: { x: number; y: number }[];
116
+ /** ms the carry occupies on screen (ground-truth wall time) */
117
+ durationMs: number;
118
+ /** carry pacing baked into the dispatched dragOver march (see CaptureDrag) */
119
+ ease?: "linear" | "smooth";
120
+ /** dropped files' display metadata (basename + bytes) for the ghost card */
121
+ files: { name: string; size?: number }[];
122
+ };
123
+
105
124
  export type CaptureEvent =
106
125
  | CaptureClick
107
126
  | CaptureType
108
127
  | CaptureDrag
109
128
  | CaptureScroll
110
129
  | CaptureHover
111
- | CapturePress;
130
+ | CapturePress
131
+ | CaptureDropFiles;
112
132
 
113
133
  export type CaptureLog = {
114
134
  video: { width: number; height: number; fps?: number | string; durationS?: number };
@@ -122,6 +142,26 @@ export type CaptureLog = {
122
142
  * summary and (with --strict) the exit code, not just an early stderr line
123
143
  * buried under render progress. `step` is the plan's 0-based step index. */
124
144
  skipped?: { step: number; action: string; target?: string; reason: string }[];
145
+ /** Beats whose editorial hold ran out before the PAGE had finished — the
146
+ * capture kept waiting (see runtime/src/settle.ts) and records how much
147
+ * longer it needed. This is the measurement that replaces guessing
148
+ * `settleMs`: `heldMs + waitedMs` is what that beat actually wanted, and
149
+ * `reason: "budget"` means even the extra wait was not enough. Absent when
150
+ * every hold was already long enough. */
151
+ settleWaits?: {
152
+ step: number;
153
+ action: string;
154
+ heldMs: number;
155
+ waitedMs: number;
156
+ reason: "idle" | "budget" | "unavailable";
157
+ }[];
158
+ /** Largest share of the frame a `<canvas>`/`<video>` held during the capture.
159
+ * It matters because the settle probe reads the page's STRUCTURE, and a
160
+ * paint surface never changes structurally no matter what is drawn inside
161
+ * it — so on a canvas-driven app "the page settled" is not evidence the
162
+ * beat's payoff had appeared, and `settleMs` is doing the whole job alone.
163
+ * Absent on an ordinary DOM app. */
164
+ paintedFrac?: number;
125
165
  };
126
166
 
127
167
  // --- the composition (editable) ----------------------------------------
@@ -146,8 +186,18 @@ export type ZoomDecision = {
146
186
  reason: string;
147
187
  };
148
188
 
189
+ /** Ghost-card knobs for a dropFiles beat (editable): the macOS-style file
190
+ * card riding the cursor during the carry. */
191
+ export type GhostCardConfig = {
192
+ enabled: boolean;
193
+ /** card offset from the cursor tip, video-px (default ~{x:26,y:30}) */
194
+ offset?: Pt;
195
+ /** ms of the release pop after the drop (fade + settle; default 280) */
196
+ releaseMs?: number;
197
+ };
198
+
149
199
  export type CompEvent = {
150
- kind: "click" | "type" | "drag" | "scroll" | "hover" | "press";
200
+ kind: "click" | "type" | "drag" | "scroll" | "hover" | "press" | "dropFiles";
151
201
  tMs: number;
152
202
  /** anchor point (click / focus / drag start / hover) in video-px. For a
153
203
  * scroll/press the cursor does not move; this is its resting point. */
@@ -170,6 +220,10 @@ export type CompEvent = {
170
220
  /** drag stroke easing baked into the ink (kind=drag): "smooth" or "linear".
171
221
  * The cursor replays it so it stays locked to the ink. Absent ⇒ linear. */
172
222
  ease?: "linear" | "smooth";
223
+ /** dropped files' display metadata (kind=dropFiles), for the ghost card */
224
+ files?: { name: string; size?: number }[];
225
+ /** ghost-card rendering knobs (kind=dropFiles); absent ⇒ enabled defaults */
226
+ ghostCard?: GhostCardConfig;
173
227
  };
174
228
 
175
229
  export type FramingConfig = {
@@ -190,15 +244,36 @@ export type CursorConfig = {
190
244
  travelMs: number;
191
245
  /** Distance-aware travel speed, as a fraction of the source video WIDTH per
192
246
  * second (resolution-independent). A travel leg's duration is
193
- * `clamp(distance / (widthsPerSec·videoWidth), travelMinMs, travelMaxMs)`, so
194
- * the cursor holds a roughly CONSTANT on-screen speed regardless of distance —
247
+ * `distance / (widthsPerSec·videoWidth·zoomFrac)`, floored at `travelMinMs` and
248
+ * then capped at `travelMaxMs` (in that order — an inverted band pins short hops
249
+ * to the floor, not everything to the ceiling), so the cursor holds a roughly
250
+ * CONSTANT on-screen speed regardless of distance —
195
251
  * the premium-recorder feel (measured ~0.30 widths/s on the reference). Set 0
196
- * to fall back to the fixed `travelMs`. */
252
+ * to fall back to the fixed `travelMs`.
253
+ *
254
+ * `zoomFrac = restScale / camera scale` — exactly 1 for a full-view take, so a
255
+ * zoom-less composition is unaffected. While the camera is punched in, the same
256
+ * video-px move covers proportionally more of the DELIVERED frame, so without
257
+ * this factor a 2× punch-in reads ~2× too fast precisely where the viewer is
258
+ * looking closest. zoomFrac is INTEGRATED across the leg, not sampled at one
259
+ * instant: a travel usually departs while the camera is still wide and lands
260
+ * after it has closed in, and pricing all of it at the landing magnification
261
+ * over-slows the departure by as much as a zoom-blind duration over-sped it.
262
+ * A leg the camera holds a frame through degenerates to that one frame's
263
+ * factor, which is the sampled model's only exactly-right case. */
197
264
  travelWidthsPerSec: number;
198
- /** Floor for a distance-aware travel (ms) so short hops aren't an instant snap. */
265
+ /** Floor for a distance-aware travel (ms) so short hops aren't an instant snap.
266
+ * NOTE both clamps are applied AFTER the speed model and neither is part of a
267
+ * `pace` preset, so on the legs they bind THEY set the duration and re-pacing
268
+ * the take does nothing. validate.ts says so once that stops being the
269
+ * exception (see CLAMPED_LEGS_FRAC). */
199
270
  travelMinMs: number;
200
271
  /** Ceiling for a distance-aware travel (ms) so a full-width jump stays a glide,
201
- * not a multi-second crawl. */
272
+ * not a multi-second crawl. Binds on any sweep past
273
+ * `travelMaxMs · travelWidthsPerSec · videoWidth` — ~571px of a 1920 frame at
274
+ * the shipped defaults — which is deliberate (it was eye-tuned on a reference
275
+ * recorder's long moves), so it also bounds how much of the zoom correction
276
+ * above a long zoomed sweep can actually receive. */
202
277
  travelMaxMs: number;
203
278
  scale: number;
204
279
  arcFrac: number;
package/src/validate.ts CHANGED
@@ -16,9 +16,37 @@
16
16
  // action needs a re-capture, not a JSON edit. Pass the capture log to enforce
17
17
  // this; without it the check is skipped (we can't know the ground truth).
18
18
 
19
- import { buildStageKeyframes, restStageScale } from "./math";
19
+ import { buildLegs, buildStageKeyframes, cameraRampSchedule, restStageScale } from "./math";
20
+ import { CLAMP_TOL_MS, MOTION, motionName } from "./presets";
21
+ import { DEFAULT_CURSOR } from "./types";
20
22
  import type { CaptureLog, TakeComposition } from "./types";
21
23
 
24
+ /** Tail past the last beat's settle that still reads as "the shot breathing".
25
+ * Beyond it the delivered mp4 is a frozen screen — the padded-to-25s failure. */
26
+ const DEAD_TAIL_MS = 2500;
27
+ /** A dwell-delayed pull-out lands a little after its own action BY DESIGN, and
28
+ * a tail of a few frames is invisible (the spring has all but arrived). The
29
+ * artifact is a camera that has barely LEFT when the action fires — so gate on
30
+ * both an absolute floor and the fraction of the ramp still to run. */
31
+ const MOVING_AT_ACTION_MS = 150;
32
+ const MOVING_AT_ACTION_FRAC = 0.25;
33
+ /** How far past the SLOWEST shipped pace a camera window may run before it is
34
+ * worth a word. Anchored on the preset vocabulary rather than a number
35
+ * invented here, so the ceiling tracks the presets if they are ever retuned. */
36
+ const RAMP_SLACK = 2;
37
+ /** A travel clamp binding on the odd short hop is the point of having clamps;
38
+ * binding on more than this share of the legs means the speed law (and the
39
+ * whole `pace` preset) is not what paces the take. Under CLAMPED_LEGS_MIN legs
40
+ * the share says nothing — two clamped legs out of two is a fixture, not a
41
+ * finding. */
42
+ const CLAMPED_LEGS_FRAC = 0.5;
43
+ const CLAMPED_LEGS_MIN = 3;
44
+ /** A travel squeezed under this share of what the speed law asked for reads as
45
+ * a dart rather than a glide. Paired with an absolute floor so a few-frame
46
+ * shortfall on an already-short hop stays quiet. */
47
+ const SQUEEZE_FRAC = 0.7;
48
+ const SQUEEZE_MIN_MS = 200;
49
+
22
50
  export type CompositionIssue = {
23
51
  severity: "error" | "warn";
24
52
  /** dotted/indexed field path, e.g. "events[3].zoom.scale" */
@@ -41,6 +69,7 @@ const reqField: Record<string, string> = {
41
69
  type: "text",
42
70
  press: "keys",
43
71
  drag: "to",
72
+ dropFiles: "to",
44
73
  };
45
74
 
46
75
  export function validateComposition(
@@ -125,6 +154,18 @@ export function validateComposition(
125
154
  `${e.kind} beat is missing "${need}"`,
126
155
  `restore ${need} from the capture`,
127
156
  );
157
+ if (e.kind === "dropFiles" && !e.files?.length)
158
+ warn(
159
+ `${p}.files`,
160
+ `dropFiles beat has no files metadata — the ghost card will show a generic "file"`,
161
+ "restore files [{name,size}] from the capture",
162
+ );
163
+ if (e.kind === "dropFiles" && !dur)
164
+ warn(
165
+ `${p}.durationMs`,
166
+ "dropFiles beat has no carry duration — the cursor teleports to the drop point and the ghost card only flashes",
167
+ "restore durationMs from the capture",
168
+ );
128
169
 
129
170
  // --- zoom decision ---
130
171
  const z = e.zoom;
@@ -136,14 +177,23 @@ export function validateComposition(
136
177
  );
137
178
  continue;
138
179
  }
139
- // inAtMs must precede the action (the zoom-in ramps in before the beat lands)
180
+ // inAtMs must precede the action (the zoom-in ramps in before the beat
181
+ // lands) — EXCEPT a press: its reveal exists only after the keypress, so
182
+ // its zoom departs AT the action (inAtMs === tMs; the schedule then runs
183
+ // the ramp after the departure instead of landing at tMs).
140
184
  if (z.inAtMs < 0) err(`${p}.zoom.inAtMs`, `negative inAtMs ${z.inAtMs}`, "clamp to 0");
141
- if (z.inAtMs > e.tMs)
185
+ if (z.inAtMs > e.tMs && e.kind !== "press")
142
186
  err(
143
187
  `${p}.zoom.inAtMs`,
144
188
  `inAtMs ${z.inAtMs} is AFTER the action at tMs ${e.tMs} — the zoom would arrive late`,
145
189
  `set inAtMs = tMs − cursor.zoomInMs (= ${Math.max(0, e.tMs - comp.cursor.zoomInMs)})`,
146
190
  );
191
+ if (e.kind === "press" && z.enabled && z.inAtMs < e.tMs)
192
+ warn(
193
+ `${p}.zoom.inAtMs`,
194
+ `press zoom departs ${e.tMs - z.inAtMs}ms BEFORE the keypress — its reveal doesn't exist yet, so the camera punches into empty space`,
195
+ `set inAtMs = tMs (${e.tMs}) so the zoom rides the reveal in`,
196
+ );
147
197
 
148
198
  if (z.enabled) {
149
199
  // scale must zoom IN (≥ rest). Below rest shows MORE than the framed
@@ -189,6 +239,87 @@ export function validateComposition(
189
239
  }
190
240
  }
191
241
 
242
+ // --- cursor motion knobs ---------------------------------------------------
243
+ // These are plain numbers in the schema and, until here, NOTHING bounded them:
244
+ // a hand edit (or an agent reaching for "start the zoom earlier" and stretching
245
+ // the wrong knob) could put the whole take on a crawl with every other check
246
+ // still passing.
247
+ //
248
+ // PRESENT-but-nonsensical is an error: the schedule arithmetic turns it into
249
+ // NaN keyframes. ABSENT is usually the LEGACY shape — compositions predate
250
+ // travelWidthsPerSec / travelMin/MaxMs / zoomInMs and the schedule has a
251
+ // documented fallback for each — so absence is an error only where nothing
252
+ // can stand in. (A validator that refused to render yesterday's composition
253
+ // would be a worse bug than the one it catches.)
254
+ const cur = comp.cursor;
255
+ type MsKnob =
256
+ | "travelMs"
257
+ | "travelMinMs"
258
+ | "travelMaxMs"
259
+ | "holdMs"
260
+ | "zoomInMs"
261
+ | "zoomOutMs"
262
+ | "travelWidthsPerSec";
263
+ const knob = (k: MsKnob, positive: boolean, required: boolean) => {
264
+ const v: number | undefined = cur[k];
265
+ if (v == null) {
266
+ if (required)
267
+ err(
268
+ `cursor.${k}`,
269
+ `${k} is missing and the schedule has no fallback for it`,
270
+ `set cursor.${k} to the shipped default (${DEFAULT_CURSOR[k]})`,
271
+ );
272
+ return;
273
+ }
274
+ if (typeof v !== "number" || !Number.isFinite(v) || (positive ? v <= 0 : v < 0))
275
+ err(
276
+ `cursor.${k}`,
277
+ `${k} must be a ${positive ? "positive" : "non-negative"} number (got ${JSON.stringify(v)})`,
278
+ `restore the shipped default (${DEFAULT_CURSOR[k]})`,
279
+ );
280
+ };
281
+ // The speed law is live only with a positive travelWidthsPerSec; without it
282
+ // the cursor runs on the fixed travelMs and the clamps are never consulted.
283
+ const speedLaw = typeof cur.travelWidthsPerSec === "number" && cur.travelWidthsPerSec > 0;
284
+ knob("holdMs", false, true);
285
+ knob("zoomOutMs", true, true);
286
+ knob("zoomInMs", true, false); // absent ⇒ the legacy inAtMs→tMs window
287
+ knob("travelWidthsPerSec", false, false); // absent/0 ⇒ the documented travelMs fallback
288
+ knob("travelMs", true, !speedLaw);
289
+ knob("travelMinMs", false, speedLaw);
290
+ knob("travelMaxMs", true, speedLaw);
291
+ if (
292
+ Number.isFinite(cur.travelMinMs) &&
293
+ Number.isFinite(cur.travelMaxMs) &&
294
+ cur.travelMaxMs < cur.travelMinMs
295
+ )
296
+ // An inverted band has no coherent answer, and the clamps are applied in
297
+ // order (floor first — see math.ts travelDur), so every leg lands on one
298
+ // bound or the other and the ordering INVERTS: a short hop takes the
299
+ // 800ms floor while a full-frame sweep takes the 400ms ceiling.
300
+ err(
301
+ "cursor.travelMaxMs",
302
+ `travelMaxMs ${cur.travelMaxMs} is below travelMinMs ${cur.travelMinMs} — an inverted band, so every leg is pinned to one bound or the other and SHORT hops (${cur.travelMinMs}ms) end up slower than full-frame sweeps (${cur.travelMaxMs}ms)`,
303
+ `raise travelMaxMs above travelMinMs (defaults ${DEFAULT_CURSOR.travelMinMs}/${DEFAULT_CURSOR.travelMaxMs})`,
304
+ );
305
+ // A punch-in's ramp END is pinned to the action instant, so a LONGER window
306
+ // means departing EARLIER and creeping — never landing later. Past roughly
307
+ // twice the slowest shipped pace the settle curve reads as a drift, and
308
+ // nothing else here catches it (the crowded-release check below only fires on
309
+ // a ramp that lands LATE).
310
+ if (cur.zoomInMs > MOTION.calm.zoomInMs * RAMP_SLACK)
311
+ warn(
312
+ "cursor.zoomInMs",
313
+ `zoomInMs ${cur.zoomInMs} is over ${RAMP_SLACK}× the slowest shipped pace (calm = ${MOTION.calm.zoomInMs}) — a punch-in lands ON the action, so this departs that much earlier and creeps in`,
314
+ `${DEFAULT_CURSOR.zoomInMs} is the frame-measured default; use pace "calm" (${MOTION.calm.zoomInMs}) for a gentler punch`,
315
+ );
316
+ if (cur.zoomOutMs > MOTION.calm.zoomOutMs * RAMP_SLACK)
317
+ warn(
318
+ "cursor.zoomOutMs",
319
+ `zoomOutMs ${cur.zoomOutMs} is over ${RAMP_SLACK}× the slowest shipped pace (calm = ${MOTION.calm.zoomOutMs}) — every release drifts out for that long, and the tail must outlast it`,
320
+ `${DEFAULT_CURSOR.zoomOutMs} is the frame-measured default; use pace "calm" (${MOTION.calm.zoomOutMs}) for a slower release`,
321
+ );
322
+
192
323
  // camera-rect spring: bounce shapes the ONE ease driving centre+size, so an
193
324
  // out-of-range value corrupts every camera move (see math.ts springEase).
194
325
  const spring = comp.cursor.zoomSpring;
@@ -231,6 +362,70 @@ export function validateComposition(
231
362
  "600-1000 reads as a natural beat; 0 = legacy (depart as soon as the action ends)",
232
363
  );
233
364
 
365
+ // SILENT PACE OVERRIDE: travelMinMs/travelMaxMs are applied AFTER the speed
366
+ // law (math.ts buildLegs), so on the legs they bind it is the clamp — not
367
+ // travelWidthsPerSec — that sets the duration. travelWidthsPerSec is what a
368
+ // `pace` preset moves and travelMin/MaxMs are NOT in the preset, so a take
369
+ // whose legs are mostly clamped answers a pace change with a shrug. Nothing
370
+ // in the JSON shows this; only the legs do.
371
+ if (cur.travelWidthsPerSec > 0 && issues.every((i) => i.severity !== "error")) {
372
+ try {
373
+ const travels = buildLegs(comp).filter((l) => !l.drag);
374
+ const pace = motionName(cur);
375
+ // RUSHED TRAVEL: a leg is bounded on the left by the previous beat's
376
+ // action end, so a beat that runs late (or a settleMs too short to hold
377
+ // the glide that follows it) squeezes the move into whatever is left and
378
+ // the cursor darts. This is the cursor's twin of the crowded-release
379
+ // check below, and like it the fix is in the RECORDING: nothing in the
380
+ // composition can widen a gap the capture never left.
381
+ const shortfall = (l: (typeof travels)[number]) => (l.wantSec ?? 0) - (l.t1 - l.t0);
382
+ const squeezed = travels
383
+ .filter(
384
+ (l) =>
385
+ l.wantSec != null &&
386
+ l.t1 - l.t0 < l.wantSec * SQUEEZE_FRAC &&
387
+ shortfall(l) > SQUEEZE_MIN_MS / 1000,
388
+ )
389
+ .sort((a, b) => shortfall(b) - shortfall(a));
390
+ const worst = squeezed[0];
391
+ if (worst) {
392
+ const got = Math.round((worst.t1 - worst.t0) * 1000);
393
+ const want = Math.round((worst.wantSec ?? 0) * 1000);
394
+ const prev = worst.evIdx != null ? events[worst.evIdx - 1] : undefined;
395
+ warn(
396
+ `events[${worst.evIdx}]`,
397
+ `${squeezed.length === 1 ? "this beat's" : `${squeezed.length} beats' travel is rushed; the worst`} approach gets ${got}ms of the ${want}ms the speed law asks for — the cursor darts in${prev ? ` because events[${worst.evIdx! - 1}] (${prev.kind}) is still running until ${prev.tMs + (prev.durationMs ?? 0)}ms` : " because the take starts too close to it"}`,
398
+ prev
399
+ ? `raise the previous step's settleMs by ≥ ${want - got}ms and re-\`make\` — the gap is in the CAPTURE, no cursor knob can widen it`
400
+ : `add a leading \`wait\` (or move \`start\` closer) and re-\`make\` — the opening sweep has no room`,
401
+ );
402
+ }
403
+ for (const which of ["min", "max"] as const) {
404
+ const n = travels.filter((l) => l.clamped === which).length;
405
+ if (travels.length < CLAMPED_LEGS_MIN || n <= travels.length * CLAMPED_LEGS_FRAC) continue;
406
+ const field = which === "min" ? "travelMinMs" : "travelMaxMs";
407
+ // A clamp at ITS PACE'S value is not an override — it IS the pace, it
408
+ // was tuned with the rest of the bundle, and re-pacing moves those legs
409
+ // like any other. Only a clamp somebody HAND-SET away from the pace
410
+ // overrides it, and only then is there anything to say. (Before the
411
+ // clamps joined MOTION every clamped leg really was deaf to the pace,
412
+ // and this warning said so; saying it now would be false.)
413
+ const shipped = pace ? MOTION[pace] : DEFAULT_CURSOR;
414
+ // Same tolerance motionName uses, so the two can never disagree: a
415
+ // value near enough to keep the pace's NAME is near enough to be the
416
+ // pace, and must not be reported as overriding it.
417
+ if (Math.abs(cur[field] - shipped[field]) < CLAMP_TOL_MS) continue;
418
+ warn(
419
+ `cursor.${field}`,
420
+ `${n} of ${travels.length} travel legs are ${which === "min" ? "floored at" : "capped at"} a hand-set cursor.${field} of ${cur[field]}ms — on those the clamp sets the duration, not cursor.travelWidthsPerSec${pace ? `, so they no longer move with the "${pace}" pace (which ships ${shipped[field]}ms)` : ""}`,
421
+ `restore cursor.${field} to ${shipped[field]}${pace ? ` (the "${pace}" pace's own value)` : " (the shipped default)"} to put those legs back under the speed law — or keep it, if they are meant to read as ${which === "min" ? "darts" : "one steady sweep"}`,
422
+ );
423
+ }
424
+ } catch {
425
+ /* never let a diagnostics pass throw */
426
+ }
427
+ }
428
+
234
429
  // tail: the composition must outlast the last action (+ a little settle)
235
430
  if (comp.durationMs < lastEnd)
236
431
  err(
@@ -244,6 +439,80 @@ export function validateComposition(
244
439
  `only ${comp.durationMs - lastEnd}ms after the last action — the final zoom-out may be cut`,
245
440
  `allow ≥ ${comp.cursor.zoomOutMs}ms (cursor.zoomOutMs) of tail`,
246
441
  );
442
+ // …and the mirror image: a tail so long the delivered mp4 ends on a frozen
443
+ // screen. The classic cause is padding a plan with trailing `wait`s to hit a
444
+ // "~25s" target — the capture keeps rolling long after the last payoff has
445
+ // settled and nothing on screen changes again. Cheap to fix (durationMs is
446
+ // render-only), invisible to an agent that never watches the tail.
447
+ else if (events.length) {
448
+ const settledEnd = lastEnd + comp.cursor.holdMs + comp.cursor.zoomOutMs;
449
+ if (comp.durationMs > settledEnd + DEAD_TAIL_MS)
450
+ warn(
451
+ "durationMs",
452
+ `${((comp.durationMs - settledEnd) / 1000).toFixed(1)}s of tail after the last beat settles — the delivered video ends on a frozen screen`,
453
+ `trim durationMs to ≈ ${Math.round(settledEnd)}, or add a beat that earns the time`,
454
+ );
455
+ }
456
+
457
+ // CROWDED RELEASE: the camera should be PARKED at the instant an action
458
+ // fires. A release (a zoomed beat followed by a full-view one) needs
459
+ // pullOutDwellMs + zoomOutMs of room after the previous beat's payoff
460
+ // settles; when the gap is tighter the schedule keeps the ramp and lands it
461
+ // LATE — deliberately, because fleeing a frame the viewer is still reading is
462
+ // worse — and the frame slides out from under the next click. That trade is
463
+ // right given the recording, but the recording is the thing to fix, so say
464
+ // so. (A zoom-enabled `press` is reveal-timed by construction: it departs AT
465
+ // the keypress and rides the reveal in, so its late landing is the design.)
466
+ if (issues.every((i) => i.severity !== "error")) {
467
+ try {
468
+ const sched = cameraRampSchedule(comp);
469
+ const room = (comp.cursor.pullOutDwellMs ?? 0) + comp.cursor.zoomOutMs;
470
+ for (let i = 0; i < events.length; i++) {
471
+ const e = events[i]!;
472
+ const r = sched[i];
473
+ if (!r) continue;
474
+ const rampMs = r.landMs - r.startMs;
475
+ // OVER-LONG WINDOW: the ramp a beat actually gets is inAtMs → its
476
+ // landing, so a hand-set inAtMs — not cursor.zoomInMs — is what makes a
477
+ // multi-second creep. The usual cause is reading "start the zoom
478
+ // earlier" as "start it much earlier": the landing is pinned to the
479
+ // action, so the only thing that moves is how slowly it gets there.
480
+ // Only HAND-SET windows are flagged; the planner's own default is
481
+ // clamped at 0 for an early first beat and that is by design.
482
+ const nominal = r.pullOut ? comp.cursor.zoomOutMs : comp.cursor.zoomInMs;
483
+ const handSet = Math.abs(e.zoom.inAtMs - Math.max(0, e.tMs - comp.cursor.zoomInMs)) >= 1;
484
+ if (handSet && nominal > 0 && rampMs > nominal * RAMP_SLACK)
485
+ warn(
486
+ `events[${i}].zoom.inAtMs`,
487
+ `this beat's camera window runs ${Math.round(rampMs)}ms — ${(rampMs / nominal).toFixed(1)}× cursor.${r.pullOut ? "zoomOutMs" : "zoomInMs"} (${nominal}ms) — so the camera departs at ${Math.round(r.startMs)}ms and creeps to the action instead of moving at the take's pace`,
488
+ `set inAtMs = ${Math.max(0, e.tMs - comp.cursor.zoomInMs)} (tMs − cursor.zoomInMs) and change cursor.${r.pullOut ? "zoomOutMs" : "zoomInMs"} if the RAMP itself should be slower`,
489
+ );
490
+ if (e.kind === "press") continue;
491
+ const lateMs = Math.round(r.landMs - e.tMs);
492
+ if (lateMs <= MOVING_AT_ACTION_MS) continue;
493
+ if (!(rampMs > 0) || lateMs / rampMs <= MOVING_AT_ACTION_FRAC) continue;
494
+ const prev = events[i - 1];
495
+ const prevEnd = prev ? prev.tMs + (prev.durationMs ?? 0) : 0;
496
+ // The dwell floor can push the departure past the action entirely, and
497
+ // then "% of the move done" is negative — a fraction that cannot
498
+ // describe a camera which has not left yet. Say the stronger thing.
499
+ const doneFrac = 1 - lateMs / rampMs;
500
+ const progress =
501
+ doneFrac > 0
502
+ ? `has only ${Math.round(doneFrac * 100)}% of its move done`
503
+ : "has not even departed";
504
+ warn(
505
+ `events[${i}].zoom`,
506
+ `the camera ${progress} when this beat's action fires (departs ${Math.round(r.startMs)}ms, lands ${Math.round(r.landMs)}ms, action ${e.tMs}ms) — the frame slides out from under it${prev ? `; the previous beat settles only ${Math.round(e.tMs - prevEnd)}ms earlier` : ""}`,
507
+ prev
508
+ ? `hold the frame — copy events[${i - 1}].zoom onto this beat so the camera never moves at the action; or re-capture with ≥ ${room}ms of settle on events[${i - 1}] (cursor.pullOutDwellMs + cursor.zoomOutMs)`
509
+ : `re-capture with more lead-in before this beat, or set zoom.enabled=false`,
510
+ );
511
+ }
512
+ } catch {
513
+ /* never let a diagnostics pass throw */
514
+ }
515
+ }
247
516
 
248
517
  // A dwell-delayed final pull-out can land LATER than the legacy tail math
249
518
  // above assumes — check the actual schedule, not the formula. (Guarded: the