Skip to content

Commit 349b42a

Browse files
committed
fix(ai-edition): measure a trim without clipId on every clip of its asset; say speed scales the move both ways
1 parent 3954ca0 commit 349b42a

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

‎electron/ai-edition/agent-tools.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,47 @@ describe("zoom transitions are reported, not hidden (#1028)", () => {
25412541
expect(snapshotZoom(trimmed.document).cutByTrim).toBe("out");
25422542
});
25432543

2544+
it("flags a zoom on the second clip of an asset that a trim without clipId cuts", () => {
2545+
// Two clips over one recording, and a pre-v7 trim (no clipId): playback cuts it from
2546+
// both clips, while the ruler maps it through the first one only.
2547+
const base = shortSingleClip();
2548+
const clip = base.timeline.clips[0];
2549+
const length = (clip.sourceEndSec ?? 0) - clip.sourceStartSec;
2550+
const twoClips: AxcutDocument = {
2551+
...base,
2552+
timeline: {
2553+
...base.timeline,
2554+
clips: [
2555+
clip,
2556+
{
2557+
...clip,
2558+
id: "clip_2",
2559+
timelineStartSec: length,
2560+
timelineEndSec: 2 * length,
2561+
},
2562+
],
2563+
trimRanges: [
2564+
{
2565+
id: "trim_legacy",
2566+
assetId: clip.assetId,
2567+
startSec: 12,
2568+
endSec: 14,
2569+
reason: "",
2570+
origin: "user",
2571+
},
2572+
],
2573+
},
2574+
};
2575+
const added = run(twoClips, "addZoom", {
2576+
startSec: length + 10,
2577+
endSec: length + 12,
2578+
depth: 3,
2579+
});
2580+
expect(added.payload.cutTransitions).toEqual([
2581+
{ zoomId: added.payload.zoomId, side: "out", cutSec: MOVE_SEC },
2582+
]);
2583+
});
2584+
25442585
it("stays quiet about a trim clear of both windows", () => {
25452586
const trimmed = run(zoomedAt10to12().document, "addTrim", { startSec: 14, endSec: 15 });
25462587
expect(trimmed.payload.cutTransitions).toBeUndefined();

‎electron/ai-edition/agent-tools.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,19 @@ function zoomTransitionsForAgent(document: AxcutDocument) {
729729
(legacy?.speedRegions as
730730
| Array<{ id: string; startMs: number; endMs: number; speed: number }>
731731
| undefined) ?? [];
732+
// A trim with no clipId cuts every clip of its asset in playback, while the ruler maps it
733+
// through one: measured per clip, so a zoom on any of them learns of the cut.
732734
const trims = document.timeline.trimRanges.flatMap((trim) => {
733-
const span = trimToTimelineSpan(trim, document.timeline.clips);
734-
return span ? [{ startMs: span.start * 1000, endMs: span.end * 1000 }] : [];
735+
const clips =
736+
trim.clipId !== undefined
737+
? [trim]
738+
: document.timeline.clips
739+
.filter((clip) => clip.assetId === trim.assetId)
740+
.map((clip) => ({ ...trim, clipId: clip.id }));
741+
return clips.flatMap((anchored) => {
742+
const span = trimToTimelineSpan(anchored, document.timeline.clips);
743+
return span ? [{ startMs: span.start * 1000, endMs: span.end * 1000 }] : [];
744+
});
735745
});
736746
return coalesceForAgent(document.zoomRanges).map((zoom) => {
737747
const transitions = zoomTransitions({ ...zoom, scale: effectiveZoomScale(zoom) }, speedRegions);
@@ -813,8 +823,8 @@ export function documentSnapshotForModel(
813823
"When a zoom carries customScale it wins over depth and depthIsOverridden is true — " +
814824
"a setZoom that only changes depth on such a zoom clears customScale so the depth takes effect. " +
815825
"startSec–endSec is where the zoom HOLDS: it animates in over zoomInFromSec–startSec and out over " +
816-
"endSec–zoomOutUntilSec (transitionSec of screen time each, stretched on the timeline by a speed " +
817-
"region). cutByTrim names the move a trim cuts into (in, out or both): the export jumps at that cut.",
826+
"endSec–zoomOutUntilSec (transitionSec of screen time each; a speed region scales that on the " +
827+
"timeline, longer above 1x and shorter below, so read the bounds rather than adding transitionSec). cutByTrim names the move a trim cuts into (in, out or both): the export jumps at that cut.",
818828
project: { id: document.project.id, title: document.project.title },
819829
primaryAssetId: document.project.primaryAssetId ?? document.assets[0]?.id ?? null,
820830
autoFocusAll,

‎electron/ai-edition/deep-agent/service.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function buildSystemPrompt(options: { editsAllowed: boolean }): string {
145145
export const SYSTEM_PROMPT = buildSystemPrompt({ editsAllowed: true });
146146

147147
// #1028: a zoom's camera moves sit OUTSIDE its span, where nothing on the ruler shows them.
148-
const ZOOM_TRANSITIONS_NOTE = `A zoom HOLDS over its span: it animates in during the window just before startSec and out during the window just after endSec. Each move lasts 0.6 s + 0.55 s × ln(renderedScale) of SCREEN time (${ZOOM_TRANSITION_LEGEND}), so inside a speed region it covers that many times more timeline. getCurrentDocument gives each zoom's zoomInFromSec and zoomOutUntilSec, in virtual seconds like the zoom. A trim inside either window cuts that move and the export jumps at the cut: leave the windows untrimmed.`;
148+
const ZOOM_TRANSITIONS_NOTE = `A zoom HOLDS over its span: it animates in during the window just before startSec and out during the window just after endSec. Each move lasts 0.6 s + 0.55 s × ln(renderedScale) of SCREEN time (${ZOOM_TRANSITION_LEGEND}), so a speed region scales the timeline it covers by its speed: longer above 1×, shorter below. getCurrentDocument gives each zoom's zoomInFromSec and zoomOutUntilSec, in virtual seconds like the zoom. A trim inside either window cuts that move and the export jumps at the cut: leave the windows untrimmed.`;
149149
const CUT_TRANSITIONS_RESULT = `When the result cuts a zoom's move in or out, it carries \`cutTransitions\`: which zoom, which side, and cutSec, the timeline seconds of the move lost. It is a warning, nothing is refused: move the cut or the zoom unless a hard cut is what you want.`;
150150

151151
export const TOOL_DESCRIPTIONS: Record<string, string> = {

0 commit comments

Comments
 (0)