Open source CapCut alternative.
TypeScript
feat(site): the assistant lays a speed curve
David Le5def2b36cf25
diff --git a/site/scripts/lib/cut-eval/cases.ts b/site/scripts/lib/cut-eval/cases.tsindex 2103bd9c..64f29686 100644--- a/site/scripts/lib/cut-eval/cases.ts+++ b/site/scripts/lib/cut-eval/cases.ts@@ -706,6 +706,32 @@ export function cases(audio: { dataBase64: string; mimeType: string }): EvalCasereturn undefined;},},+ {+ // A described ramp is a curve, laid in one call: the shape the user+ // asked for lands as nodes over the clip's footage.+ name: "speed-ramp-from-description",+ bucket: "single-tool",+ input: () => [+ userTurn("ease the san francisco clip into slow motion at the end", { state: PARKED_STATE }),+ ],+ reply: /slow|ramp|curve|ease/i,+ requiredTools: ["set_speed_curve"],+ state: PARKED_STATE,+ simulate: () => (name, args) => {+ if (name === "set_speed_curve") {+ return {+ id: args.clipId ?? "c2",+ nodes: [+ { at: 0, speed: 1 },+ { at: 6, speed: 0.4 },+ ],+ speed: 0.7,+ len: 8.6,+ };+ }+ return undefined;+ },+ },{// Scope: "the grey ones" are the parked bars alone. The attached pair// keeps playing; clearing one of them is the over-rotation regression.diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.tsindex a8d9aafb..056cc020 100644--- a/site/src/cut/components/Inspector.tools.ts+++ b/site/src/cut/components/Inspector.tools.ts@@ -18,6 +18,10 @@ import {SOUND_EQ_DB_RANGE,SOUND_LIMITER_RANGE,SOUND_PRESETS,+ SPEED_CURVE_MAX,+ SPEED_CURVE_MIN,+ SPEED_CURVE_PRESET_IDS,+ speedCurvePresetCatalogText,} from "@donkeycut/effects-kit";import { bool, num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";@@ -264,9 +268,36 @@ export const INSPECTOR_TOOLS = [{name: "set_speed",description:- "Set a video clip's playback speed. Faster shortens the clip on the timeline; slower stretches it. Later clips, titles, captions, and soundtrack shift to stay in sync.",+ "Set a video clip's playback speed, one rate across the whole clip. Faster shortens the clip on the timeline; slower stretches it. Later clips, titles, captions, and soundtrack shift to stay in sync. A clip carrying a speed curve loses it: the rate becomes uniform again (set_speed_curve is the tool for a rate that changes through the footage).",inputSchema: obj({ clipId: str("Video clip id"), speed: num("Playback rate (1 = normal, no upper limit)") }, ["clipId", "speed"]),},+ {+ name: "set_speed_curve",+ description:+ `Give a video clip (any track) a speed curve: its rate changes through the footage instead of being one number, so one clip can race through a walk, land on a beat, and hold on a face. Nodes are {at, speed}: \`at\` in SOURCE seconds inside the clip's trim — the unit detect_beats, trim_clip and watch_video speak, so beat times drop straight in — and speed ${SPEED_CURVE_MIN}–${SPEED_CURVE_MAX}×. The rate curves smoothly between nodes and holds flat past the outermost ones; the whole list replaces the clip's curve, and an empty list clears it (the clip keeps its length at one uniform rate). Or pass a preset to lay a named ramp over the trim: ${speedCurvePresetCatalogText()}. Technique: give a peak a beat of normal speed on either side or it reads as a glitch; below about 0.5× ordinary footage shows its own frame rate, so real slow motion wants high-frame-rate source (say so instead of shipping judder); sound stretches with its pitch kept, which holds up on speech to roughly 0.5–2×. The clip's timeline length becomes the integral of the curve and later items shift like a trim. Returns the resulting nodes, the clip's length before and after, and the rows that moved. In the UI the Speed Curve row opens the same graph over the timeline.`,+ inputSchema: obj(+ {+ clipId: str("Video clip id"),+ nodes: {+ type: "array",+ description: "The whole curve, any order; empty clears it",+ items: obj(+ {+ at: num("Source seconds, inside the clip's trim"),+ speed: num(`Rate at that moment, ${SPEED_CURVE_MIN}–${SPEED_CURVE_MAX}`),+ },+ ["at", "speed"]+ ),+ },+ preset: {+ type: "string",+ enum: SPEED_CURVE_PRESET_IDS,+ description: "A named ramp laid over the clip's trim, instead of nodes",+ },+ },+ ["clipId"]+ ),+ },{name: "set_color_grade",description:diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.tsindex 598b2c7a..89ca43b2 100644--- a/site/src/cut/lib/aiContext.ts+++ b/site/src/cut/lib/aiContext.ts@@ -1,6 +1,6 @@"use client";-import { hasOverlayAnim, type ClipSound } from "@donkeycut/effects-kit";+import { hasOverlayAnim, retimeOf, speedCurveOf, type ClipSound, type SpeedNode } from "@donkeycut/effects-kit";import { chatOwner } from "./chatAssets";import { useGenerate } from "./generate";import { useMatteBakes } from "./removal/bakeJobs";@@ -196,7 +196,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nulen: r(sp.len),muted: sp.clip.muted,...(sp.clip.hidden ? { hidden: true } : {}),- speed: r(sp.clip.speed ?? 1),+ ...describeRate(sp.clip),};}// A layer clip carries no span (spans are track 0); describe its@@ -337,7 +337,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu// set_clip_sound; absent when its sound is untouched....(sp.clip.sound ? { sound: sp.clip.sound } : {}),framing: sp.clip.fit ?? "fit",- speed: r(sp.clip.speed ?? 1),+ ...describeRate(sp.clip),// The generated scene shot this clip came from — sceneShot is the// 1-based number regenerate_shot takes; heldStill marks a render that// fell back to its keyframe.@@ -452,22 +452,35 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu};}+/** A clip's rate as the model reads it: one number, or the average plus the+ * curve's nodes as [sourceSeconds, rate] when the rate changes through the+ * footage. */+function describeRate(c: { speed?: number; speedCurve?: SpeedNode[]; in: number; out: number }) {+ const nodes = speedCurveOf(c);+ if (!nodes) return { speed: r(c.speed ?? 1) };+ return {+ speed: r(retimeOf(c).rate),+ speedCurve: nodes.map(([at, rate]) => [r(at), r(rate)]),+ };+}+function describeAudio(- a: { assetId: string; start: number; in: number; out: number; volume: number; fadeIn?: number; fadeOut?: number; speed?: number; sound?: ClipSound; duck?: number; lane?: number; hidden?: boolean },+ a: { assetId: string; start: number; in: number; out: number; volume: number; fadeIn?: number; fadeOut?: number; speed?: number; speedCurve?: SpeedNode[]; sound?: ClipSound; duck?: number; lane?: number; hidden?: boolean },assets: Map<string, { name: string }>) {- const speed = a.speed && a.speed > 0 ? a.speed : 1;+ const rt = retimeOf(a);+ const speed = rt.rate;return {asset: assets.get(a.assetId)?.name ?? a.assetId,start: r(a.start),- len: r((a.out - a.in) / speed),+ len: r(rt.len),in: r(a.in),out: r(a.out),volume: r(a.volume),fadeIn: r(a.fadeIn ?? 0),fadeOut: r(a.fadeOut ?? 0),...(a.sound ? { sound: a.sound } : {}),- ...(speed !== 1 ? { speed: r(speed) } : {}),+ ...(speed !== 1 || a.speedCurve ? describeRate(a) : {}),...(a.lane ? { lane: a.lane } : {}),...(a.hidden ? { hidden: true } : {}),// A voiceover: while it plays, other audio ducks to this gain.@@ -476,13 +489,12 @@ function describeAudio(}function describeOverlayClip(c: VideoClip, assets: Map<string, { name: string }>) {- const speed = c.speed && c.speed > 0 ? c.speed : 1;const rect = rectOf(c);return {asset: assets.get(c.assetId)?.name ?? c.assetId,track: c.track,start: r(c.start),- len: r((c.out - c.in) / speed),+ len: r(retimeOf(c).len),in: r(c.in),out: r(c.out),muted: c.muted,@@ -500,7 +512,7 @@ function describeOverlayClip(c: VideoClip, assets: Map<string, { name: string }>: {}),...(c.rotation ? { rotation: c.rotation } : {}),...((c.opacity ?? 1) < 1 ? { opacity: r(c.opacity ?? 1) } : {}),- ...(speed !== 1 ? { speed: r(speed) } : {}),+ ...(retimeOf(c).rate !== 1 || c.speedCurve ? describeRate(c) : {}),...(c.grade ? { colorGrade: c.grade } : {}),...(c.mask ? { mask: c.mask } : {}),...(c.boxStyle ? { boxStyle: c.boxStyle } : {}),diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 37c36b73..492502fc 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -10,14 +10,20 @@ import {matchGrade,normalizeGrade,normalizeSound,+ retimeOf,semanticMasterCurve,SOUND_PRESETS,+ SPEED_CURVE_MAX,+ SPEED_CURVE_MIN,+ SPEED_CURVE_PRESET_IDS,+ speedCurveOf,type ClipSound,type ColorStats,type CurvePoint,type EffectId,type GradeCurves,type HslBand,+ type SpeedNode,type WheelTuple,type Mask,OVERLAY_ANIM_DEFAULT_SECONDS,@@ -112,7 +118,7 @@ import { STOCK_VIDEOS } from "./stockVideoManifest";import { storedMediaUrl } from "./mediaSync";import { isSoundPresetTemplate, listSoundPresets, saveSoundPreset } from "./soundPresets";import { isStylePresetTemplate } from "./stylePresets";-import { applyOverlayPatchSettled, track0Clips, laneGapAt, getClipSpans, nextFreeStart, overlayLaneOrder, overlayLayers, parkedTransitions, projectDuration, resolveTransitions, totalDuration, useEditor } from "./store";+import { applyOverlayPatchSettled, clipLen, track0Clips, laneGapAt, getClipSpans, nextFreeStart, overlayLaneOrder, overlayLayers, parkedTransitions, projectDuration, resolveTransitions, totalDuration, useEditor } from "./store";import { playheadAt } from "./playhead";import { renderProjectFrame } from "./exportRender";import { renderStageFrame, storeStageStill } from "./stageFrame";@@ -210,7 +216,7 @@ function tracksAfter() {const row = track0Clips(cur.clips).map((c) => ({id: c.id,start: round2(c.start),- len: round2((c.out - c.in) / (c.speed && c.speed > 0 ? c.speed : 1)),+ len: round2(clipLen(c)),}));const lanes = cur.audioClips.map((a) => ({id: a.id,@@ -576,8 +582,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {const clip = requireItem(s.clips, input.clipId, "video clip");const raw = input.keys;if (!Array.isArray(raw)) throw new ToolError("keys must be a list.");- const speed = clip.speed && clip.speed > 0 ? clip.speed : 1;- const dur = Math.max(0.1, (clip.out - clip.in) / speed);+ const dur = clipLen(clip);let kf = clip.kf;if (raw.length === 0) {s.clearClipKeys(clip.id);@@ -666,7 +671,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {const st = useEditor.getState();const dur = o? Math.max(0.1, o.end - o.start)- : Math.max(0.1, (clip!.out - clip!.in) / (clip!.speed && clip!.speed > 0 ? clip!.speed : 1));+ : clipLen(clip!);if (raw.length === 0) {if (o) st.clearOverlayMaskKeys(o.id);else st.clearClipMaskKeys(clip!.id);@@ -872,8 +877,8 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {if (clip) {speech = laneCues(s.subtitles, s.subtitleLane).map((c) => ({- start: clip.in + (c.start - clip.start) * speed,- end: clip.in + (c.end - clip.start) * speed,+ start: retimeOf(clip).srcAt(c.start - clip.start),+ end: retimeOf(clip).srcAt(c.end - clip.start),text: c.text,})).filter((c) => c.end > from && c.start < body.coveredTo);@@ -922,7 +927,14 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {in: round2(clip.in),out: round2(clip.out),speed: round2(speed),- note: `timeline_t = ${round2(clip.start)} + (source_t - ${round2(clip.in)}) / ${round2(speed)}, for source_t in [${round2(clip.in)}, ${round2(clip.out)}]`,+ ...(speedCurveOf(clip)+ ? {+ speedCurve: speedCurveOf(clip)!.map(([at, rate]) => [round2(at), round2(rate)]),+ note: `this clip has a speed curve (average ${round2(speed)}×): source_t maps to the timeline through the curve, with the clip occupying [${round2(clip.start)}, ${round2(clip.start + retimeOf(clip).len)}]; work in source seconds here`,+ }+ : {+ note: `timeline_t = ${round2(clip.start)} + (source_t - ${round2(clip.in)}) / ${round2(speed)}, for source_t in [${round2(clip.in)}, ${round2(clip.out)}]`,+ }),},}: {}),@@ -1161,13 +1173,10 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {place_clip: (s, input) => {const clip = requireItem(s.clips, input.clipId, "video clip");if (!isNum(input.start)) throw new ToolError("start (seconds) is required.");- const len = (clip.out - clip.in) / (clip.speed && clip.speed > 0 ? clip.speed : 1);+ const len = clipLen(clip);const taken = s.clips.filter((c) => c.id !== clip.id && c.track === clip.track)- .map((c) => ({- start: c.start,- end: c.start + (c.out - c.in) / (c.speed && c.speed > 0 ? c.speed : 1),- }));+ .map((c) => ({ start: c.start, end: c.start + clipLen(c) }));const at = nextFreeStart(taken, Math.max(0, input.start), len);// Closing a gap is this tool's main job, so the clip's blends travel// with it: a bar playing its head or its cut lands on the edge's new@@ -1214,7 +1223,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {id: c.id,track: c.track,start: round2(c.start),- len: round2((c.out - c.in) / (c.speed && c.speed > 0 ? c.speed : 1)),+ len: round2(clipLen(c)),layout: regionLabel(rectOf(c)),};},@@ -1376,7 +1385,6 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {// the air both sides wanted, so both give ground and the joint sits// inside that pause — reverting to the cut's own numbers is what put an// edge back on top of a word.- const spd = (c: VideoClip) => (c.speed && c.speed > 0 ? c.speed : 1);const rows = new Map<number, VideoClip[]>();for (const c of s.clips) rows.set(c.track, [...(rows.get(c.track) ?? []), c]);for (const row of rows.values()) {@@ -1429,7 +1437,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {if (plan) {patch.in = plan.in;patch.out = plan.out;- delta += (plan.out - plan.in - (c.out - c.in)) / spd(c);+ delta += retimeOf({ ...c, in: plan.in, out: plan.out }).len - retimeOf(c).len;}if (plan || patch.start !== undefined) patches.push({ id: c.id, patch });}@@ -2053,8 +2061,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {update_audio: (s, input) => {const a = requireItem(s.audioClips, input.id, "soundtrack clip");- const aSpeed = a.speed && a.speed > 0 ? a.speed : 1;- const len = (a.out - a.in) / aSpeed;+ const len = retimeOf(a).len;const patch: Partial<AudioClip> = {};if (isNum(input.volume)) patch.volume = clamp(input.volume, 0, 3);if (isNum(input.fadeIn)) patch.fadeIn = clamp(input.fadeIn, 0, len / 2);@@ -2289,10 +2296,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {const span = spans.find((sp) => t >= sp.start && t < sp.start + sp.len) ?? spans[spans.length - 1];// Timeline seconds run at the clip's speed in source time, so a sped-up// clip freezes the frame the preview actually shows.- const srcTime =- span.clip.in +- (t - span.start) *- (span.clip.speed && span.clip.speed > 0 ? span.clip.speed : 1);+ const srcTime = retimeOf(span.clip).srcAt(t - span.start);let body: MediaAsset;const freezeDur = Math.min(10, Math.max(0.5, isNum(input.duration) ? input.duration : 1));if (input.with_elements === true) {@@ -3537,9 +3541,60 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {set_speed: (s, input) => {const clip = requireItem(s.clips, input.clipId, "video clip");if (!isNum(input.speed)) throw new ToolError("speed is required (e.g. 1.5).");+ const before = clipLen(clip);s.setClipSpeed(clip.id, input.speed);const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;- return { id: next.id, speed: next.speed ?? 1 };+ return {+ id: next.id,+ speed: next.speed ?? 1,+ lenBefore: round2(before),+ lenAfter: round2(clipLen(next)),+ ...tracksAfter(),+ };+ },++ set_speed_curve: (s, input) => {+ const clip = requireItem(s.clips, input.clipId, "video clip");+ const before = clipLen(clip);+ if (typeof input.preset === "string") {+ if (Array.isArray(input.nodes) && input.nodes.length > 0)+ throw new ToolError(+ "Pass either `preset` or `nodes`, not both — a preset lays its own nodes over the clip."+ );+ if (!SPEED_CURVE_PRESET_IDS.includes(input.preset))+ throw new ToolError(+ `Unknown preset "${input.preset}". One of: ${SPEED_CURVE_PRESET_IDS.join(", ")}.`+ );+ s.setClipSpeedPreset(clip.id, input.preset);+ } else {+ const raw = input.nodes;+ if (!Array.isArray(raw))+ throw new ToolError("nodes must be a list (empty clears the curve), or pass a preset.");+ if (raw.length === 0) {+ s.setClipSpeedCurve(clip.id, undefined);+ } else {+ const nodes: SpeedNode[] = (raw as Record<string, unknown>[]).map((n) => {+ if (!isNum(n.at) || !isNum(n.speed))+ throw new ToolError("Every node needs `at` (source seconds) and `speed`.");+ if (n.at < clip.in - 1e-6 || n.at > clip.out + 1e-6)+ throw new ToolError(+ `Node at ${round2(n.at)}s is outside the clip's trim [${round2(clip.in)}, ${round2(clip.out)}] (source seconds).`+ );+ return [n.at, clamp(n.speed, SPEED_CURVE_MIN, SPEED_CURVE_MAX)];+ });+ s.setClipSpeedCurve(clip.id, nodes);+ }+ }+ const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;+ const curve = speedCurveOf(next);+ return {+ id: next.id,+ speed: round2(retimeOf(next).rate),+ nodes: curve ? curve.map(([at, speed]) => ({ at: round2(at), speed: round2(speed) })) : [],+ lenBefore: round2(before),+ lenAfter: round2(clipLen(next)),+ ...tracksAfter(),+ };},set_color_grade: (s, input) => {@@ -4013,7 +4068,7 @@ function resolveWatchTarget(input: Record<string, unknown>): {asset: MediaAsset;- clip: { id: string; start: number; in: number; out: number; speed?: number } | null;+ clip: { id: string; start: number; in: number; out: number; speed?: number; speedCurve?: SpeedNode[] } | null;} {if (input.clip_id !== undefined && input.clip_id !== null) {const id = String(input.clip_id);@@ -4040,7 +4095,7 @@ function resolveWatchRange(): {projectId: string;asset: MediaAsset;- clip: { id: string; start: number; in: number; out: number; speed?: number } | null;+ clip: { id: string; start: number; in: number; out: number; speed?: number; speedCurve?: SpeedNode[] } | null;speed: number;from: number;to: number | undefined;@@ -4048,7 +4103,7 @@ function resolveWatchRange(const projectId = s.projectId;if (!projectId) throw new ToolError("No project open.");const { asset, clip } = resolveWatchTarget(s, input);- const speed = clip?.speed && clip.speed > 0 ? clip.speed : 1;+ const speed = clip ? retimeOf(clip).rate : 1;const dur = asset.duration > 0 ? asset.duration : Infinity;const from = clamp(isNum(input.from) ? input.from : clip ? clip.in : 0, 0, dur);// An unknown duration leaves `to` for the engine to probe.diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 5a4a8d6b..2f6a56f6 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -91,10 +91,10 @@ Times are in seconds on the shared timeline. The playhead is currentTime; a skim- Two ways to move a track-0 clip: place_clip sets its start (respects gaps, slides right if the spot is taken); move_clip reorders by index, opening a slot at the landing point — clips after it shift right, every other gap survives. Index-based inserts (freeze_frame, generated clips) open a slot the same way.- add_clip puts a project asset on the timeline the way a drag does: video/image onto track 0 (a \`start\`, an \`index\` insert, or appended at the end), audio onto the soundtrack.- Overlay video: a video/image asset can sit on a track above track 0 (track 1, 2… — topmost wins). A full-frame overlay covers everything below it; give it a layout to share the frame — top/bottom/left/right halves for a split screen, pip for a floating corner box, or a custom region rect. add_overlay_video creates one from a media asset; update_overlay_video moves/trims/regions/mutes/hides it. The user makes them by dragging media above track 0; they drag the region in the preview.-- A clip's timeline length is (out-in)/speed; total duration runs to the last clip's end, gaps included. Transitions blend at cuts and never change layout or length.+- A clip's timeline length is (out-in)/speed — or, for a clip with a speed curve, the integral of its curve over the trim (editor_state reports \`len\` either way, and lists a curved clip's \`speedCurve\` nodes as [sourceSeconds, rate]). Total duration runs to the last clip's end, gaps included. Transitions blend at cuts and never change layout or length.- trim_clip changes in/out inside the source media. in >= 0, out <= source duration, out-in >= 0.1.- Resizes ripple the same way deletes do: while track 0 is the only video track, a track-0 trim or speed change slides everything past the clip's tail — clips, titles, captions, soundtrack — with the moved edge, in both directions, every existing gap keeping its width. With overlay video tracks present, growth pushes the track-0 run and a shrink leaves a gap.-- set_speed sets a clip's playback rate; it changes the clip's timeline length and carries the timeline behind it like a trim.+- set_speed sets a clip's playback rate; it changes the clip's timeline length and carries the timeline behind it like a trim. set_speed_curve makes the rate change through the footage — nodes of {at: source seconds, speed} or a named preset ramp — for speed ramps, whips, holds, and hits on the beat: detect_beats first, then place nodes at the beats it returns (same unit, no arithmetic). set_speed on a curved clip makes it uniform again.- set_transition joins a clip into the next one (0–2s, ${TRANSITION_STYLE_IDS.length} styles); set_animation animates one clip's own entrance/exit — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition. A transition is a bar on its own row at an absolute time, so an edit can leave one lining up with nothing: every timeline mutation reports those as \`parkedTransitions\`, and clearing them (remove_transition) is part of finishing the edit. Grading a clip's picture is the color tools (set_color_preset, set_color_grade, set_color_curves, set_color_wheels, set_color_hsl — read the color-grading skill); a stylized post treatment (grain, VHS, halation…) is add_effect, dropped over the stretch of timeline it covers — as is a treatment on the sound (echo, reverb, telephone…).- Cutting a clip's background away — the AI person matte, ink around the silhouette, a fill behind the subject — is the cutout suite (set_removal, set_removal_stroke, set_removal_background); read the background-removal skill.- split_at cuts the track-0 clip under that time into two clips at the exact frame. With a soundtrack or overlay clip selected it splits that instead.@@ -159,13 +159,13 @@ The flow for "edit this for me":2. Speech? subtitles_generate first — cue timings are timeline seconds and say what is said when.3. watch_video each distinct source (or the ranges in question); note scene changes and what happens where.4. Plan in thoughts: group the cues into sentences and thoughts, decide which thoughts stay whole, then detect_silence to find where the speaker actually pauses. Cue timings approximate the audio — a trailing word often spills past its cue — so aim every speech cut into a detected silence span, and aim loose: up to a second of spare air on each side beats a tight cut, because the refine step trues the edges after. A cue boundary with no silence span around it means the speech runs continuously there, so leave that joint alone.-5. Execute: split_at (timeline s) to divide, delete_item to drop a segment, trim_clip (source s) to tighten edges, place_clip/move_clip to close gaps or reorder, set_speed to compress slow stretches. Batch each wave in one round: splits don't move times, so issue every planned split_at together, then every delete together. Every timeline mutation returns the updated track-0 and soundtrack rows (ids, starts, lengths) — read the new ids from the result and keep cutting; get_state between steps is a wasted round.+5. Execute: split_at (timeline s) to divide, delete_item to drop a segment, trim_clip (source s) to tighten edges, place_clip/move_clip to close gaps or reorder, set_speed to compress slow stretches (set_speed_curve when the pace should change inside one clip). Batch each wave in one round: splits don't move times, so issue every planned split_at together, then every delete together. Every timeline mutation returns the updated track-0 and soundtrack rows (ids, starts, lengths) — read the new ids from the result and keep cutting; get_state between steps is a wasted round.6. Refine: refine_speech_cuts with every recut clip id, and with the \`pace\` the request asked for. It measures the recording's own room tone and voice level, finds where each word truly starts and finishes, and re-trims every edge to sit a beat clear of one, keeping the clips' spacing. It reads sound, not intent — leave out a clip whose edge you placed mid-speech on purpose.7. Verify by ear: listen_audio at each edge the refine flagged, plus a spot-check or two (scope from/to to ~2s around the joint), and check the first and last words arrive whole and the hand-off into the next thought sounds natural. A clipped word → widen that trim deeper into the silence and listen again. After a heavy edit, listen once end-to-end. seek + capture_frame when the change is visual.Time math (get this right):- watch_video, detect_silence, and trim_clip speak SOURCE seconds; split_at and place_clip speak TIMELINE seconds.-- timeline_t = clip.start + (source_t − clip.in) / clip.speed, valid while source_t is inside [in, out]. Each watch result's clip block carries this formula with the real numbers filled in.+- timeline_t = clip.start + (source_t − clip.in) / clip.speed, valid while source_t is inside [in, out]. Each watch result's clip block carries this formula with the real numbers filled in. A clip with a speed curve has no closed form: work in source seconds there (trim_clip, set_speed_curve, split by proportion of its reported len) and read the clip's len from editor_state after each change.- The same source can appear in several clips — map per clip.Cutting speech well: pace is part of the message, and it is set in one place — refine_speech_cuts' \`pace\`. "Fast paced", "punchy", "tight" means pace: fast there; a calm piece means relaxed. Placing your own edges closer to the words is not a faster cut, it is a clipped one: a word's tail runs past its cue, the ear hears the truncation, and no amount of tightening reads as energy. So cut loose — up to a second of spare air on each side — and let the refine step take it back to the beat the pace asks for. Shorten a long pause to that beat rather than deleting it; speech butted directly together reads as rushed however fast the piece is meant to be. Prefer split_at + delete_item, then place_clip to close the gap (a beat of black may be wanted — ask the cut, not the tool); trim_clip only tightens a clip's edges.`,