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(schema): keep the migration composer out of the aliased module graph
Etienne Lescot0fbd4af0513a
diff --git a/electron/ai-edition/document-service.ts b/electron/ai-edition/document-service.tsindex 98881ee11..08201eed2 100644--- a/electron/ai-edition/document-service.ts+++ b/electron/ai-edition/document-service.ts@@ -13,12 +13,12 @@import fs, { type FileHandle } from "node:fs/promises";import path from "node:path";import { createId } from "../../src/lib/ai-edition/document/ids";-import { migrateRawDocumentToCurrent } from "../../src/lib/ai-edition/document/migrate";import {type AxcutAsset,type AxcutDocument,createEmptyDocument,documentSchema,+ migrateRawDocumentToCurrent,} from "../../src/lib/ai-edition/schema";const PROJECT_FILE_EXTENSION = ".openscreen";diff --git a/src/components/ai-edition/EditorEmptyState.test.tsx b/src/components/ai-edition/EditorEmptyState.test.tsxindex a8f1e457a..9b33082b6 100644--- a/src/components/ai-edition/EditorEmptyState.test.tsx+++ b/src/components/ai-edition/EditorEmptyState.test.tsx@@ -21,11 +21,11 @@ const bridgeMocks = vi.hoisted(() => ({}));const sampleDoc = vi.hoisted(() => ({- // ponytail: the bridge contract after the migration hoist is v5 — every+ // ponytail: the bridge contract after the migration hoist is v6 — every// load site (DocumentService, browserShim) runs `migrateRawDocumentToCurrent`// before returning, and the renderer's `parseDocument` is a pure v6// validator. Test fixtures model the post-hoist contract.- schemaVersion: 5,+ schemaVersion: 6,project: {id: "proj_test",title: "Test",diff --git a/src/lib/ai-edition/schema/index.test.ts b/src/lib/ai-edition/schema/index.test.tsindex 80f06ad59..fb5ce1cac 100644--- a/src/lib/ai-edition/schema/index.test.ts+++ b/src/lib/ai-edition/schema/index.test.ts@@ -567,56 +567,58 @@ describe("v5 -> v6 native AspectRatio migration", () => {});it("picks the largest clip when the timeline is mixed-shape", () => {- const doc = documentSchema.parse(migrateRawDocumentToCurrent({- schemaVersion: 5,- project: {- id: "p1",- title: "mixed",- createdAt: "2024-01-01T00:00:00.000Z",- updatedAt: "2024-01-01T00:00:00.000Z",- },- assets: [- {- id: "asset_f",- kind: "video",- label: "A",- originalPath: "/a.mp4",- cameraTrack: null,- video: { width: 1920, height: 1080 },- },- {- id: "asset_g",- kind: "video",- label: "B",- originalPath: "/b.mp4",- cameraTrack: null,- video: { width: 2160, height: 3840 },+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent({+ schemaVersion: 5,+ project: {+ id: "p1",+ title: "mixed",+ createdAt: "2024-01-01T00:00:00.000Z",+ updatedAt: "2024-01-01T00:00:00.000Z",},- ],- timeline: {- clips: [+ assets: [{- id: "clip_a",- assetId: "asset_f",- sourceStartSec: 0,- sourceEndSec: 10,- timelineStartSec: 0,- timelineEndSec: 10,- origin: "user",+ id: "asset_f",+ kind: "video",+ label: "A",+ originalPath: "/a.mp4",+ cameraTrack: null,+ video: { width: 1920, height: 1080 },},{- id: "clip_b",- assetId: "asset_g",- sourceStartSec: 0,- sourceEndSec: 10,- timelineStartSec: 10,- timelineEndSec: 20,- origin: "user",+ id: "asset_g",+ kind: "video",+ label: "B",+ originalPath: "/b.mp4",+ cameraTrack: null,+ video: { width: 2160, height: 3840 },},],- },- legacyEditor: { aspectRatio: "native" },- }));+ timeline: {+ clips: [+ {+ id: "clip_a",+ assetId: "asset_f",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ origin: "user",+ },+ {+ id: "clip_b",+ assetId: "asset_g",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 10,+ timelineEndSec: 20,+ origin: "user",+ },+ ],+ },+ legacyEditor: { aspectRatio: "native" },+ }),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("9:16");});@@ -625,19 +627,25 @@ describe("v5 -> v6 native AspectRatio migration", () => {// Deliberately NOT a 16:9 fallback: an empty/unprobed timeline gives no basis// for a concrete token, and guessing one persists a wrong frame. See the v1.7// import case below.- const doc = documentSchema.parse(migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "native" } })));+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "native" } })),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("native");});it("passes through a concrete aspectRatio unchanged", () => {- const doc = documentSchema.parse(migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "4:5" } })));+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "4:5" } })),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("4:5");});it("passes through a legacyEditor without aspectRatio unchanged", () => {- const doc = documentSchema.parse(migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { someOtherField: "preserved" } })));+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { someOtherField: "preserved" } })),+ );expect(doc.schemaVersion).toBe(6);const legacy = doc.legacyEditor as Record<string, unknown>;expect(legacy.someOtherField).toBe("preserved");@@ -652,7 +660,9 @@ describe("v5 -> v6 native AspectRatio migration", () => {});it("is idempotent — re-parsing an already-v6 document changes nothing", () => {- const once = documentSchema.parse(migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "16:9" } })));+ const once = documentSchema.parse(+ migrateRawDocumentToCurrent(makeV5Doc({ legacyEditor: { aspectRatio: "16:9" } })),+ );const twice = documentSchema.parse(once);expect(twice).toEqual(once);});@@ -664,39 +674,41 @@ describe("v5 -> v6 native AspectRatio migration", () => {// reframing every portrait v1.7 project saved with "Native". Leave the// sentinel; it resolves dynamically at runtime and converts on a later load,// once useTimeline's probe has written `asset.video` back.- const doc = documentSchema.parse(migrateRawDocumentToCurrent({- schemaVersion: 5,- project: {- id: "p1",- title: "from v1.7",- createdAt: "2024-01-01T00:00:00.000Z",- updatedAt: "2024-01-01T00:00:00.000Z",- },- assets: [- {- id: "asset_u",- kind: "video",- label: "A",- originalPath: "/a.mp4",- cameraTrack: null,- // no `video` — exactly what the v2 import produces+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent({+ schemaVersion: 5,+ project: {+ id: "p1",+ title: "from v1.7",+ createdAt: "2024-01-01T00:00:00.000Z",+ updatedAt: "2024-01-01T00:00:00.000Z",},- ],- timeline: {- clips: [+ assets: [{- id: "clip_a",- assetId: "asset_u",- sourceStartSec: 0,- sourceEndSec: 10,- timelineStartSec: 0,- timelineEndSec: 10,- origin: "user",+ id: "asset_u",+ kind: "video",+ label: "A",+ originalPath: "/a.mp4",+ cameraTrack: null,+ // no `video` — exactly what the v2 import produces},],- },- legacyEditor: { aspectRatio: "native" },- }));+ timeline: {+ clips: [+ {+ id: "clip_a",+ assetId: "asset_u",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ origin: "user",+ },+ ],+ },+ legacyEditor: { aspectRatio: "native" },+ }),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("native");});@@ -704,39 +716,41 @@ describe("v5 -> v6 native AspectRatio migration", () => {it("converts 'native' once the probe has persisted dimensions", () => {// Second load of the same project, after useTimeline probed a PORTRAIT source.// This is the case that must not become 16:9.- const doc = documentSchema.parse(migrateRawDocumentToCurrent({- schemaVersion: 5,- project: {- id: "p1",- title: "from v1.7, probed",- createdAt: "2024-01-01T00:00:00.000Z",- updatedAt: "2024-01-01T00:00:00.000Z",- },- assets: [- {- id: "asset_u",- kind: "video",- label: "A",- originalPath: "/a.mp4",- cameraTrack: null,- video: { width: 1080, height: 1920 },+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent({+ schemaVersion: 5,+ project: {+ id: "p1",+ title: "from v1.7, probed",+ createdAt: "2024-01-01T00:00:00.000Z",+ updatedAt: "2024-01-01T00:00:00.000Z",},- ],- timeline: {- clips: [+ assets: [{- id: "clip_a",- assetId: "asset_u",- sourceStartSec: 0,- sourceEndSec: 10,- timelineStartSec: 0,- timelineEndSec: 10,- origin: "user",+ id: "asset_u",+ kind: "video",+ label: "A",+ originalPath: "/a.mp4",+ cameraTrack: null,+ video: { width: 1080, height: 1920 },},],- },- legacyEditor: { aspectRatio: "native" },- }));+ timeline: {+ clips: [+ {+ id: "clip_a",+ assetId: "asset_u",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ origin: "user",+ },+ ],+ },+ legacyEditor: { aspectRatio: "native" },+ }),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("9:16");});@@ -745,40 +759,42 @@ describe("v5 -> v6 native AspectRatio migration", () => {// "native" resolved to the cropped clip at runtime. A 3840x2160 asset cropped// to its left half is effectively 1920x2160 → 8:9. Reading the raw dims would// wrongly yield 16:9 and silently reframe the project.- const doc = documentSchema.parse(migrateRawDocumentToCurrent({- schemaVersion: 5,- project: {- id: "p1",- title: "cropped",- createdAt: "2024-01-01T00:00:00.000Z",- updatedAt: "2024-01-01T00:00:00.000Z",- },- assets: [- {- id: "asset_c",- kind: "video",- label: "A",- originalPath: "/a.mp4",- cameraTrack: null,- video: { width: 3840, height: 2160 },+ const doc = documentSchema.parse(+ migrateRawDocumentToCurrent({+ schemaVersion: 5,+ project: {+ id: "p1",+ title: "cropped",+ createdAt: "2024-01-01T00:00:00.000Z",+ updatedAt: "2024-01-01T00:00:00.000Z",},- ],- timeline: {- clips: [+ assets: [{- id: "clip_a",- assetId: "asset_c",- sourceStartSec: 0,- sourceEndSec: 10,- timelineStartSec: 0,- timelineEndSec: 10,- origin: "user",- cropRegion: { x: 0, y: 0, width: 0.5, height: 1 },+ id: "asset_c",+ kind: "video",+ label: "A",+ originalPath: "/a.mp4",+ cameraTrack: null,+ video: { width: 3840, height: 2160 },},],- },- legacyEditor: { aspectRatio: "native" },- }));+ timeline: {+ clips: [+ {+ id: "clip_a",+ assetId: "asset_c",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ origin: "user",+ cropRegion: { x: 0, y: 0, width: 0.5, height: 1 },+ },+ ],+ },+ legacyEditor: { aspectRatio: "native" },+ }),+ );expect(doc.schemaVersion).toBe(6);expect((doc.legacyEditor as Record<string, unknown>).aspectRatio).toBe("8:9");});diff --git a/src/native/browserShim.ts b/src/native/browserShim.tsindex 2cb16e8cb..c02377556 100644--- a/src/native/browserShim.ts+++ b/src/native/browserShim.ts@@ -4,7 +4,7 @@// rapid iteration without the Electron window overhead.import { PROVIDER_DEFINITIONS } from "../../electron/ai-edition/provider-registry";-import { migrateRawDocumentToCurrent } from "../lib/ai-edition/document/migrate";+import { axcutSchemaVersion, migrateRawDocumentToCurrent } from "../lib/ai-edition/schema";import { nativeBridgeClient as realClient } from "./client";function detectBrowserMode(): boolean {@@ -120,7 +120,6 @@ function createShimElectronAPI() {sendCloseConfirmResponse: () => undefined,onRequestCloseConfirm: () => () => undefined,onRequestSaveBeforeClose: () => () => undefined,- onAiEditionChatEvent: () => () => undefined,loadProjectFileFromPath: () => Promise.resolve({ success: false, canceled: true }),getPathForFile: () => "",getSources: () => Promise.resolve(SHIM_SOURCES),@@ -347,11 +346,11 @@ function createShimBridgeClient() {},create: (title?: string) => {const doc: ShimDocument = {- // ponytail: write v5 directly. The shim's IIFE above migrates any- // stale v3 entries on init, and new projects are minted at the- // current schema version so the renderer's `documentSchema.parse`- // (a pure v6 validator) accepts the returned document.- schemaVersion: 5,+ // Mint at the current schema version so the renderer's+ // `documentSchema.parse` (a pure validator, no migration) accepts+ // the returned document. Must never be a literal: this value has to+ // track `axcutSchemaVersion` on every schema bump.+ schemaVersion: axcutSchemaVersion,project: {id: `proj_${Math.random().toString(36).slice(2, 10)}`,title: title || "Untitled Project",@@ -489,6 +488,52 @@ function createShimBridgeClient() {success: false,error: "[browser-shim] No agent tool batches to undo in browser mode.",}),+ chatRunDefault: (projectId: string, message?: string) => {+ // ponytail: legacy single-session consumers — pick the most+ // recent session or auto-create one.+ const sessions = getSessions(projectId);+ let s = [...sessions.values()].sort((a, b) => b.createdAt.localeCompare(a.createdAt))[0];+ if (!s) {+ s = {+ id: `sess_${Date.now()}`,+ projectId,+ title: "Conversation 1",+ createdAt: new Date().toISOString(),+ messages: [],+ };+ sessions.set(s.id, s);+ }+ if (message) {+ s.messages.push({+ id: `msg_${Date.now()}_u`,+ role: "user",+ content: message,+ createdAt: new Date().toISOString(),+ });+ }+ const assistantMessage = {+ id: `msg_${Date.now()}_a`,+ role: "assistant" as const,+ content:+ "[browser-shim] AI features need real LLM deps. Configure a provider in Settings, install the LangChain packages, then chat will work for real.",+ createdAt: new Date().toISOString(),+ };+ s.messages.push(assistantMessage);+ persistChat();+ return Promise.resolve({ success: true, assistantMessage });+ },+ chatHistory: (projectId: string) => {+ const m = sessionsByProject.get(projectId);+ if (!m || m.size === 0) return Promise.resolve([]);+ const arr = Array.from(m.values()).sort((a, b) => b.createdAt.localeCompare(a.createdAt));+ return Promise.resolve([...arr[0].messages]);+ },+ chatClear: (projectId: string) => {+ const m = sessionsByProject.get(projectId);+ if (m) for (const s of m.values()) s.messages = [];+ persistChat();+ return Promise.resolve({ success: true });+ },chatListSessions: (projectId: string) => {const m = sessionsByProject.get(projectId);if (!m) return Promise.resolve([]);