@morshoto/framekit 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +68 -5
- package/dist-package/adapters/final-cut/typescript/src/background-materialization.js +175 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery.js +31 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-verification.js +16 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +600 -56
- package/dist-package/adapters/final-cut/typescript/src/connection.js +52 -14
- package/dist-package/adapters/final-cut/typescript/src/fcpxml-console-experiment.js +74 -0
- package/dist-package/adapters/final-cut/typescript/src/index.js +9 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +11 -4
- package/dist-package/adapters/final-cut/typescript/src/native.js +321 -19
- package/dist-package/adapters/final-cut/typescript/src/session.js +19 -1
- package/dist-package/adapters/final-cut/typescript/src/shadow-mutation.js +174 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-experiment.js +472 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-inspection.js +433 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-materialization.js +230 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.js +372 -0
- package/dist-package/adapters/final-cut/typescript/src/unattended-editing.js +66 -0
- package/dist-package/apps/mcp-server/src/headless-sessions.js +112 -0
- package/dist-package/apps/mcp-server/src/main.js +36 -2
- package/dist-package/apps/mcp-server/src/materialization-jobs.js +326 -0
- package/dist-package/apps/mcp-server/src/routing.js +17 -0
- package/dist-package/apps/mcp-server/src/server.js +146 -12
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +52 -6
- package/dist-package/packages/runtime/src/context/project-catalog.js +46 -1
- package/dist-package/packages/runtime/src/index.js +2 -0
- package/dist-package/packages/runtime/src/skills/builtin.js +99 -8
- package/dist-package/packages/runtime/src/skills/runtime.js +1 -0
- package/dist-package/packages/runtime/src/timeline/drift-reconciliation.js +295 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.js +490 -0
- package/package.json +10 -6
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { addRationalTimes } from "./rational-time.js";
|
|
3
|
+
import { parseRational } from "./rational-time.js";
|
|
4
|
+
import { reconcileTimelineIr } from "./drift-reconciliation.js";
|
|
5
|
+
export const TIMELINE_IR_SCHEMA_VERSION = 1;
|
|
6
|
+
export class EditingSession {
|
|
7
|
+
value;
|
|
8
|
+
clock;
|
|
9
|
+
constructor(document, clock) {
|
|
10
|
+
validateEditingSessionDocument(document);
|
|
11
|
+
this.value = structuredClone(document);
|
|
12
|
+
this.clock = clock ?? (() => new Date().toISOString());
|
|
13
|
+
}
|
|
14
|
+
static create(options) {
|
|
15
|
+
validateTimelineIr(options.base);
|
|
16
|
+
const base = structuredClone(options.base);
|
|
17
|
+
return new EditingSession({
|
|
18
|
+
schemaVersion: TIMELINE_IR_SCHEMA_VERSION,
|
|
19
|
+
...(options.provider ? { provider: { ...options.provider } } : {}),
|
|
20
|
+
base,
|
|
21
|
+
desired: structuredClone(base),
|
|
22
|
+
state: "clean",
|
|
23
|
+
}, options.clock);
|
|
24
|
+
}
|
|
25
|
+
static fromJSON(input, clock) {
|
|
26
|
+
let value;
|
|
27
|
+
try {
|
|
28
|
+
value = typeof input === "string" ? JSON.parse(input) : input;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`TIMELINE_IR_INVALID: session JSON is malformed: ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
}
|
|
33
|
+
const document = asRecord(value);
|
|
34
|
+
if (!document)
|
|
35
|
+
throw new Error("TIMELINE_IR_INVALID: session must be an object");
|
|
36
|
+
validateEditingSessionDocument(document);
|
|
37
|
+
return new EditingSession(document, clock);
|
|
38
|
+
}
|
|
39
|
+
document() {
|
|
40
|
+
return structuredClone(this.value);
|
|
41
|
+
}
|
|
42
|
+
base() {
|
|
43
|
+
return structuredClone(this.value.base);
|
|
44
|
+
}
|
|
45
|
+
desired() {
|
|
46
|
+
return structuredClone(this.value.desired);
|
|
47
|
+
}
|
|
48
|
+
state() {
|
|
49
|
+
return this.value.state;
|
|
50
|
+
}
|
|
51
|
+
serialize() {
|
|
52
|
+
return stableJson(this.value);
|
|
53
|
+
}
|
|
54
|
+
preview(operations, expectedRevision = this.value.desired.revision) {
|
|
55
|
+
assertRevision(this.value.desired.revision, expectedRevision);
|
|
56
|
+
const before = structuredClone(this.value.desired);
|
|
57
|
+
const after = this.nextTimeline(before, operations);
|
|
58
|
+
const changed = changedIds(before, after);
|
|
59
|
+
return {
|
|
60
|
+
baseRevision: this.value.base.revision,
|
|
61
|
+
before,
|
|
62
|
+
after,
|
|
63
|
+
operations: structuredClone(operations),
|
|
64
|
+
...changed,
|
|
65
|
+
state: changedOccurrenceOrMarkers(changed) ? editState(this.value.state) : this.value.state,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
apply(operations, expectedRevision = this.value.desired.revision) {
|
|
69
|
+
const preview = this.preview(operations, expectedRevision);
|
|
70
|
+
this.value.desired = preview.after;
|
|
71
|
+
if (changedOccurrenceOrMarkers(preview)) {
|
|
72
|
+
this.value.desired.revision = nextRevision(preview.after, this.value.desired.revision, this.clock());
|
|
73
|
+
this.value.state = editState(this.value.state);
|
|
74
|
+
preview.after = structuredClone(this.value.desired);
|
|
75
|
+
preview.state = this.value.state;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
...preview,
|
|
79
|
+
state: this.value.state,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
assertMaterializationReady(providerRevision) {
|
|
83
|
+
if (!sameRevision(this.value.base.revision, providerRevision)) {
|
|
84
|
+
this.value.state = "possibly_stale";
|
|
85
|
+
throw new Error("RECONCILIATION_REQUIRED: provider revision changed before materialization");
|
|
86
|
+
}
|
|
87
|
+
if (this.value.state === "possibly_stale" || this.value.state === "conflicted") {
|
|
88
|
+
throw new Error("RECONCILIATION_REQUIRED: session must be reconciled before materialization");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
reconcile(providerState) {
|
|
92
|
+
if (!sameRevision(this.value.base.revision, providerState.revision))
|
|
93
|
+
this.value.state = "possibly_stale";
|
|
94
|
+
const result = reconcileTimelineIr({ base: this.value.base, ours: this.value.desired, theirs: providerState });
|
|
95
|
+
if (result.status === "conflicted") {
|
|
96
|
+
this.value.state = "conflicted";
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
this.value.base = structuredClone(providerState);
|
|
100
|
+
this.value.desired = structuredClone(result.merged);
|
|
101
|
+
if (timelineIrDigest(this.value.desired) !== timelineIrDigest(this.value.base)) {
|
|
102
|
+
const previous = this.value.desired.revision.sequence >= providerState.revision.sequence
|
|
103
|
+
? this.value.desired.revision
|
|
104
|
+
: providerState.revision;
|
|
105
|
+
this.value.desired.revision = nextRevision(this.value.desired, previous, this.clock());
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.value.desired = structuredClone(providerState);
|
|
109
|
+
}
|
|
110
|
+
this.value.state = "rebased";
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
markPossiblyStale() {
|
|
114
|
+
this.value.state = "possibly_stale";
|
|
115
|
+
}
|
|
116
|
+
bindObservation(observation) {
|
|
117
|
+
const previous = this.value.observation;
|
|
118
|
+
if (previous && previous.sourceId !== observation.sourceId) {
|
|
119
|
+
throw new Error("SESSION_OBSERVATION_SOURCE_MISMATCH: observation source changed");
|
|
120
|
+
}
|
|
121
|
+
this.value.observation = structuredClone(observation);
|
|
122
|
+
if (!previous)
|
|
123
|
+
return "observed";
|
|
124
|
+
if (previous.digest === observation.digest && previous.schemaVersion === observation.schemaVersion)
|
|
125
|
+
return "unchanged";
|
|
126
|
+
this.value.state = "possibly_stale";
|
|
127
|
+
return "changed";
|
|
128
|
+
}
|
|
129
|
+
markConflicted() {
|
|
130
|
+
this.value.state = "conflicted";
|
|
131
|
+
}
|
|
132
|
+
markRebased() {
|
|
133
|
+
this.value.state = "rebased";
|
|
134
|
+
}
|
|
135
|
+
markWaitingForMaterialization() {
|
|
136
|
+
this.value.state = "waiting_for_materialization";
|
|
137
|
+
}
|
|
138
|
+
markClean() {
|
|
139
|
+
this.value.state = timelineIrDigest(this.value.base) === timelineIrDigest(this.value.desired) ? "clean" : "dirty";
|
|
140
|
+
}
|
|
141
|
+
nextTimeline(before, operations) {
|
|
142
|
+
const after = structuredClone(before);
|
|
143
|
+
for (const operation of operations)
|
|
144
|
+
applyOperation(after, operation);
|
|
145
|
+
validateTimelineIr(after);
|
|
146
|
+
return after;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export function createTimelineIrFromProjectSnapshot(snapshot, provider) {
|
|
150
|
+
const binding = provider ? (kind, identity) => ({
|
|
151
|
+
provider: provider.id,
|
|
152
|
+
kind,
|
|
153
|
+
identity,
|
|
154
|
+
}) : undefined;
|
|
155
|
+
const resources = snapshot.media.map((media) => ({
|
|
156
|
+
id: media.mediaId,
|
|
157
|
+
name: sourceName(media.source, media.mediaId),
|
|
158
|
+
mediaKind: media.mediaKind ?? "unknown",
|
|
159
|
+
source: media.source,
|
|
160
|
+
...(media.sourceDigest ? { sourceDigest: media.sourceDigest } : {}),
|
|
161
|
+
...(binding ? { binding: binding("resource", media.mediaId) } : {}),
|
|
162
|
+
}));
|
|
163
|
+
const occurrences = snapshot.timeline.clips.map((clip) => ({
|
|
164
|
+
id: clip.id,
|
|
165
|
+
name: clip.name,
|
|
166
|
+
startTime: normalizeRationalTime(clip.startTime),
|
|
167
|
+
durationTime: normalizeRationalTime(clip.durationTime),
|
|
168
|
+
...(clip.sourceStartTime ? { sourceStartTime: normalizeRationalTime(clip.sourceStartTime) } : {}),
|
|
169
|
+
track: clip.track,
|
|
170
|
+
...(clip.role ? { role: clip.role } : {}),
|
|
171
|
+
...(clip.mediaId ? { mediaId: clip.mediaId } : {}),
|
|
172
|
+
...(clip.gainDb !== undefined ? { gainDb: clip.gainDb } : {}),
|
|
173
|
+
...(clip.fadeIn !== undefined ? { fadeIn: clip.fadeIn } : {}),
|
|
174
|
+
...(clip.fadeOut !== undefined ? { fadeOut: clip.fadeOut } : {}),
|
|
175
|
+
...(clip.enabled !== undefined ? { enabled: clip.enabled } : {}),
|
|
176
|
+
...(clip.attachedTo ? { attachedTo: clip.attachedTo } : {}),
|
|
177
|
+
...(binding ? { binding: binding("occurrence", clip.id) } : {}),
|
|
178
|
+
}));
|
|
179
|
+
const storyElements = snapshot.timeline.storyElements.map((element) => storyElementToIr(element, binding));
|
|
180
|
+
const markers = snapshot.timeline.markers.map((marker) => ({
|
|
181
|
+
id: marker.id,
|
|
182
|
+
name: marker.name,
|
|
183
|
+
startTime: requiredRational(marker.startTime, `marker ${marker.id} startTime`),
|
|
184
|
+
durationTime: requiredRational(marker.durationTime, `marker ${marker.id} durationTime`),
|
|
185
|
+
}));
|
|
186
|
+
const captions = snapshot.timeline.captions.map((caption) => ({
|
|
187
|
+
id: caption.id,
|
|
188
|
+
text: caption.text,
|
|
189
|
+
startTime: requiredRational(caption.startTime, `caption ${caption.id} startTime`),
|
|
190
|
+
durationTime: requiredRational(caption.durationTime, `caption ${caption.id} durationTime`),
|
|
191
|
+
}));
|
|
192
|
+
return {
|
|
193
|
+
schemaVersion: TIMELINE_IR_SCHEMA_VERSION,
|
|
194
|
+
project: {
|
|
195
|
+
id: snapshot.projectId,
|
|
196
|
+
name: snapshot.projectName,
|
|
197
|
+
...(binding ? { binding: binding("project", snapshot.projectId) } : {}),
|
|
198
|
+
},
|
|
199
|
+
sequence: {
|
|
200
|
+
id: snapshot.timeline.id,
|
|
201
|
+
name: snapshot.timeline.name,
|
|
202
|
+
durationTime: requiredRational(snapshot.timeline.durationTime, "timeline durationTime"),
|
|
203
|
+
frameDuration: requiredRational(snapshot.timeline.frameDuration, "timeline frameDuration"),
|
|
204
|
+
occurrences,
|
|
205
|
+
storyElements,
|
|
206
|
+
markers,
|
|
207
|
+
captions,
|
|
208
|
+
...(binding ? { binding: binding("sequence", snapshot.timeline.id) } : {}),
|
|
209
|
+
},
|
|
210
|
+
resources,
|
|
211
|
+
revision: structuredClone(snapshot.revision),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function validateTimelineIr(timeline) {
|
|
215
|
+
if (!timeline || typeof timeline !== "object" || timeline.schemaVersion !== TIMELINE_IR_SCHEMA_VERSION) {
|
|
216
|
+
throw new Error("TIMELINE_IR_INVALID: schemaVersion must be 1");
|
|
217
|
+
}
|
|
218
|
+
if (!timeline.project || typeof timeline.project !== "object")
|
|
219
|
+
throw new Error("TIMELINE_IR_INVALID: project is required");
|
|
220
|
+
if (!timeline.sequence || typeof timeline.sequence !== "object")
|
|
221
|
+
throw new Error("TIMELINE_IR_INVALID: sequence is required");
|
|
222
|
+
if (!Array.isArray(timeline.resources))
|
|
223
|
+
throw new Error("TIMELINE_IR_INVALID: resources must be an array");
|
|
224
|
+
if (!Array.isArray(timeline.sequence.occurrences))
|
|
225
|
+
throw new Error("TIMELINE_IR_INVALID: occurrences must be an array");
|
|
226
|
+
if (!Array.isArray(timeline.sequence.storyElements))
|
|
227
|
+
throw new Error("TIMELINE_IR_INVALID: storyElements must be an array");
|
|
228
|
+
if (!Array.isArray(timeline.sequence.markers))
|
|
229
|
+
throw new Error("TIMELINE_IR_INVALID: markers must be an array");
|
|
230
|
+
if (!Array.isArray(timeline.sequence.captions))
|
|
231
|
+
throw new Error("TIMELINE_IR_INVALID: captions must be an array");
|
|
232
|
+
requireText(timeline.project?.id, "project.id");
|
|
233
|
+
requireText(timeline.project?.name, "project.name");
|
|
234
|
+
requireText(timeline.sequence?.id, "sequence.id");
|
|
235
|
+
requireText(timeline.sequence?.name, "sequence.name");
|
|
236
|
+
validateRational(timeline.sequence.durationTime, "sequence.durationTime", false);
|
|
237
|
+
validateRational(timeline.sequence.frameDuration, "sequence.frameDuration", true);
|
|
238
|
+
validateRevision(timeline.revision);
|
|
239
|
+
validateBinding(timeline.project.binding, "project.binding");
|
|
240
|
+
validateBinding(timeline.sequence.binding, "sequence.binding");
|
|
241
|
+
const resourceIds = uniqueIds(timeline.resources.map((resource) => resource.id), "resource");
|
|
242
|
+
for (const resource of timeline.resources) {
|
|
243
|
+
requireText(resource.name, `resource ${resource.id}.name`);
|
|
244
|
+
if (!["video", "audio", "unknown"].includes(resource.mediaKind)) {
|
|
245
|
+
throw new Error(`TIMELINE_IR_INVALID: resource ${resource.id} has unsupported mediaKind`);
|
|
246
|
+
}
|
|
247
|
+
validateBinding(resource.binding, `resource ${resource.id}.binding`);
|
|
248
|
+
}
|
|
249
|
+
const occurrenceIds = uniqueIds(timeline.sequence.occurrences.map((occurrence) => occurrence.id), "occurrence");
|
|
250
|
+
for (const occurrence of timeline.sequence.occurrences) {
|
|
251
|
+
requireText(occurrence.name, `occurrence ${occurrence.id}.name`);
|
|
252
|
+
validateRational(occurrence.startTime, `occurrence ${occurrence.id}.startTime`, false);
|
|
253
|
+
validateRational(occurrence.durationTime, `occurrence ${occurrence.id}.durationTime`, true);
|
|
254
|
+
if (!Number.isInteger(occurrence.track) || occurrence.track < 0) {
|
|
255
|
+
throw new Error(`TIMELINE_IR_INVALID: occurrence ${occurrence.id}.track must be a non-negative integer`);
|
|
256
|
+
}
|
|
257
|
+
if (occurrence.mediaId && !resourceIds.has(occurrence.mediaId)) {
|
|
258
|
+
throw new Error(`TIMELINE_IR_INVALID: occurrence ${occurrence.id} references unknown resource ${occurrence.mediaId}`);
|
|
259
|
+
}
|
|
260
|
+
if (occurrence.attachedTo && !occurrenceIds.has(occurrence.attachedTo)) {
|
|
261
|
+
throw new Error(`TIMELINE_IR_INVALID: occurrence ${occurrence.id} references unknown attachment ${occurrence.attachedTo}`);
|
|
262
|
+
}
|
|
263
|
+
if (occurrence.sourceStartTime)
|
|
264
|
+
validateRational(occurrence.sourceStartTime, `occurrence ${occurrence.id}.sourceStartTime`, false);
|
|
265
|
+
if (occurrence.gainDb !== undefined && !Number.isFinite(occurrence.gainDb))
|
|
266
|
+
throw new Error(`TIMELINE_IR_INVALID: occurrence ${occurrence.id}.gainDb must be finite`);
|
|
267
|
+
validateBinding(occurrence.binding, `occurrence ${occurrence.id}.binding`);
|
|
268
|
+
}
|
|
269
|
+
uniqueIds(timeline.sequence.storyElements.map((element) => element.id), "story element");
|
|
270
|
+
for (const element of timeline.sequence.storyElements) {
|
|
271
|
+
requireText(element.kind, `story element ${element.id}.kind`);
|
|
272
|
+
validateRational(element.startTime, `story element ${element.id}.startTime`, false);
|
|
273
|
+
validateRational(element.durationTime, `story element ${element.id}.durationTime`, true);
|
|
274
|
+
if (element.occurrenceId && !occurrenceIds.has(element.occurrenceId))
|
|
275
|
+
throw new Error(`TIMELINE_IR_INVALID: story element ${element.id} references unknown occurrence`);
|
|
276
|
+
validateBinding(element.binding, `story element ${element.id}.binding`);
|
|
277
|
+
}
|
|
278
|
+
uniqueIds(timeline.sequence.markers.map((marker) => marker.id), "marker");
|
|
279
|
+
for (const marker of timeline.sequence.markers) {
|
|
280
|
+
requireText(marker.name, `marker ${marker.id}.name`);
|
|
281
|
+
validateRational(marker.startTime, `marker ${marker.id}.startTime`, false);
|
|
282
|
+
validateRational(marker.durationTime, `marker ${marker.id}.durationTime`, false);
|
|
283
|
+
}
|
|
284
|
+
uniqueIds(timeline.sequence.captions.map((caption) => caption.id), "caption");
|
|
285
|
+
for (const caption of timeline.sequence.captions) {
|
|
286
|
+
requireText(caption.text, `caption ${caption.id}.text`);
|
|
287
|
+
validateRational(caption.startTime, `caption ${caption.id}.startTime`, false);
|
|
288
|
+
validateRational(caption.durationTime, `caption ${caption.id}.durationTime`, false);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export function validateEditingSessionDocument(document) {
|
|
292
|
+
if (!document || typeof document !== "object" || document.schemaVersion !== TIMELINE_IR_SCHEMA_VERSION) {
|
|
293
|
+
throw new Error("TIMELINE_IR_INVALID: session schemaVersion must be 1");
|
|
294
|
+
}
|
|
295
|
+
if (document.provider) {
|
|
296
|
+
requireText(document.provider.id, "provider.id");
|
|
297
|
+
if (document.provider.version !== undefined)
|
|
298
|
+
requireText(document.provider.version, "provider.version");
|
|
299
|
+
}
|
|
300
|
+
validateTimelineIr(document.base);
|
|
301
|
+
validateTimelineIr(document.desired);
|
|
302
|
+
if (document.base.project.id !== document.desired.project.id || document.base.sequence.id !== document.desired.sequence.id) {
|
|
303
|
+
throw new Error("TIMELINE_IR_INVALID: base and desired targets must match");
|
|
304
|
+
}
|
|
305
|
+
if (!["clean", "dirty", "possibly_stale", "conflicted", "rebased", "waiting_for_materialization"].includes(document.state)) {
|
|
306
|
+
throw new Error("TIMELINE_IR_INVALID: unsupported session state");
|
|
307
|
+
}
|
|
308
|
+
if (document.observation)
|
|
309
|
+
validateEditingSessionObservation(document.observation);
|
|
310
|
+
}
|
|
311
|
+
function validateEditingSessionObservation(observation) {
|
|
312
|
+
if (!observation.backend || !observation.sourceId || !observation.databaseKind || !observation.digest) {
|
|
313
|
+
throw new Error("TIMELINE_IR_INVALID: session observation identity is incomplete");
|
|
314
|
+
}
|
|
315
|
+
if (!Number.isInteger(observation.schemaVersion) || observation.schemaVersion < 0) {
|
|
316
|
+
throw new Error("TIMELINE_IR_INVALID: session observation schemaVersion must be non-negative");
|
|
317
|
+
}
|
|
318
|
+
if (observation.canonical !== false || observation.coverageComplete !== false) {
|
|
319
|
+
throw new Error("TIMELINE_IR_INVALID: storage observation cannot be canonical or complete");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
export function timelineIrDigest(timeline) {
|
|
323
|
+
const content = structuredClone(timeline);
|
|
324
|
+
delete content.revision;
|
|
325
|
+
return createHash("sha256").update(stableJson(content)).digest("hex");
|
|
326
|
+
}
|
|
327
|
+
function applyOperation(timeline, operation) {
|
|
328
|
+
const occurrence = operation.type === "add-marker" ? undefined : timeline.sequence.occurrences.find(({ id }) => id === operation.occurrenceId);
|
|
329
|
+
if (operation.type !== "add-marker" && !occurrence)
|
|
330
|
+
throw new Error(`TIMELINE_IR_OPERATION_INVALID: occurrence not found: ${operation.occurrenceId}`);
|
|
331
|
+
switch (operation.type) {
|
|
332
|
+
case "rename-occurrence":
|
|
333
|
+
requireText(operation.name, "operation.name");
|
|
334
|
+
occurrence.name = operation.name;
|
|
335
|
+
return;
|
|
336
|
+
case "trim-occurrence":
|
|
337
|
+
occurrence.durationTime = normalizeRationalTime(operation.durationTime);
|
|
338
|
+
validateRational(occurrence.durationTime, "operation.durationTime", true);
|
|
339
|
+
timeline.sequence.durationTime = maxRational(timeline.sequence.durationTime, addRationalTimes(occurrence.startTime, occurrence.durationTime));
|
|
340
|
+
return;
|
|
341
|
+
case "move-occurrence":
|
|
342
|
+
occurrence.startTime = normalizeRationalTime(operation.startTime);
|
|
343
|
+
validateRational(occurrence.startTime, "operation.startTime", false);
|
|
344
|
+
if (operation.track !== undefined) {
|
|
345
|
+
if (!Number.isInteger(operation.track) || operation.track < 0)
|
|
346
|
+
throw new Error("TIMELINE_IR_OPERATION_INVALID: track must be a non-negative integer");
|
|
347
|
+
occurrence.track = operation.track;
|
|
348
|
+
}
|
|
349
|
+
timeline.sequence.durationTime = maxRational(timeline.sequence.durationTime, addRationalTimes(occurrence.startTime, occurrence.durationTime));
|
|
350
|
+
return;
|
|
351
|
+
case "set-gain":
|
|
352
|
+
if (!Number.isFinite(operation.gainDb))
|
|
353
|
+
throw new Error("TIMELINE_IR_OPERATION_INVALID: gainDb must be finite");
|
|
354
|
+
occurrence.gainDb = operation.gainDb;
|
|
355
|
+
return;
|
|
356
|
+
case "remove-occurrence":
|
|
357
|
+
timeline.sequence.occurrences = timeline.sequence.occurrences.filter(({ id }) => id !== operation.occurrenceId);
|
|
358
|
+
timeline.sequence.storyElements = timeline.sequence.storyElements.filter(({ occurrenceId }) => occurrenceId !== operation.occurrenceId);
|
|
359
|
+
return;
|
|
360
|
+
case "add-marker":
|
|
361
|
+
validateMarker(operation.marker);
|
|
362
|
+
if (timeline.sequence.markers.some(({ id }) => id === operation.marker.id))
|
|
363
|
+
throw new Error(`TIMELINE_IR_OPERATION_INVALID: marker already exists: ${operation.marker.id}`);
|
|
364
|
+
timeline.sequence.markers.push({ ...structuredClone(operation.marker), startTime: normalizeRationalTime(operation.marker.startTime), durationTime: normalizeRationalTime(operation.marker.durationTime) });
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function validateMarker(marker) {
|
|
369
|
+
requireText(marker.id, "marker.id");
|
|
370
|
+
requireText(marker.name, `marker ${marker.id}.name`);
|
|
371
|
+
validateRational(marker.startTime, `marker ${marker.id}.startTime`, false);
|
|
372
|
+
validateRational(marker.durationTime, `marker ${marker.id}.durationTime`, false);
|
|
373
|
+
}
|
|
374
|
+
function storyElementToIr(element, binding) {
|
|
375
|
+
return {
|
|
376
|
+
id: element.id,
|
|
377
|
+
kind: element.kind,
|
|
378
|
+
startTime: requiredRational(element.startTime, `story element ${element.id} startTime`),
|
|
379
|
+
durationTime: requiredRational(element.durationTime, `story element ${element.id} durationTime`),
|
|
380
|
+
...(element.lane !== undefined ? { lane: element.lane } : {}),
|
|
381
|
+
...(element.text !== undefined ? { text: element.text } : {}),
|
|
382
|
+
...(element.attachedTo ? { attachedTo: element.attachedTo } : {}),
|
|
383
|
+
...(binding ? { binding: binding("story-element", element.id) } : {}),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function requiredRational(value, field) {
|
|
387
|
+
if (!value)
|
|
388
|
+
throw new Error(`TIMELINE_IR_INVALID: ${field} is required`);
|
|
389
|
+
validateRational(value, field, false);
|
|
390
|
+
return normalizeRationalTime(value);
|
|
391
|
+
}
|
|
392
|
+
function validateRational(value, field, requirePositive) {
|
|
393
|
+
const parsed = parseRational(value, "TIMELINE_IR_INVALID");
|
|
394
|
+
if (parsed.value < 0n)
|
|
395
|
+
throw new Error(`TIMELINE_IR_INVALID: ${field} cannot be negative`);
|
|
396
|
+
if (requirePositive && parsed.value <= 0n)
|
|
397
|
+
throw new Error(`TIMELINE_IR_INVALID: ${field} must be positive`);
|
|
398
|
+
}
|
|
399
|
+
function validateRevision(revision) {
|
|
400
|
+
requireText(revision?.id, "revision.id");
|
|
401
|
+
if (!Number.isSafeInteger(revision.sequence) || revision.sequence < 0)
|
|
402
|
+
throw new Error("TIMELINE_IR_INVALID: revision.sequence must be a non-negative safe integer");
|
|
403
|
+
requireText(revision.timestamp, "revision.timestamp");
|
|
404
|
+
}
|
|
405
|
+
function validateBinding(binding, field) {
|
|
406
|
+
if (!binding)
|
|
407
|
+
return;
|
|
408
|
+
requireText(binding.provider, `${field}.provider`);
|
|
409
|
+
requireText(binding.kind, `${field}.kind`);
|
|
410
|
+
if (![
|
|
411
|
+
"project",
|
|
412
|
+
"sequence",
|
|
413
|
+
"resource",
|
|
414
|
+
"occurrence",
|
|
415
|
+
"story-element",
|
|
416
|
+
].includes(binding.kind))
|
|
417
|
+
throw new Error(`TIMELINE_IR_INVALID: ${field}.kind is unsupported`);
|
|
418
|
+
requireText(binding.identity, `${field}.identity`);
|
|
419
|
+
}
|
|
420
|
+
function requireText(value, field) {
|
|
421
|
+
if (typeof value !== "string" || !value.trim())
|
|
422
|
+
throw new Error(`TIMELINE_IR_INVALID: ${field} must be non-empty`);
|
|
423
|
+
}
|
|
424
|
+
function uniqueIds(values, label) {
|
|
425
|
+
const ids = new Set();
|
|
426
|
+
for (const value of values) {
|
|
427
|
+
requireText(value, `${label}.id`);
|
|
428
|
+
if (ids.has(value))
|
|
429
|
+
throw new Error(`TIMELINE_IR_INVALID: duplicate ${label} id ${value}`);
|
|
430
|
+
ids.add(value);
|
|
431
|
+
}
|
|
432
|
+
return ids;
|
|
433
|
+
}
|
|
434
|
+
function normalizeRationalTime(value) {
|
|
435
|
+
const parsed = parseRational(value, "TIMELINE_IR_INVALID");
|
|
436
|
+
const absolute = parsed.value < 0n ? -parsed.value : parsed.value;
|
|
437
|
+
const divisor = greatestCommonDivisor(absolute, parsed.timescale);
|
|
438
|
+
return { value: String(parsed.value / divisor), timescale: String(parsed.timescale / divisor) };
|
|
439
|
+
}
|
|
440
|
+
function maxRational(left, right) {
|
|
441
|
+
const leftParts = parseRational(left, "TIMELINE_IR_INVALID");
|
|
442
|
+
const rightParts = parseRational(right, "TIMELINE_IR_INVALID");
|
|
443
|
+
return leftParts.value * rightParts.timescale >= rightParts.value * leftParts.timescale ? left : right;
|
|
444
|
+
}
|
|
445
|
+
function greatestCommonDivisor(left, right) {
|
|
446
|
+
while (right !== 0n) {
|
|
447
|
+
const remainder = left % right;
|
|
448
|
+
left = right;
|
|
449
|
+
right = remainder;
|
|
450
|
+
}
|
|
451
|
+
return left || 1n;
|
|
452
|
+
}
|
|
453
|
+
function nextRevision(timeline, previous, timestamp) {
|
|
454
|
+
return { id: `ir:${timelineIrDigest(timeline)}`, sequence: previous.sequence + 1, timestamp };
|
|
455
|
+
}
|
|
456
|
+
function assertRevision(actual, expected) {
|
|
457
|
+
if (actual.id !== expected.id || actual.sequence !== expected.sequence)
|
|
458
|
+
throw new Error("STALE_CONTEXT: desired timeline revision changed before editing");
|
|
459
|
+
}
|
|
460
|
+
function sameRevision(left, right) {
|
|
461
|
+
return left.id === right.id && left.sequence === right.sequence;
|
|
462
|
+
}
|
|
463
|
+
function changedIds(before, after) {
|
|
464
|
+
const occurrenceIds = new Set([...before.sequence.occurrences, ...after.sequence.occurrences].map(({ id }) => id));
|
|
465
|
+
const markerIds = new Set([...before.sequence.markers, ...after.sequence.markers].map(({ id }) => id));
|
|
466
|
+
return {
|
|
467
|
+
changedOccurrenceIds: [...occurrenceIds].filter((id) => JSON.stringify(before.sequence.occurrences.find((item) => item.id === id)) !== JSON.stringify(after.sequence.occurrences.find((item) => item.id === id))),
|
|
468
|
+
changedMarkerIds: [...markerIds].filter((id) => JSON.stringify(before.sequence.markers.find((item) => item.id === id)) !== JSON.stringify(after.sequence.markers.find((item) => item.id === id))),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function changedOccurrenceOrMarkers(changed) {
|
|
472
|
+
return changed.changedOccurrenceIds.length > 0 || changed.changedMarkerIds.length > 0;
|
|
473
|
+
}
|
|
474
|
+
function editState(state) {
|
|
475
|
+
return state === "possibly_stale" || state === "conflicted" || state === "rebased" || state === "waiting_for_materialization" ? state : "dirty";
|
|
476
|
+
}
|
|
477
|
+
function sourceName(source, fallback) {
|
|
478
|
+
return source.split(/[\\/]/).pop() || fallback;
|
|
479
|
+
}
|
|
480
|
+
function stableJson(value) {
|
|
481
|
+
if (value === null || typeof value !== "object")
|
|
482
|
+
return JSON.stringify(value);
|
|
483
|
+
if (Array.isArray(value))
|
|
484
|
+
return `[${value.map(stableJson).join(",")}]`;
|
|
485
|
+
const entries = Object.entries(value).filter(([, child]) => child !== undefined).sort(([left], [right]) => left.localeCompare(right));
|
|
486
|
+
return `{${entries.map(([key, child]) => `${JSON.stringify(key)}:${stableJson(child)}`).join(",")}}`;
|
|
487
|
+
}
|
|
488
|
+
function asRecord(value) {
|
|
489
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
490
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morshoto/framekit",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"packageManager": "pnpm@12.
|
|
3
|
+
"version": "0.1.12",
|
|
4
|
+
"packageManager": "pnpm@12.5.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Agentic video editing runtime and MCP server for Final Cut Pro",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test:golden": "tsx --test tests/golden/*.test.ts",
|
|
30
30
|
"test:release-gate": "tsx --test tests/release-gate/*.test.ts",
|
|
31
31
|
"release-gate": "tsx scripts/run-release-gate.ts",
|
|
32
|
+
"acceptance:v0112": "tsx scripts/run-v0112-acceptance.ts",
|
|
32
33
|
"release-report": "tsx scripts/generate-release-report.ts",
|
|
33
34
|
"verify-release-provenance": "tsx scripts/verify-release-provenance.ts",
|
|
34
35
|
"test:codex-plugin": "node scripts/codex-plugin-smoke.mjs",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"test:final-cut-project-selection-headed": "node scripts/final-cut-project-selection-headed-e2e.mjs",
|
|
42
43
|
"test:final-cut-canonical-headed": "node scripts/final-cut-canonical-headed-e2e.mjs",
|
|
43
44
|
"test:final-cut-filler-headed": "node scripts/final-cut-filler-removal-headed-e2e.mjs",
|
|
45
|
+
"test:final-cut-dialogue-headed": "node scripts/final-cut-dialogue-normalization-headed-e2e.mjs",
|
|
44
46
|
"test:watch": "tsx --test --watch tests/integration/*.test.ts tests/evaluation/*.test.ts tests/filler-removal/*.test.ts tests/golden/*.test.ts",
|
|
45
47
|
"test:final-cut-disposable-headed": "node scripts/final-cut-disposable-native-headed-e2e.mjs",
|
|
46
48
|
"test:final-cut-transition-headed": "node scripts/final-cut-transition-headed-e2e.mjs",
|
|
@@ -49,7 +51,9 @@
|
|
|
49
51
|
"test:final-cut-title-headed": "node scripts/final-cut-title-discovery-headed-e2e.mjs",
|
|
50
52
|
"test:final-cut-rough-cut-headed": "node scripts/final-cut-rough-cut-headed-e2e.mjs",
|
|
51
53
|
"test:final-cut-background-headed": "node scripts/final-cut-background-regression-headed-e2e.mjs",
|
|
54
|
+
"test:final-cut-fcpxml-console-experiment": "node --import tsx scripts/final-cut-fcpxml-console-experiment.mjs",
|
|
52
55
|
"hooks:install": "node scripts/install-git-hooks.mjs",
|
|
56
|
+
"check:git-config": "node scripts/check-git-config.mjs",
|
|
53
57
|
"mcp": "tsx apps/mcp-server/src/main.ts",
|
|
54
58
|
"framekit": "node ./bin/framekit.mjs",
|
|
55
59
|
"package:final-cut-release": "bash scripts/package-final-cut-release.sh",
|
|
@@ -73,10 +77,10 @@
|
|
|
73
77
|
"zod": "^3.25.76"
|
|
74
78
|
},
|
|
75
79
|
"devDependencies": {
|
|
76
|
-
"@openai/codex": "0.
|
|
77
|
-
"@types/node": "24.13.
|
|
78
|
-
"c8": "
|
|
79
|
-
"tsc-alias": "1.9.
|
|
80
|
+
"@openai/codex": "0.155.1",
|
|
81
|
+
"@types/node": "24.13.6",
|
|
82
|
+
"c8": "12.0.0",
|
|
83
|
+
"tsc-alias": "1.9.5",
|
|
80
84
|
"tsx": "4.23.13",
|
|
81
85
|
"typescript": "7.0.2"
|
|
82
86
|
}
|