Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(ai-edition): text like the editor's, sets that land where asked, and a format tool
EtienneLescotb2460ab66960
diff --git a/electron/ai-edition/agent-tools.test.ts b/electron/ai-edition/agent-tools.test.tsindex c900ee24b..d0f17a2f6 100644--- a/electron/ai-edition/agent-tools.test.ts+++ b/electron/ai-edition/agent-tools.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from "vitest";import {+ type AxcutAnnotationRegion,type AxcutDocument,createEmptyDocument,documentSchema,@@ -16,6 +17,15 @@ import { executeAgentTool, isMutatingTool, MUTATING_TOOL_NAMES } from "./agent-t* so pinning it costs nothing and makes every document in the file comparable. */const FIXTURE_CREATED_AT = "2026-01-01T00:00:00.000Z";+/** Where an annotation's box is centred, in frame percentages. */+function centreOf(region: Pick<AxcutAnnotationRegion, "position" | "size"> | undefined) {+ if (!region) return undefined;+ return {+ x: region.position.x + region.size.width / 2,+ y: region.position.y + region.size.height / 2,+ };+}+function fixtureDocument(): AxcutDocument {const base = createEmptyDocument({title: "Test",@@ -186,6 +196,7 @@ describe("the mutating-tool table", () => {"removeWords","replaceTimeline","setAnnotation",+ "setAspectRatio","setAudio","setCameraFullscreen","setClipRange",@@ -685,9 +696,11 @@ describe("executeAgentTool", () => {endMs: 3000,type: "text",textContent: "Look here",- // x/y are the text's centre: a 30x20 box centred on (20, 80).- position: { x: 5, y: 70 },+ // On the output frame, as the editor places text: padding and zooms never move it.+ space: "frame",});+ // x/y are the text's centre, and the box is fitted to the text around it.+ expect(centreOf(ann)).toEqual({ x: expect.closeTo(20, 5), y: expect.closeTo(80, 5) });expect(() => documentSchema.parse(result.document)).not.toThrow();});@@ -697,16 +710,124 @@ describe("executeAgentTool", () => {"addAnnotation",JSON.stringify({ startSec: 1, endSec: 3, text: "Hi" }),).document?.annotations.at(-1);- expect(centred).toMatchObject({- position: { x: 35, y: 40 },- style: { backgroundColor: "rgba(0, 0, 0, 0.7)" },- });+ expect(centred).toMatchObject({ style: { backgroundColor: "rgba(0, 0, 0, 0.7)" } });+ expect(centreOf(centred)).toEqual({ x: expect.closeTo(50, 5), y: expect.closeTo(50, 5) });const corner = executeAgentTool(fixtureDocument(),"addAnnotation",JSON.stringify({ startSec: 1, endSec: 3, text: "Hi", x: 100, y: 0 }),).document?.annotations.at(-1);- expect(corner).toMatchObject({ position: { x: 70, y: 0 } });+ expect(corner?.position.y).toBe(0);+ expect((corner?.position.x ?? 0) + (corner?.size.width ?? 0)).toBeCloseTo(100, 5);+ });++ it("addAnnotation takes the look the editor's inspector offers", () => {+ const add = (look: Record<string, unknown>) =>+ executeAgentTool(+ fixtureDocument(),+ "addAnnotation",+ JSON.stringify({ startSec: 1, endSec: 3, text: "Palettes in one click", ...look }),+ ).document?.annotations.at(-1);+ const plain = add({});+ const title = add({+ fontSize: 72,+ color: "#ffcc00",+ background: "none",+ bold: false,+ animation: "typewriter",+ });+ expect(title?.style).toMatchObject({+ fontSize: 72,+ color: "#ffcc00",+ backgroundColor: "transparent",+ fontWeight: "normal",+ textAnimation: "typewriter",+ });+ // Bigger text, bigger box: the box is the text's.+ expect(title?.size.width).toBeGreaterThan(plain?.size.width ?? 0);+ });++ it("setAnnotation moves the text, restyles it and refits its box around its centre", () => {+ const added = executeAgentTool(+ fixtureDocument(),+ "addAnnotation",+ JSON.stringify({ startSec: 1, endSec: 3, text: "Hi", x: 30, y: 30 }),+ );+ const id = JSON.parse(added.resultJson).annotationId;+ const moved = executeAgentTool(+ added.document as AxcutDocument,+ "setAnnotation",+ JSON.stringify({ annotationId: id, x: 70, y: 85, animation: "pop" }),+ ).document?.annotations.find((a) => a.id === id);+ expect(centreOf(moved)).toEqual({ x: expect.closeTo(70, 5), y: expect.closeTo(85, 5) });+ expect(moved?.style.textAnimation).toBe("pop");++ const retexted = executeAgentTool(+ added.document as AxcutDocument,+ "setAnnotation",+ JSON.stringify({ annotationId: id, text: "A much longer callout than before" }),+ ).document?.annotations.find((a) => a.id === id);+ expect(retexted?.size.width).toBeGreaterThan(moved?.size.width ?? 0);+ expect(centreOf(retexted)).toEqual({ x: expect.closeTo(30, 5), y: expect.closeTo(30, 5) });+ });++ it("setAspectRatio sets the video's shape, keeping frame text where it was", () => {+ const added = executeAgentTool(+ fixtureDocument(),+ "addAnnotation",+ JSON.stringify({ startSec: 1, endSec: 3, text: "Centred", x: 50, y: 50 }),+ );+ const result = executeAgentTool(+ added.document as AxcutDocument,+ "setAspectRatio",+ JSON.stringify({ aspectRatio: "9:16" }),+ );+ expect(result.ok).toBe(true);+ expect(JSON.parse(result.resultJson)).toMatchObject({ aspectRatio: "9:16" });+ expect((result.document?.legacyEditor as { aspectRatio?: string }).aspectRatio).toBe("9:16");+ expect(centreOf(result.document?.annotations.at(-1))).toEqual({+ x: expect.closeTo(50, 5),+ y: expect.closeTo(50, 5),+ });+ expect(+ executeAgentTool(fixtureDocument(), "setAspectRatio", JSON.stringify({ aspectRatio: "7:3" }))+ .ok,+ ).toBe(false);+ });++ it("refuses a set that would run into another region, instead of landing it elsewhere", () => {+ let document = fixtureDocument();+ const add = (name: string, args: Record<string, unknown>) => {+ const result = executeAgentTool(document, name, JSON.stringify(args));+ document = result.document as AxcutDocument;+ return result;+ };+ const first = add("addAnnotation", { startSec: 1, endSec: 2, text: "One" });+ add("addAnnotation", { startSec: 6, endSec: 8, text: "Two" });+ const firstId = JSON.parse(first.resultJson).annotationId;+ const blocked = executeAgentTool(+ document,+ "setAnnotation",+ JSON.stringify({ annotationId: firstId, startSec: 7, endSec: 9 }),+ );+ expect(blocked.ok).toBe(false);+ expect(blocked.document).toBeUndefined();+ expect(blocked.resultJson).toMatch(/NOT changed.*6\.0|NOT changed/);++ // The same rule for every kind of effect.+ const zoom = add("addZoom", { startSec: 1, endSec: 2, depth: 2 });+ add("addZoom", { startSec: 6, endSec: 8, depth: 4 });+ const zoomId = JSON.parse(zoom.resultJson).zoomId;+ const zoomBlocked = executeAgentTool(+ document,+ "setZoom",+ JSON.stringify({ zoomId, startSec: 7, endSec: 9 }),+ );+ expect(zoomBlocked.ok).toBe(false);+ // A span clear of it still moves.+ expect(+ executeAgentTool(document, "setZoom", JSON.stringify({ zoomId, startSec: 3, endSec: 4 })).ok,+ ).toBe(true);});it("snapshot exposes clips/trims/effects as virtual-time groups with a time-base note", () => {diff --git a/electron/ai-edition/agent-tools.ts b/electron/ai-edition/agent-tools.tsindex e39022dad..3610270e6 100644--- a/electron/ai-edition/agent-tools.ts+++ b/electron/ai-edition/agent-tools.ts@@ -17,6 +17,7 @@import { z } from "zod";import { DEFAULT_TEXT_PLATE } from "../../src/lib/ai-edition/annotations/background";+import { fitTextBox } from "../../src/lib/ai-edition/annotations/placement";import {collapseTracksToPills,patchAudioTrack,@@ -24,6 +25,7 @@ import {trackGroupId,} from "../../src/lib/ai-edition/document/audioTracks";import { createId } from "../../src/lib/ai-edition/document/ids";+import { resolveAspectRatioValue } from "../../src/lib/ai-edition/document/outputFormat";import {moveClip,planTimelineReplacement,@@ -34,7 +36,9 @@ import {setClipSourceRange,} from "../../src/lib/ai-edition/document/timeline";import { setDocumentWordText } from "../../src/lib/ai-edition/document/transcript";-import type { AxcutDocument } from "../../src/lib/ai-edition/schema";+import type { AxcutAnnotationRegion, AxcutDocument } from "../../src/lib/ai-edition/schema";+import { getEditorSettings } from "../../src/lib/ai-edition/store/editorSettings";+import { applySettingsPatch } from "../../src/lib/ai-edition/store/settingsPatch";import { hasAnyClipWithCamera } from "../../src/lib/ai-edition/timeline/camera";import { isGeneratedAssetId } from "../../src/lib/ai-edition/timeline/clip-parts";import {@@ -52,10 +56,6 @@ import {trimAppliesToClip,trimToTimelineSpan,} from "../../src/lib/ai-edition/timeline/trim-mapping";-// ponytail: relative, and it has to stay that way — `electron/` never resolves-// the `@/` alias (the main-process build does not declare it), which is why the-// scale table was moved out of `components/video-editor/types.ts` to be-// reachable from here at all.import {effectiveZoomScale,ZOOM_DEPTH_LEGEND,@@ -66,6 +66,7 @@ import {zoomTransitions,} from "../../src/lib/ai-edition/timeline/zoom-transitions";import { SETTING_BOUNDS } from "../../src/lib/projectDefaults";+import { ASPECT_RATIO_PRESETS } from "../../src/utils/aspectRatioUtils";export interface AgentToolExecution {ok: boolean;@@ -129,6 +130,93 @@ function resolveSpanMs(return { startMs: toMs(Math.min(s, e)), endMs: toMs(Math.max(s, e)) };}+/**+ * For the effect set* tools: the region another span of the same kind would have to cross.+ *+ * `replacePillSpan` follows the editor's drag rule: a region dragged into a neighbour with other+ * settings stops against it, part of the way back to where it started. That is right under a+ * mouse, which shows the stop as it happens. For a caller who named an exact span it put the+ * region somewhere it never asked for (asked 7.6 – 9.5 s, landed 1.5 – 3.3 s), so a set that+ * would be stopped is refused instead, naming what is in the way. The neighbours are the same+ * walls the drag rule sees: other pills with other settings, not ones the region already overlaps.+ */+function refuseIfBlocked<T extends { id: string; startMs: number; endMs: number }>(+ kind: string,+ regions: T[],+ id: string,+ span: { startMs: number; endMs: number },+): AgentToolExecution | null {+ const pills = coalesceRegionsForRuler(regions);+ const pill = pills.find((p) => p.ids.includes(id));+ if (!pill) return null;+ const start = span.startMs / 1000;+ const end = span.endMs / 1000;+ const wall = pills.find(+ (other) =>+ other !== pill &&+ other.identity !== pill.identity &&+ (other.end <= pill.start || other.start >= pill.end) &&+ other.start < end &&+ other.end > start,+ );+ if (!wall) return null;+ return failure(+ `The ${kind} was NOT changed: ${formatSec(start)} – ${formatSec(end)} would run into ${kind} ` ++ `${wall.ids[0]} at ${formatSec(wall.start)} – ${formatSec(wall.end)}, and two ${kind}s with ` ++ "different settings cannot overlap. Move or shorten that one first, or pick a span clear of it.",+ );+}++type AnnotationLook = {+ fontSize?: number;+ color?: string;+ background?: string;+ bold?: boolean;+ animation?: NonNullable<AxcutAnnotationRegion["style"]["textAnimation"]>;+};++/** The look arguments, written onto a style the way the editor's inspector writes them. */+function applyAnnotationLook(+ style: AxcutAnnotationRegion["style"],+ look: AnnotationLook,+): AxcutAnnotationRegion["style"] {+ const next = { ...style };+ if (look.fontSize !== undefined) next.fontSize = look.fontSize;+ if (look.color !== undefined) next.color = look.color;+ if (look.bold !== undefined) next.fontWeight = look.bold ? "bold" : "normal";+ if (look.animation !== undefined) next.textAnimation = look.animation;+ if (look.background !== undefined) {+ if (look.background === "none") {+ // As the inspector's switch does: keep the colour, so turning it back on restores it.+ if (style.backgroundColor !== "transparent") next.lastBackgroundColor = style.backgroundColor;+ next.backgroundColor = "transparent";+ } else {+ next.backgroundColor = look.background;+ }+ }+ return next;+}++/**+ * A text annotation on the output frame, its box sized to its text around `center` (frame+ * percentages): what the editor's "add text" does, so the agent's text sits where the editor's+ * would, is measured the same, and stays put when the picture zooms.+ */+function placeTextOnFrame<T extends AxcutAnnotationRegion>(+ region: T,+ center: { x: number; y: number },+ document: AxcutDocument,+): T {+ const frameAspect = resolveAspectRatioValue(document, getEditorSettings(document).aspectRatio);+ const centred = {+ ...region,+ space: "frame" as const,+ position: center,+ size: { width: 0, height: 0 },+ };+ return { ...centred, ...fitTextBox(centred, frameAspect) };+}+// v5: a modifier is stored as clip-anchored fragment(s), and adjacent regions with the// same properties read as ONE pill (timelineMap merge rule). The agent reasons in VIRTUAL// seconds over whole regions, so we present exactly the pills the user sees, keyed by the@@ -442,6 +530,10 @@ export const setClipRangeArgs = z.object({sourceEndSec: secondsSchema,});+export const setAspectRatioArgs = z.object({+ aspectRatio: z.enum(["auto", ...ASPECT_RATIO_PRESETS]),+});+export const replaceTimelineArgs = z.object({intervals: z.array(z.object({ startSec: secondsSchema, endSec: secondsSchema })).min(1),reason: z.string().default(""),@@ -526,8 +618,25 @@ export const setSpeedArgs = z.object({speed: speedSchema.optional(),});-/** A new text annotation's box, in frame percentages: the editor's own size for one. */-const ANNOTATION_BOX = { width: 30, height: 20 } as const;+/** How a text annotation looks: the settings the editor's inspector offers for one. */+const annotationLookArgs = {+ fontSize: z+ .number()+ .min(8)+ .max(200)+ .optional()+ .describe("Text size; 32 is the editor's default, a title reads well at 56 to 80."),+ color: z.string().optional().describe("Text colour, a CSS colour such as #ffffff."),+ background: z+ .string()+ .optional()+ .describe('Colour of the plate behind the text, or "none" for no plate.'),+ bold: z.boolean().optional(),+ animation: z+ .enum(["none", "fade", "rise", "pop", "slide-left", "typewriter", "pulse"])+ .optional()+ .describe("How the text enters: typewriter types it out, pop springs it in, and so on."),+};export const addAnnotationArgs = z.object({startSec: secondsSchema,@@ -535,6 +644,7 @@ export const addAnnotationArgs = z.object({text: z.string().default(""),x: z.number().min(0).max(100).default(50),y: z.number().min(0).max(100).default(50),+ ...annotationLookArgs,});export const setAnnotationArgs = z.object({@@ -542,6 +652,9 @@ export const setAnnotationArgs = z.object({startSec: secondsSchema.optional(),endSec: secondsSchema.optional(),text: z.string().optional(),+ x: z.number().min(0).max(100).optional(),+ y: z.number().min(0).max(100).optional(),+ ...annotationLookArgs,});export const addAudioArgs = z.object({@@ -646,6 +759,7 @@ export const OPENSCREEN_TOOL_NAMES = ["removeTrim","removeModifier","removeClip",+ "setAspectRatio",] as const;/**@@ -718,6 +832,7 @@ export const MUTATING_TOOL_NAMES: ReadonlySet<string> = new Set(["removeTrim","removeModifier","removeClip",+ "setAspectRatio",]);export function isMutatingTool(name: string): boolean {@@ -851,7 +966,7 @@ export function documentSnapshotForModel(const autoFocusAll = legacy?.autoFocusAll === true;return {timeBaseNote:- "clips and trims are in source-time seconds; zooms, speedRegions, annotations, cameraFullscreenRegions and audioTracks are in virtual (edited-timeline) seconds.",+ "clips and trims are in source-time seconds; zooms, speedRegions, annotations, cameraFullscreenRegions and audioTracks are in virtual (edited-timeline) seconds: the editor's ruler, where a trim leaves a hole instead of shortening it and a speed region stretches nothing. The exported video's clock skips those holes and plays sped-up spans faster, so it differs from the ruler once there are any.",audioNote:"audioTracks are imported voiceover / music files laid over the recording. They are clip-anchored like every other region, so they travel with their clip through reorder and trim, and they play at 1x whatever a speed region does to the picture under them. addAudio places an EXISTING asset of kind 'audio'; nothing here can import a file from disk or record one, so if the project has no audio asset, say so rather than inventing an id.",zoomNote:@@ -1326,6 +1441,20 @@ export function executeAgentTool(}switch (name) {+ case "setAspectRatio": {+ const parsed = setAspectRatioArgs.safeParse(args);+ if (!parsed.success) return failure(parsed.error.message);+ const previous = getEditorSettings(document).aspectRatio;+ // The editor's own write: the frame-placed annotations keep their shape and centre.+ const next = applySettingsPatch(document, { aspectRatio: parsed.data.aspectRatio });+ return {+ ok: true,+ document: next,+ resultJson: JSON.stringify({ aspectRatio: parsed.data.aspectRatio, previous }),+ summary: `set the format to ${parsed.data.aspectRatio}`,+ };+ }+case "getCurrentDocument": {return {ok: true,@@ -2063,6 +2192,8 @@ export function executeAgentTool(const existing = document.zoomRanges.find((z) => z.id === zoomId);if (!existing) return failure(`Unknown zoom: ${zoomId}`);const { startMs, endMs } = resolveSpanMs(existing, parsed.data.startSec, parsed.data.endSec);+ const blocked = refuseIfBlocked("zoom", document.zoomRanges, zoomId, { startMs, endMs });+ if (blocked) return blocked;const zoomPill = new Set(resolvePillIds(document.zoomRanges, zoomId));// ponytail: a depth write CLEARS customScale, and that is the whole// point. `effectiveZoomScale` returns customScale when it is set, so on a@@ -2179,6 +2310,11 @@ export function executeAgentTool(const speedPill = new Set(resolvePillIds(prev, parsed.data.speedId));if (!existing) return failure(`Unknown speed region: ${parsed.data.speedId}`);const { startMs, endMs } = resolveSpanMs(existing, parsed.data.startSec, parsed.data.endSec);+ const blocked = refuseIfBlocked("speed region", prev, parsed.data.speedId, {+ startMs,+ endMs,+ });+ if (blocked) return blocked;const speed = parsed.data.speed ?? existing.speed;const rebuiltSpeeds = replacePillSpan(prev.map((s) => (speedPill.has(s.id) ? { ...s, speed } : s)),@@ -2215,39 +2351,37 @@ export function executeAgentTool(if (!parsed.success) return failure(parsed.error.message);const startMs = toMs(Math.min(parsed.data.startSec, parsed.data.endSec));const endMs = toMs(Math.max(parsed.data.startSec, parsed.data.endSec));- const ann = {- id: createId("ann"),- startMs,- endMs,- type: "text" as const,- content: parsed.data.text,- textContent: parsed.data.text,- // x/y name the text's centre, which is what "default centre" always promised: the- // position is the box's top-left corner, so {50, 50} dropped the text into the- // bottom-right quarter. Kept whole inside the frame.- position: {- x: Math.min(- 100 - ANNOTATION_BOX.width,- Math.max(0, parsed.data.x - ANNOTATION_BOX.width / 2),- ),- y: Math.min(- 100 - ANNOTATION_BOX.height,- Math.max(0, parsed.data.y - ANNOTATION_BOX.height / 2),+ // The editor's new text: its defaults, then whatever look the caller asked for, on the+ // output frame with the box fitted to the text around x/y (the text's centre).+ const ann = placeTextOnFrame(+ {+ id: createId("ann"),+ startMs,+ endMs,+ type: "text" as const,+ content: parsed.data.text,+ textContent: parsed.data.text,+ position: { x: 0, y: 0 },+ size: { width: 0, height: 0 },+ style: applyAnnotationLook(+ {+ color: "#ffffff",+ backgroundColor: DEFAULT_TEXT_PLATE,+ fontSize: 32,+ fontFamily: "Inter",+ fontWeight: "bold",+ fontStyle: "normal",+ textDecoration: "none",+ textAlign: "center",+ textAnimation: "none",+ },+ parsed.data,),- },- size: { ...ANNOTATION_BOX },- style: {- color: "#ffffff",- backgroundColor: DEFAULT_TEXT_PLATE,- fontSize: 32,- fontFamily: "Inter",- fontWeight: "bold" as const,- fontStyle: "normal" as const,- textDecoration: "none" as const,- textAlign: "center" as const,- },- zIndex: document.annotations.length + 1,- };+ zIndex: document.annotations.length + 1,+ } as AxcutAnnotationRegion,+ { x: parsed.data.x, y: parsed.data.y },+ document,+ );const placed = anchorForAgent(ann, document, "ann");const landing = landingOf(placed, document);if (!landing.anchored) {@@ -2278,17 +2412,48 @@ export function executeAgentTool(const annPill = new Set(resolvePillIds(document.annotations, annotationId));if (!existing) return failure(`Unknown annotation: ${annotationId}`);const { startMs, endMs } = resolveSpanMs(existing, parsed.data.startSec, parsed.data.endSec);+ const blocked = refuseIfBlocked("annotation", document.annotations, annotationId, {+ startMs,+ endMs,+ });+ if (blocked) return blocked;+ const { x, y, text } = parsed.data;+ const edit = (a: AxcutAnnotationRegion): AxcutAnnotationRegion => {+ const next: AxcutAnnotationRegion = {+ ...a,+ ...(text !== undefined ? { content: text, textContent: text } : {}),+ style: applyAnnotationLook(a.style, parsed.data),+ };+ const centre = {+ x: x ?? a.position.x + a.size.width / 2,+ y: y ?? a.position.y + a.size.height / 2,+ };+ const moved = x !== undefined || y !== undefined;+ if (a.type === "text") {+ // A text box is the size of its text: refit it whenever the text, its size or its+ // weight changes, around its centre or the new one. One saved before frame placement+ // moves onto the frame the first time it is moved, as the editor does.+ const resized =+ text !== undefined ||+ parsed.data.fontSize !== undefined ||+ parsed.data.bold !== undefined;+ return moved || (resized && a.space === "frame")+ ? placeTextOnFrame(next, centre, document)+ : next;+ }+ if (!moved) return next;+ // An image or an arrow keeps its size and moves its centre, inside its own box.+ const { width, height } = a.size;+ return {+ ...next,+ position: {+ x: Math.min(Math.max(centre.x - width / 2, 0), Math.max(0, 100 - width)),+ y: Math.min(Math.max(centre.y - height / 2, 0), Math.max(0, 100 - height)),+ },+ };+ };const rebuiltAnnotations = replacePillSpan(- document.annotations.map((a) =>- annPill.has(a.id)- ? {- ...a,- ...(parsed.data.text !== undefined- ? { content: parsed.data.text, textContent: parsed.data.text }- : {}),- }- : a,- ),+ document.annotations.map((a) => (annPill.has(a.id) ? edit(a) : a)),annotationId,startMs,endMs,@@ -2362,6 +2527,11 @@ export function executeAgentTool(if (!existing)return failure(`Unknown full-camera region: ${parsed.data.cameraFullscreenId}`);const { startMs, endMs } = resolveSpanMs(existing, parsed.data.startSec, parsed.data.endSec);+ const blocked = refuseIfBlocked("full-camera region", prev, parsed.data.cameraFullscreenId, {+ startMs,+ endMs,+ });+ if (blocked) return blocked;const camPill = new Set(resolvePillIds(prev, parsed.data.cameraFullscreenId));const rebuiltCamera = replacePillSpan(prev,diff --git a/electron/ai-edition/deep-agent/service.test.ts b/electron/ai-edition/deep-agent/service.test.tsindex aa174e6ee..104c64abc 100644--- a/electron/ai-edition/deep-agent/service.test.ts+++ b/electron/ai-edition/deep-agent/service.test.ts@@ -83,6 +83,7 @@ const ARGS: Record<string, unknown> = {removeTrim: { trimRangeId: "trim_1" },removeModifier: { id: "nope" },removeClip: { clipId: "clip_1" },+ setAspectRatio: { aspectRatio: "16:9" },};/** ponytail: the fixture starts from a FIXED instant. `createEmptyDocument` readsdiff --git a/electron/ai-edition/deep-agent/service.ts b/electron/ai-edition/deep-agent/service.tsindex a6fe68089..d11ff757f 100644--- a/electron/ai-edition/deep-agent/service.ts+++ b/electron/ai-edition/deep-agent/service.ts@@ -50,6 +50,7 @@ import {replaceTimelineArgs,resolveCursorAssetId,setAnnotationArgs,+ setAspectRatioArgs,setAudioArgs,setCameraFullscreenArgs,setClipRangeArgs,@@ -111,7 +112,7 @@ const BASE_SYSTEM_PROMPT = ["You can call the tools below against the live document snapshot; the runtime executes each edit and feeds the result back into the loop.","The AxcutDocument is the single source of truth. The timeline, the transcript editor, and the chat panel are all direct editors of the same document — when the user places a clip on the timeline, the document updates immediately, and when the timeline is empty, the document has no clips. Your edits operate on the live document, so preserve the user's placed clips.","",- "Time-bases (do not mix them up): clips and trims are in SOURCE-time seconds of an asset; zooms, speed regions, annotations and camera-fullscreen regions are in VIRTUAL (edited-timeline) seconds — the position on the ruler after clips + trims are applied. getCurrentDocument returns all of them, clearly labelled.",+ "Time-bases (do not mix them up): clips and trims are in SOURCE-time seconds of an asset; zooms, speed regions, annotations and camera-fullscreen regions are in VIRTUAL (edited-timeline) seconds — the position on the editor's ruler, where the clips sit end to end. A trim leaves a hole in that ruler rather than shortening it, and a speed region does not stretch it, so the exported video's own clock differs from it as soon as there is a trim or a speed region: always place effects in ruler seconds. getCurrentDocument returns all of them, clearly labelled.","",// ponytail: these describe what each tool is FOR, deliberately without quoting// user phrasings. A phrase→tool table reads as helpful and is not: it swaps the@@ -123,6 +124,7 @@ const BASE_SYSTEM_PROMPT = ["- Cutting specific spoken words (fillers, a repeated or flubbed phrase, a false start, a duplicate take) is removeWords: read getTranscriptWords, choose the occurrences from their surrounding speech, then pass that assetId and ONLY those word IDs. Word IDs restart for each asset, so keep the read's assetId. Consecutive words become one cut. Do not cut every occurrence of a word just because its text matches one you were asked to remove.","- Changing where a clip starts or ends within its source is setClipRange — the clip's in/out, distinct from a trim.",`- addZoom takes a virtual-timeline span (depth is an ordinal 1–6 selecting from a fixed table — ${ZOOM_DEPTH_LEGEND} — never a multiplier; focus in 0–1 frame fractions). addSpeed changes pacing over a span. addAnnotation puts text on screen. addCameraFullscreen enlarges the webcam, and only does something where assets[].hasCameraTrack is true.`,+ "- setAspectRatio picks the shape of the whole video, for where it will be shown; auto follows the recording.","- A zoom animates in just before its span and out just after it (zoomInFromSec, zoomOutUntilSec in getCurrentDocument). Leave those windows untrimmed, or the export jumps at the cut.","- addAudio lays an imported voiceover or music file over a span. It plays an asset the project already has (kind 'audio'); importing or recording one is the editor's job, not a tool you have — so when the project has none, say so rather than naming an id that does not exist.","- moveClip changes the order of placed clips, one call per clip that moves, preserving ids, source ranges, trims and anchored effects. replaceTimeline rebuilds the timeline from kept intervals and sorts them, so it cannot reorder anything.",@@ -181,9 +183,11 @@ export const TOOL_DESCRIPTIONS: Record<string, string> = {setSpeed:"Move, resize, or change the multiplier of an existing speed region by id (virtual-timeline seconds). Only the fields you pass are changed.",addAnnotation:- "Add a text annotation over a span of the edited timeline (virtual seconds). x/y place the text's centre, in frame percentages (0–100, default the frame's centre); the box stays inside the frame. It is drawn on a dark plate so it reads on any footage. Use for callouts and labels.",+ "Add a text annotation over a span of the edited timeline (virtual seconds). It sits on the output frame, the whole picture padding included, as text added in the editor does: zooms and padding never move it. x/y place the text's centre in frame percentages (0–100, default the centre); the box is sized to the text and kept inside the frame. By default it is drawn on a dark plate so it reads on any footage; fontSize, color, background, bold and animation set its look. Use for callouts, labels and titles.",setAnnotation:- "Move, resize, or edit the text of an existing annotation by id (virtual-timeline seconds). Only the fields you pass are changed.",+ "Change an existing annotation by id: its span (virtual-timeline seconds), its text, its centre (x/y, frame percentages) or its look (fontSize, color, background, bold, animation). Only the fields you pass are changed; a text box is refitted to its text around its centre. A new span that would run into another annotation is refused, naming it.",+ setAspectRatio:+ "Set the shape of the exported video: 16:9 for X, YouTube or a slide, 9:16 for a vertical story or short, 1:1 or 4:5 for a square feed, auto to follow the recording. Annotations on the frame keep their place and shape.",addCameraFullscreen:"Add a camera-fullscreen region over a span of the edited timeline (virtual seconds): the webcam fills the frame for that span. This only does something when the footage under that span comes from an asset with a linked webcam — check assets[].hasCameraTrack (or hasAnyCamera) in getCurrentDocument first. On footage with no camera the call is refused rather than storing a region that would render nothing; say so instead of retrying.",setCameraFullscreen:@@ -393,6 +397,7 @@ export const TOOL_ARG_SCHEMAS: ReadonlyArray<readonly [string, z.ZodObject]> = [["removeTrim", removeTrimArgs],["removeModifier", removeModifierArgs],["removeClip", removeClipArgs],+ ["setAspectRatio", setAspectRatioArgs],];/**diff --git a/src/lib/ai-edition/store/settingsPatch.ts b/src/lib/ai-edition/store/settingsPatch.tsnew file mode 100644index 000000000..89d00dc6b--- /dev/null+++ b/src/lib/ai-edition/store/settingsPatch.ts@@ -0,0 +1,26 @@+// A settings patch applied to a document, with what it implies for the rest of it. Pure, so the+// editor's hook and the agent's tools apply a setting through the same code.++import { refitFrameAnnotations } from "../annotations/placement";+import { resolveAspectRatioValue } from "../document/outputFormat";+import type { AxcutDocument } from "../schema";+import { type EditorSettingsPatch, getEditorSettings, patchEditorSettings } from "./editorSettings";++/**+ * `patchEditorSettings`, plus what a new format does to the annotations placed on the frame:+ * each keeps its shape and its centre (`refitFrameAnnotations`), in the same write, so one undo+ * takes both back.+ */+export function applySettingsPatch(doc: AxcutDocument, patch: EditorSettingsPatch): AxcutDocument {+ const next = patchEditorSettings(doc, patch);+ // ponytail: only a format picked in the settings refits. Under Auto the frame can also+ // reshape when clips change, and those annotations keep their shares of the frame; refit+ // there too if that shows up in practice.+ if (patch.aspectRatio === undefined) return next;+ const annotations = refitFrameAnnotations(+ next.annotations,+ resolveAspectRatioValue(doc, getEditorSettings(doc).aspectRatio),+ resolveAspectRatioValue(next, getEditorSettings(next).aspectRatio),+ );+ return annotations === next.annotations ? next : { ...next, annotations };+}diff --git a/src/lib/ai-edition/store/useEditorSettings.ts b/src/lib/ai-edition/store/useEditorSettings.tsindex d104f5454..11f7698c9 100644--- a/src/lib/ai-edition/store/useEditorSettings.ts+++ b/src/lib/ai-edition/store/useEditorSettings.ts@@ -13,35 +13,14 @@// extra state, no caches — the document is the single source of truth.import { useCallback, useEffect, useMemo, useRef } from "react";-import { refitFrameAnnotations } from "../annotations/placement";-import { resolveAspectRatioValue } from "../document/outputFormat";import type { AxcutDocument } from "../schema";import {type EditorSettingsPatch,type EditorSettingsSnapshot,getEditorSettings,- patchEditorSettings,} from "./editorSettings";import { useProjectStore } from "./projectStore";--/**- * `patchEditorSettings`, plus what a new format does to the annotations placed on the frame:- * each keeps its shape and its centre (`refitFrameAnnotations`), in the same write, so one undo- * takes both back.- */-export function applySettingsPatch(doc: AxcutDocument, patch: EditorSettingsPatch): AxcutDocument {- const next = patchEditorSettings(doc, patch);- // ponytail: only a format picked in the settings refits. Under Auto the frame can also- // reshape when clips change, and those annotations keep their shares of the frame; refit- // there too if that shows up in practice.- if (patch.aspectRatio === undefined) return next;- const annotations = refitFrameAnnotations(- next.annotations,- resolveAspectRatioValue(doc, getEditorSettings(doc).aspectRatio),- resolveAspectRatioValue(next, getEditorSettings(next).aspectRatio),- );- return annotations === next.annotations ? next : { ...next, annotations };-}+import { applySettingsPatch } from "./settingsPatch";export interface UseEditorSettingsResult {settings: EditorSettingsSnapshot;diff --git a/src/lib/ai-edition/timeline/zoom-suggestions.ts b/src/lib/ai-edition/timeline/zoom-suggestions.tsindex 9ca9709b5..8df686f48 100644--- a/src/lib/ai-edition/timeline/zoom-suggestions.ts+++ b/src/lib/ai-edition/timeline/zoom-suggestions.ts@@ -12,9 +12,7 @@// automatic zoom.import type { CursorTelemetryPoint, ZoomFocus } from "@/components/video-editor/types";-// Relative, not `@/`: the main process plans a fresh MCP take's zooms with this file,-// and its build does not resolve the alias.-import { zoomTransitionMs } from "../../zoomMath/constants";+import { zoomTransitionMs } from "@/lib/zoomMath/constants";import type { AxcutClip } from "../schema";import { DEFAULT_ZOOM_DEPTH, ZOOM_DEPTH_SCALES, type ZoomDepth } from "./zoom-scale";diff --git a/vite.config.ts b/vite.config.tsindex 7261f2197..cb1bffcbf 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -33,6 +33,14 @@ export default defineConfig({},vite: {build: {},+ // The main process runs code from `src/lib` too (the agent's tools, the MCP+ // server): it resolves `@/` as the renderer does, or every such import fails+ // the build.+ resolve: {+ alias: {+ "@": path.resolve(__dirname, "src"),+ },+ },},},preload: {