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(mcp): read an export through the document it rendered
EtienneLescot4d948298e3ff
diff --git a/electron/ai-edition/agent-tools.test.ts b/electron/ai-edition/agent-tools.test.tsindex d0f17a2f6..aa1801f38 100644--- a/electron/ai-edition/agent-tools.test.ts+++ b/electron/ai-edition/agent-tools.test.ts@@ -784,7 +784,9 @@ describe("executeAgentTool", () => {);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(+ (result.document?.legacyEditor as { aspectRatio?: string } | undefined)?.aspectRatio,+ ).toBe("9:16");expect(centreOf(result.document?.annotations.at(-1))).toEqual({x: expect.closeTo(50, 5),y: expect.closeTo(50, 5),diff --git a/electron/mcp/media-tools.test.ts b/electron/mcp/media-tools.test.tsindex 0470c15a6..1ce39955f 100644--- a/electron/mcp/media-tools.test.ts+++ b/electron/mcp/media-tools.test.ts@@ -387,12 +387,13 @@ describe("exportVideo", () => {expect(runners.open).toBe(0);});- it("refuses a path that is not a video, and reports a failed render", async () => {- expect((await call("exportVideo", { projectId: "proj_x", path: "out.mov" })).isError).toBe(- true,- );+ it("refuses a path that is not a video or an unknown project, and reports a failed render", async () => {+ const { projectId } = await recordTake();+ expect((await call("exportVideo", { projectId, path: "out.mov" })).isError).toBe(true);+ const unknown = await call("exportVideo", { projectId: "proj_x", path: "out.mp4" });+ expect(textOf(unknown)).toContain('No project has the id "proj_x"');runners.results.export = { success: false, error: "compositor exploded" };- const failed = await call("exportVideo", { projectId: "proj_x", path: "out.gif" });+ const failed = await call("exportVideo", { projectId, path: "out.gif" });expect(failed.isError).toBe(true);expect(textOf(failed)).toContain("compositor exploded");expect(runners.started.at(-1)).toMatchObject({ format: "gif" });@@ -417,10 +418,13 @@ describe("getFrames on a project", () => {]);expect(labels[0]).not.toContain("changed after this export");- // An edit after the export is flagged, so a stale video is never taken for the edit.- await call("addAnnotation", { projectId, startSec: 5, endSec: 7, text: "New" });+ // A cut made after the export is flagged, and does not move which frame of THAT video+ // a ruler second shows: the mapping is the exported document's.+ await call("addTrim", { projectId, startSec: 4.5, endSec: 5.5 });const stale = await call("getFrames", { projectId, atSec: [6] });expect(textOf(stale)).toContain("changed after this export");+ const staleLabels = stale.content.flatMap((part) => (part.type === "text" ? [part.text] : []));+ expect(staleLabels[1]).toBe("6.00s on the ruler, 4.00s into the video");});it("takes a project or a file, not both", async () => {diff --git a/electron/mcp/media-tools.ts b/electron/mcp/media-tools.tsindex 8472b81d6..53ef61306 100644--- a/electron/mcp/media-tools.ts+++ b/electron/mcp/media-tools.ts@@ -165,7 +165,7 @@ export function registerMediaTools(server: McpServer, deps: MediaToolDeps): void/** When each take of this session started, by its video: setPointerTrack's clock. */const startedAtByVideo = new Map<string, number>();/** Each project's last export of this session, and when it was made: what getFrames reads. */- const lastExports = new Map<string, { path: string; at: string }>();+ const lastExports = new Map<string, { path: string; at: Date; rendered: AxcutDocument }>();/** A runner's result, its hidden window closed: this server outlives every runner. */async function finish(run: ReturnType<MediaToolDeps["runners"]["start"]>) {@@ -486,6 +486,12 @@ export function registerMediaTools(server: McpServer, deps: MediaToolDeps): voidconst progressToken = extra._meta?.progressToken;exporting = true;try {+ // The project as the export reads it, and when: getFrames maps ruler seconds through+ // THIS document's cuts and speeds, and calls anything saved after `at` a change the+ // video does not have.+ const at = new Date();+ const rendered = await deps.documents.getProject(args.projectId).catch(() => null);+ if (!rendered) return text(`No project has the id "${args.projectId}".`, true);const run = deps.runners.start({kind: "export",@@ -516,10 +522,7 @@ export function registerMediaTools(server: McpServer, deps: MediaToolDeps): voidif (!result.success) {return text(`The export failed: ${result.error ?? "unknown error"}`, true);}- lastExports.set(args.projectId, {- path: result.outputPath ?? outPath,- at: new Date().toISOString(),- });+ lastExports.set(args.projectId, { path: result.outputPath ?? outPath, at, rendered });return text(JSON.stringify({path: result.outputPath,@@ -573,11 +576,14 @@ export function registerMediaTools(server: McpServer, deps: MediaToolDeps): voidif (!exported) {return text("This project has no export yet: call exportVideo first.", true);}- const document = await deps.documents.getProject(args.projectId);+ // Mapped through the document the export rendered, so a cut made since cannot shift+ // which frame of this video is shown; the current one only says whether it is stale.+ const { rendered } = exported;videoPath = exported.path;- toVideoSec = (sec) => programmeSecOf(document, sec);- rulerEndSec = Math.max(0, ...document.timeline.clips.map((clip) => clip.timelineEndSec));- if (document.project.updatedAt > exported.at) {+ toVideoSec = (sec) => programmeSecOf(rendered, sec);+ rulerEndSec = Math.max(0, ...rendered.timeline.clips.map((clip) => clip.timelineEndSec));+ const current = await deps.documents.getProject(args.projectId);+ if (Date.parse(current.project.updatedAt) > exported.at.getTime()) {note = " The project changed after this export: export it again to see the changes.";}} else {