@morshoto/framekit 0.1.0 → 0.1.5

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.
Files changed (65) hide show
  1. package/README.md +42 -17
  2. package/dist-package/adapters/final-cut/typescript/src/analyzers.js +86 -2
  3. package/dist-package/adapters/final-cut/typescript/src/connection.js +5 -1
  4. package/dist-package/adapters/final-cut/typescript/src/export.js +231 -8
  5. package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +70 -9
  6. package/dist-package/adapters/final-cut/typescript/src/live.js +2 -2
  7. package/dist-package/adapters/final-cut/typescript/src/native.js +1000 -100
  8. package/dist-package/adapters/final-cut/typescript/src/publisher.js +242 -30
  9. package/dist-package/adapters/final-cut/typescript/src/session.js +86 -9
  10. package/dist-package/apps/mcp-server/src/main.js +10 -1
  11. package/dist-package/apps/mcp-server/src/routing.js +172 -0
  12. package/dist-package/apps/mcp-server/src/server.js +867 -52
  13. package/dist-package/apps/mcp-server/src/version.js +34 -0
  14. package/dist-package/packages/runtime/src/application/duration-policy-service.js +6 -0
  15. package/dist-package/packages/runtime/src/application/media-analysis-service.js +473 -0
  16. package/dist-package/packages/runtime/src/application/project-service.js +146 -0
  17. package/dist-package/packages/runtime/src/application/runtime-options.js +1 -0
  18. package/dist-package/packages/runtime/src/application/transaction-store.js +12 -0
  19. package/dist-package/packages/runtime/src/audio/dialogue-normalization.js +64 -0
  20. package/dist-package/packages/runtime/src/audio/noise-reduction.js +46 -0
  21. package/dist-package/packages/runtime/src/capabilities.js +187 -1
  22. package/dist-package/packages/runtime/src/color-correction.js +48 -0
  23. package/dist-package/packages/runtime/src/context/context-engine.js +20 -6
  24. package/dist-package/packages/runtime/src/context/context-service.js +30 -0
  25. package/dist-package/packages/runtime/src/context/revision.js +3 -0
  26. package/dist-package/packages/runtime/src/domain/capabilities.js +1 -0
  27. package/dist-package/packages/runtime/src/domain/context.js +1 -0
  28. package/dist-package/packages/runtime/src/domain/diff.js +1 -0
  29. package/dist-package/packages/runtime/src/domain/duration.js +1 -0
  30. package/dist-package/packages/runtime/src/domain/editing.js +1 -0
  31. package/dist-package/packages/runtime/src/domain/index.js +12 -0
  32. package/dist-package/packages/runtime/src/domain/media.js +8 -0
  33. package/dist-package/packages/runtime/src/domain/ports.js +1 -0
  34. package/dist-package/packages/runtime/src/domain/primitives.js +1 -0
  35. package/dist-package/packages/runtime/src/domain/project.js +1 -0
  36. package/dist-package/packages/runtime/src/domain/rough-cut.js +69 -0
  37. package/dist-package/packages/runtime/src/domain/skills.js +33 -0
  38. package/dist-package/packages/runtime/src/domain/types.js +5 -1
  39. package/dist-package/packages/runtime/src/domain/verification.js +1 -0
  40. package/dist-package/packages/runtime/src/editing/dialogue-normalization-service.js +141 -0
  41. package/dist-package/packages/runtime/src/editing/duration-policy.js +187 -0
  42. package/dist-package/packages/runtime/src/editing/edit-service.js +449 -0
  43. package/dist-package/packages/runtime/src/editing/filler-removal-service.js +361 -0
  44. package/dist-package/packages/runtime/src/editing/music-service.js +85 -0
  45. package/dist-package/packages/runtime/src/index.js +14 -3
  46. package/dist-package/packages/runtime/src/planning/rough-cut.js +71 -0
  47. package/dist-package/packages/runtime/src/runtime.js +131 -826
  48. package/dist-package/packages/runtime/src/skills/builtin.js +339 -0
  49. package/dist-package/packages/runtime/src/skills/index.js +3 -0
  50. package/dist-package/packages/runtime/src/skills/registry.js +74 -0
  51. package/dist-package/packages/runtime/src/skills/requirements.js +170 -0
  52. package/dist-package/packages/runtime/src/skills/runtime.js +239 -0
  53. package/dist-package/packages/runtime/src/speech/analysis.js +301 -0
  54. package/dist-package/packages/runtime/src/speech/filler-detector.js +132 -0
  55. package/dist-package/packages/runtime/src/speech/mapping.js +227 -0
  56. package/dist-package/packages/runtime/src/speech/safe-cut-resolver.js +314 -0
  57. package/dist-package/packages/runtime/src/timeline/rational-time.js +63 -0
  58. package/dist-package/packages/runtime/src/verification/verification.js +712 -1
  59. package/dist-package/packages/testkit/src/fixture-analyzers.js +28 -0
  60. package/dist-package/packages/testkit/src/in-memory-editor.js +287 -3
  61. package/dist-package/packages/testkit/src/index.js +1 -0
  62. package/dist-package/packages/testkit/src/skill-fixtures.js +64 -0
  63. package/package.json +17 -8
  64. /package/dist-package/packages/runtime/src/{diff/diff.js → timeline/snapshot-diff.js} +0 -0
  65. /package/dist-package/packages/runtime/src/{snapshot-digest.js → timeline/snapshot-digest.js} +0 -0
@@ -1,5 +1,6 @@
1
1
  import { execFile as execFileCallback } from "node:child_process";
2
- import { copyFile, mkdtemp, readFile, rm } from "node:fs/promises";
2
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { createHash } from "node:crypto";
3
4
  import { basename, join } from "node:path";
4
5
  import { tmpdir } from "node:os";
5
6
  import { promisify } from "node:util";
@@ -10,40 +11,72 @@ export class FinalCutProjectPublisher {
10
11
  sourcePath;
11
12
  executor;
12
13
  liveState;
13
- waitMs;
14
+ verificationTimeoutMs;
15
+ pollIntervalMs;
14
16
  constructor(options) {
15
17
  this.enabled = options.enabled ?? false;
16
18
  this.sourcePath = options.sourcePath;
17
19
  this.executor = options.executor ?? runAppleScript;
18
20
  this.liveState = options.liveState;
19
- this.waitMs = options.waitMs ?? 1_500;
21
+ this.verificationTimeoutMs = Math.max(0, options.verificationTimeoutMs ?? 15_000);
22
+ this.pollIntervalMs = Math.max(0, options.pollIntervalMs ?? options.waitMs ?? 100);
20
23
  }
21
- async publishNewProject(sourceTransactionId) {
24
+ isAvailable() {
25
+ return this.enabled;
26
+ }
27
+ async publishNewProject(request) {
22
28
  if (!this.enabled)
23
- throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project publishing is disabled; set FRAMEKIT_FINAL_CUT_NATIVE_WRITES=1");
29
+ throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project publishing is disabled; configure FRAMEKIT_EDITOR=final-cut-live and FRAMEKIT_FCPXML_PATH, and ensure Final Cut is reachable through FRAMEKIT_FINAL_CUT_SOCKET");
30
+ if (!request.confirm)
31
+ throw new Error("PUBLISH_CONFIRMATION_REQUIRED: set confirm=true to create a new Final Cut project");
32
+ if (!request.sourceTransactionId.trim())
33
+ throw new Error("INVALID_PUBLISH_REQUEST: sourceTransactionId is required");
34
+ if (!request.artifactDigest.trim())
35
+ throw new Error("INVALID_PUBLISH_REQUEST: artifactDigest is required");
36
+ if (request.artifactPath !== this.sourcePath) {
37
+ throw new Error(`PUBLISH_TARGET_MISMATCH: requested artifact ${request.artifactPath} is not managed by this publisher`);
38
+ }
24
39
  const source = await readFile(this.sourcePath, "utf8");
40
+ if (hash(source) !== request.artifactDigest) {
41
+ throw new Error("PUBLISH_SOURCE_CHANGED: managed FCPXML artifact changed after transaction verification");
42
+ }
25
43
  if (!source.includes("<fcpxml") || !source.includes("<project")) {
26
44
  throw new Error("FINAL_CUT_PUBLISH_VALIDATION_FAILED: source is not a valid FCPXML project artifact");
27
45
  }
28
- const projectName = projectNameFromXml(source);
46
+ const identity = projectIdentityFromXml(source);
47
+ if (!this.liveState) {
48
+ throw new Error("FINAL_CUT_PUBLISH_VERIFICATION_UNAVAILABLE: live project and sequence state is required");
49
+ }
50
+ const beforeLive = await readLiveState(this.liveState, "before import");
29
51
  const directory = await mkdtemp(join(tmpdir(), "framekit-finalcut-publish-"));
30
52
  const importedPath = join(directory, basename(this.sourcePath));
31
- await copyFile(this.sourcePath, importedPath);
53
+ await writeFile(importedPath, source, "utf8");
32
54
  try {
33
55
  await this.executor(importXmlScript(importedPath));
34
- await delay(this.waitMs);
35
- const live = this.liveState ? await this.liveState() : undefined;
36
- if (live && live.project?.name !== projectName) {
37
- throw new Error(`FINAL_CUT_PUBLISH_VERIFICATION_FAILED: expected new project ${projectName}, observed ${live.project?.name ?? "none"}`);
38
- }
56
+ const live = await waitForImportedProject(this.liveState, identity, beforeLive, this.verificationTimeoutMs, this.pollIntervalMs);
39
57
  return {
40
- sourceTransactionId,
58
+ sourceTransactionId: request.sourceTransactionId,
41
59
  sourcePath: this.sourcePath,
60
+ sourceTarget: { kind: "artifact", artifactPath: this.sourcePath },
42
61
  importedPath,
43
- projectName,
62
+ projectName: identity.projectName,
63
+ createdTarget: {
64
+ kind: "editor.project",
65
+ ...(live?.project?.id ? { projectId: live.project.id } : {}),
66
+ ...(live?.sequence?.id ? { sequenceId: live.sequence.id } : {}),
67
+ projectName: identity.projectName,
68
+ ...(live?.sequence?.name ? { sequenceName: live.sequence.name } : {}),
69
+ },
70
+ activeProject: {
71
+ ...(beforeLive.project ? { before: beforeLive.project } : {}),
72
+ ...(live.project ? { after: live.project } : {}),
73
+ ...(beforeLive.project && live.project
74
+ ? { changed: beforeLive.project.id !== live.project.id || beforeLive.project.name !== live.project.name }
75
+ : {}),
76
+ },
44
77
  verified: true,
45
- ...(live?.project?.name ? { liveProject: live.project.name } : {}),
46
- ...(live?.sequence?.name ? { liveSequence: live.sequence.name } : {}),
78
+ ...(live.project?.name ? { liveProject: live.project.name } : {}),
79
+ ...(live.sequence?.name ? { liveSequence: live.sequence.name } : {}),
47
80
  };
48
81
  }
49
82
  finally {
@@ -66,25 +99,157 @@ async function runAppleScript(script) {
66
99
  }
67
100
  function importXmlScript(path) {
68
101
  return `
102
+ using terms from application "System Events"
103
+
104
+ on waitForMenuItem(container, expectedNames, timeoutSeconds, timeoutMessage)
105
+ set deadline to (current date) + timeoutSeconds
106
+ repeat
107
+ repeat with candidate in (menu items of container)
108
+ try
109
+ set candidateName to name of candidate as text
110
+ repeat with expectedName in expectedNames
111
+ if candidateName is (expectedName as text) then return candidate
112
+ end repeat
113
+ end try
114
+ end repeat
115
+ if (current date) > deadline then error timeoutMessage
116
+ delay 0.1
117
+ end repeat
118
+ end waitForMenuItem
119
+
120
+ on waitForSubmenu(menuItem, submenuName, timeoutSeconds, timeoutMessage)
121
+ set deadline to (current date) + timeoutSeconds
122
+ repeat
123
+ try
124
+ if exists menu submenuName of menuItem then return menu submenuName of menuItem
125
+ end try
126
+ if (current date) > deadline then error timeoutMessage
127
+ delay 0.1
128
+ end repeat
129
+ end waitForSubmenu
130
+
131
+ on waitForWindow(finalCut, windowName, timeoutSeconds, timeoutMessage)
132
+ set deadline to (current date) + timeoutSeconds
133
+ repeat
134
+ try
135
+ if exists window windowName of finalCut then return window windowName of finalCut
136
+ end try
137
+ if (current date) > deadline then error timeoutMessage
138
+ delay 0.1
139
+ end repeat
140
+ end waitForWindow
141
+
142
+ on waitForImportSheet(importWindow, timeoutSeconds)
143
+ set deadline to (current date) + timeoutSeconds
144
+ repeat
145
+ try
146
+ if exists sheet 1 of importWindow then return sheet 1 of importWindow
147
+ end try
148
+ if (current date) > deadline then error "FINAL_CUT_PUBLISH_IMPORT_SHEET_TIMEOUT: Import XML sheet did not appear"
149
+ delay 0.1
150
+ end repeat
151
+ end waitForImportSheet
152
+
153
+ on matchesImportPathField(candidate)
154
+ set candidateIdentifier to ""
155
+ set candidateDescription to ""
156
+ try
157
+ set candidateIdentifier to value of attribute "AXIdentifier" of candidate as text
158
+ end try
159
+ try
160
+ set candidateDescription to description of candidate as text
161
+ end try
162
+ if candidateIdentifier is "path" or candidateIdentifier is "location" then return true
163
+ if candidateDescription contains "Go to the folder" then return true
164
+ if candidateDescription contains "path" or candidateDescription contains "location" then return true
165
+ return false
166
+ end matchesImportPathField
167
+
168
+ on locateImportPathField(pathSheet)
169
+ set matchingFields to {}
170
+ repeat with candidate in (text fields of pathSheet)
171
+ if matchesImportPathField(candidate) then set end of matchingFields to candidate
172
+ end repeat
173
+ if (count of matchingFields) is 0 then error "FINAL_CUT_PUBLISH_PATH_CONTROL_UNAVAILABLE: Import XML path control had no accessibility identifier or description"
174
+ if (count of matchingFields) is not 1 then error "FINAL_CUT_PUBLISH_PATH_CONTROL_AMBIGUOUS: Import XML path control was not unique"
175
+ return item 1 of matchingFields
176
+ end locateImportPathField
177
+
178
+ on waitForImportSheetDismissal(importWindow, timeoutSeconds)
179
+ set deadline to (current date) + timeoutSeconds
180
+ repeat
181
+ try
182
+ if not (exists sheet 1 of importWindow) then return
183
+ end try
184
+ if (current date) > deadline then error "FINAL_CUT_PUBLISH_IMPORT_SHEET_DISMISS_TIMEOUT: Import XML sheet did not disappear"
185
+ delay 0.1
186
+ end repeat
187
+ end waitForImportSheetDismissal
188
+
189
+ on waitForImportWindowDismissal(finalCut, timeoutSeconds)
190
+ set deadline to (current date) + timeoutSeconds
191
+ repeat
192
+ try
193
+ if not (exists window "Import XML" of finalCut) then return
194
+ end try
195
+ if (current date) > deadline then error "FINAL_CUT_PUBLISH_IMPORT_TIMEOUT: Import XML window did not close"
196
+ delay 0.1
197
+ end repeat
198
+ end waitForImportWindowDismissal
199
+
200
+ on cancelImportIfOpen(finalCut)
201
+ try
202
+ if exists window "Import XML" of finalCut then
203
+ set importWindow to window "Import XML" of finalCut
204
+ repeat with candidate in (buttons of importWindow)
205
+ try
206
+ if (name of candidate as text) is "Cancel" then
207
+ perform action "AXPress" of candidate
208
+ exit repeat
209
+ end if
210
+ end try
211
+ end repeat
212
+ end if
213
+ end try
214
+ end cancelImportIfOpen
215
+
216
+ end using terms from
217
+
69
218
  tell application "System Events"
70
219
  tell process "Final Cut Pro"
71
- if not frontmost then error number -1719
72
- click menu item "XML..." of menu item "Import" of menu "File" of menu bar 1
73
- delay 0.4
74
- keystroke "g" using {command down}
75
- delay 0.2
76
- set value of first text field of front window to ${appleScriptString(path)}
77
- key code 36
78
- delay 0.5
79
- key code 36
220
+ set finalCut to it
221
+ set importWindow to missing value
222
+ try
223
+ if not frontmost then error number -1719
224
+ set fileMenu to menu "File" of menu bar 1
225
+ set importMenuItem to my waitForMenuItem(fileMenu, {"Import"}, 10, "FINAL_CUT_PUBLISH_IMPORT_MENU_TIMEOUT: File > Import was not exposed")
226
+ perform action "AXPress" of importMenuItem
227
+ set importMenu to my waitForSubmenu(importMenuItem, "Import", 10, "FINAL_CUT_PUBLISH_IMPORT_MENU_TIMEOUT: Import submenu was not exposed")
228
+ set xmlMenuItem to my waitForMenuItem(importMenu, {"XML…", "XML..."}, 10, "FINAL_CUT_PUBLISH_IMPORT_MENU_TIMEOUT: Import XML command was not exposed")
229
+ perform action "AXPress" of xmlMenuItem
230
+ set importWindow to my waitForWindow(finalCut, "Import XML", 10, "FINAL_CUT_PUBLISH_IMPORT_SHEET_TIMEOUT: Import XML sheet did not appear")
231
+ keystroke "g" using {command down, shift down}
232
+ set pathSheet to my waitForImportSheet(importWindow, 10)
233
+ set pathField to my locateImportPathField(pathSheet)
234
+ set value of pathField to ${appleScriptString(path)}
235
+ key code 36
236
+ my waitForImportSheetDismissal(importWindow, 10)
237
+ key code 36
238
+ my waitForImportWindowDismissal(finalCut, 60)
239
+ on error errorMessage number errorNumber
240
+ my cancelImportIfOpen(finalCut)
241
+ error errorMessage number errorNumber
242
+ end try
80
243
  end tell
81
244
  end tell`;
82
245
  }
83
- function projectNameFromXml(source) {
84
- const match = source.match(/<project\b[^>]*\bname="([^"]+)"/);
85
- if (!match?.[1])
246
+ function projectIdentityFromXml(source) {
247
+ const projectMatch = source.match(/<project\b[^>]*\bname="([^"]+)"/);
248
+ if (!projectMatch?.[1])
86
249
  throw new Error("FINAL_CUT_PUBLISH_VALIDATION_FAILED: FCPXML project has no name");
87
- return decodeXml(match[1]);
250
+ const projectName = decodeXml(projectMatch[1]);
251
+ const sequenceMatch = source.match(/<sequence\b[^>]*\bname="([^"]+)"/);
252
+ return { projectName, sequenceName: sequenceMatch?.[1] ? decodeXml(sequenceMatch[1]) : projectName };
88
253
  }
89
254
  function decodeXml(value) {
90
255
  return value
@@ -95,8 +260,55 @@ function decodeXml(value) {
95
260
  .replaceAll("&amp;", "&");
96
261
  }
97
262
  function appleScriptString(value) {
98
- return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replace(/[\\r\\n]/g, " ")}"`;
263
+ return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replace(/[\r\n]/g, " ")}"`;
264
+ }
265
+ async function readLiveState(liveState, phase) {
266
+ try {
267
+ return await liveState();
268
+ }
269
+ catch (error) {
270
+ const detail = error instanceof Error ? error.message : String(error);
271
+ throw new Error(`FINAL_CUT_PUBLISH_STATE_UNAVAILABLE: ${phase}: ${detail}`);
272
+ }
273
+ }
274
+ async function waitForImportedProject(liveState, identity, before, timeoutMs, pollIntervalMs) {
275
+ const deadline = Date.now() + timeoutMs;
276
+ let latest;
277
+ let lastError;
278
+ do {
279
+ try {
280
+ latest = await readLiveState(liveState, "after import");
281
+ lastError = undefined;
282
+ if (isImportedProject(latest, identity, before))
283
+ return latest;
284
+ }
285
+ catch (error) {
286
+ lastError = error;
287
+ }
288
+ if (Date.now() >= deadline)
289
+ break;
290
+ await delay(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
291
+ } while (true);
292
+ if (lastError)
293
+ throw lastError;
294
+ const observedProject = latest?.project?.name ?? "none";
295
+ const observedSequence = latest?.sequence?.name ?? "none";
296
+ throw new Error(`FINAL_CUT_PUBLISH_VERIFICATION_FAILED: expected new project ${identity.projectName} / sequence ${identity.sequenceName}, observed ${observedProject} / ${observedSequence}`);
297
+ }
298
+ function isImportedProject(live, identity, before) {
299
+ if (!live.project || !live.sequence)
300
+ return false;
301
+ if (live.project.name !== identity.projectName || live.sequence.name !== identity.sequenceName)
302
+ return false;
303
+ if (before.project && live.project.id === before.project.id)
304
+ return false;
305
+ if (before.sequence && live.sequence.id === before.sequence.id)
306
+ return false;
307
+ return true;
99
308
  }
100
309
  function delay(milliseconds) {
101
310
  return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
102
311
  }
312
+ function hash(content) {
313
+ return createHash("sha256").update(content).digest("hex");
314
+ }
@@ -1,4 +1,4 @@
1
- import { withCanonicalTimelineMode } from "../../../../packages/runtime/src/index.js";
1
+ import { withCanonicalTimelineMode, withCapabilityFamilies } from "../../../../packages/runtime/src/index.js";
2
2
  /** Composes the independent Final Cut live, snapshot, and mutation surfaces. */
3
3
  export class FinalCutSessionAdapter {
4
4
  options;
@@ -21,6 +21,14 @@ export class FinalCutSessionAdapter {
21
21
  return this.options.live.getIdentity();
22
22
  return { name: "Final Cut Pro", version: "unknown", backend: "final-cut-session" };
23
23
  }
24
+ async getManagedArtifact() {
25
+ if (this.options.snapshot?.getManagedArtifact)
26
+ return this.options.snapshot.getManagedArtifact();
27
+ throw new Error("CAPABILITY_UNAVAILABLE: managed FCPXML artifact");
28
+ }
29
+ async getManagedArtifactDigest() {
30
+ return this.options.snapshot?.getManagedArtifactDigest?.();
31
+ }
24
32
  async getCapabilities() {
25
33
  const snapshot = await this.options.snapshot?.getCapabilities();
26
34
  const mutation = await this.options.mutation?.getCapabilities();
@@ -35,16 +43,42 @@ export class FinalCutSessionAdapter {
35
43
  && live?.editor.canonicalTimelineMode === "canonical-write"
36
44
  && this.options.live?.apply
37
45
  && this.options.live.restore);
38
- return withCanonicalTimelineMode({
46
+ const operationRuntimeCapabilities = hasExplicitDocumentPair
47
+ ? mutation
48
+ : liveMutation
49
+ ? live
50
+ : snapshot;
51
+ const operationCapabilities = operationRuntimeCapabilities?.editor;
52
+ const operationAdapter = hasExplicitDocumentPair
53
+ ? this.options.mutation
54
+ : liveMutation
55
+ ? this.options.live
56
+ : this.options.snapshot;
57
+ const readCapabilities = snapshot ?? (liveSnapshot ? live : undefined);
58
+ const readAdapter = this.options.snapshot ?? (liveSnapshot ? this.options.live : undefined);
59
+ const hasTransactionMethods = Boolean(operationAdapter
60
+ && typeof operationAdapter.previewTransaction === "function"
61
+ && typeof operationAdapter.applyTransaction === "function");
62
+ const canReadAfterWrite = Boolean(readAdapter?.readProject
63
+ && readCapabilities?.editor.readAfterWrite
64
+ && operationCapabilities?.readAfterWrite
65
+ && operationAdapter?.restore
66
+ && operationCapabilities?.rollback);
67
+ const compositeTransactions = Boolean(operationCapabilities?.compositeTransactions
68
+ && hasTransactionMethods
69
+ && canReadAfterWrite);
70
+ const operationFamilies = operationRuntimeCapabilities?.families;
71
+ const readFamilies = readCapabilities?.families;
72
+ return withCapabilityFamilies({
39
73
  editor: {
74
+ ...operationCapabilities,
40
75
  projectRead: Boolean(snapshot?.editor.projectRead || (liveSnapshot && live?.editor.projectRead)),
41
- timelineSnapshotRead: Boolean(snapshot?.editor.timelineSnapshotRead || liveSnapshot),
42
- timelineWrite: Boolean((hasExplicitDocumentPair && mutation?.editor.timelineWrite) || liveMutation),
43
- timelineArtifactWrite: Boolean(hasExplicitDocumentPair && mutation?.editor.timelineArtifactWrite),
44
- readAfterWrite: Boolean((hasExplicitDocumentPair && snapshot?.editor.readAfterWrite && mutation?.editor.readAfterWrite)
45
- || (liveMutation && live?.editor.readAfterWrite)),
76
+ timelineSnapshotRead: Boolean(readCapabilities?.editor.timelineSnapshotRead),
77
+ timelineWrite: Boolean(operationCapabilities?.timelineWrite),
78
+ timelineArtifactWrite: Boolean(operationCapabilities?.timelineArtifactWrite),
79
+ readAfterWrite: canReadAfterWrite,
46
80
  incrementalChanges: Boolean(live?.editor.incrementalChanges),
47
- rollback: Boolean((hasExplicitDocumentPair && mutation?.editor.rollback) || liveMutation),
81
+ rollback: Boolean(operationCapabilities?.rollback && operationAdapter?.restore),
48
82
  assetDiscovery: Boolean(snapshot?.editor.assetDiscovery || this.options.assets?.listAssets),
49
83
  liveStateRead: Boolean(live?.editor.liveStateRead),
50
84
  playheadWrite: Boolean(live?.editor.playheadWrite),
@@ -52,6 +86,7 @@ export class FinalCutSessionAdapter {
52
86
  playbackControl: Boolean(live?.editor.playbackControl),
53
87
  projectCatalogRead: Boolean(snapshot?.editor.projectCatalogRead || (!this.options.snapshot && live?.editor.projectCatalogRead)),
54
88
  projectSelection: Boolean(snapshot?.editor.projectSelection || (!this.options.snapshot && live?.editor.projectSelection)),
89
+ compositeTransactions,
55
90
  },
56
91
  analyzers: {
57
92
  speechTranscribe: Boolean(snapshot?.analyzers.speechTranscribe || mutation?.analyzers.speechTranscribe || live?.analyzers.speechTranscribe),
@@ -59,8 +94,36 @@ export class FinalCutSessionAdapter {
59
94
  audioLoudness: Boolean(snapshot?.analyzers.audioLoudness || mutation?.analyzers.audioLoudness || live?.analyzers.audioLoudness),
60
95
  visualTrack: Boolean(snapshot?.analyzers.visualTrack || mutation?.analyzers.visualTrack || live?.analyzers.visualTrack),
61
96
  },
97
+ }, {
98
+ backend: "final-cut-session",
99
+ canonicalDocument: {
100
+ read: readFamilies?.canonicalDocument.read ?? Boolean(readCapabilities?.editor.timelineSnapshotRead),
101
+ write: operationFamilies?.canonicalDocument.write ?? Boolean(operationCapabilities?.timelineWrite),
102
+ artifactWrite: operationFamilies?.canonicalDocument.artifactWrite ?? Boolean(operationCapabilities?.timelineArtifactWrite),
103
+ },
104
+ editing: {
105
+ compositeTransactions: compositeTransactions,
106
+ titlePlacement: operationFamilies?.editing.titlePlacement ?? Boolean(operationCapabilities?.titlePlacement),
107
+ pictureInPicture: operationFamilies?.editing.pictureInPicture ?? false,
108
+ masking: operationFamilies?.editing.masking ?? false,
109
+ },
110
+ editingBackend: operationFamilies?.editing.compositeTransactions.backend,
62
111
  });
63
112
  }
113
+ async previewTransaction(operations, expectedRevision) {
114
+ const provider = await this.routedTransactionProvider();
115
+ if (!provider?.previewTransaction) {
116
+ throw new Error("CAPABILITY_UNAVAILABLE: editor composite transaction preview");
117
+ }
118
+ return provider.previewTransaction(operations, expectedRevision);
119
+ }
120
+ async applyTransaction(operations, expectedRevision) {
121
+ const provider = await this.routedTransactionProvider();
122
+ if (!provider?.applyTransaction) {
123
+ throw new Error("CAPABILITY_UNAVAILABLE: editor composite transaction execution");
124
+ }
125
+ await provider.applyTransaction(operations, expectedRevision);
126
+ }
64
127
  async read() {
65
128
  return this.readProject();
66
129
  }
@@ -68,7 +131,10 @@ export class FinalCutSessionAdapter {
68
131
  if (this.options.snapshot)
69
132
  return this.options.snapshot.readProject();
70
133
  const liveCapabilities = await optionalCapabilities(this.options.live);
71
- if (liveCapabilities?.editor.timelineSnapshotRead && this.options.live?.readProject) {
134
+ if (liveCapabilities?.editor.canonicalTimelineMode !== "metadata-only"
135
+ && !this.options.mutation
136
+ && liveCapabilities?.editor.timelineSnapshotRead
137
+ && this.options.live?.readProject) {
72
138
  return this.options.live.readProject();
73
139
  }
74
140
  throw new Error("CAPABILITY_UNAVAILABLE: Final Cut session has no snapshot provider");
@@ -142,6 +208,17 @@ export class FinalCutSessionAdapter {
142
208
  throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut editor state");
143
209
  return this.options.live.liveChangesSince(revision, waitMs);
144
210
  }
211
+ async routedTransactionProvider() {
212
+ if (this.options.snapshot && this.options.mutation)
213
+ return this.options.mutation;
214
+ const liveCapabilities = await optionalCapabilities(this.options.live);
215
+ const liveMutation = Boolean(liveCapabilities?.editor.canonicalTimelineMode === "canonical-write"
216
+ && this.options.live?.apply
217
+ && this.options.live.restore);
218
+ if (liveMutation && this.options.live)
219
+ return this.options.live;
220
+ return this.options.snapshot;
221
+ }
145
222
  }
146
223
  async function optionalCapabilities(live) {
147
224
  if (!live)
@@ -1,7 +1,7 @@
1
1
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
2
  import { InMemoryEditorAdapter } from "../../../packages/testkit/src/index.js";
3
3
  import { createCommandAnalyzers, createFinalCutLiveAdapter, FcpxmlDocumentAdapter, FinalCutAssetRegistry, FinalCutConnectionManager, FinalCutNativeAutomationAdapter, DisposableNativeEditWorkflow, FinalCutProjectPublisher, FinalCutVideoExporter, FinalCutSessionAdapter, createNativeOperationLease, isFinalCutVideoProbeAvailable, } from "../../../adapters/final-cut/typescript/src/index.js";
4
- import { FixtureAudioAnalyzer, FixtureSpeechAnalyzer, FixtureVisualAnalyzer } from "../../../packages/testkit/src/index.js";
4
+ import { FixtureAudioAnalyzer, FixtureMetadataAnalyzer, FixtureSpeechAnalyzer, FixtureVisualAnalyzer } from "../../../packages/testkit/src/index.js";
5
5
  import { AgentVideoRuntime } from "../../../packages/runtime/src/index.js";
6
6
  import { createMcpServer } from "./server.js";
7
7
  const fixture = new InMemoryEditorAdapter({
@@ -23,6 +23,12 @@ const fixture = new InMemoryEditorAdapter({
23
23
  motion: { score: 0.12, label: "low" },
24
24
  keyframes: [{ time: 1, source: "interview.wav", labels: ["person", "interview"] }],
25
25
  },
26
+ metadata: {
27
+ environments: [{ value: "studio", confidence: 0.91 }],
28
+ timeOfDay: [{ value: "day", confidence: 0.88 }],
29
+ moods: [{ value: "focused", confidence: 0.86 }],
30
+ usableRanges: [{ start: 0, end: 10 }],
31
+ },
26
32
  }],
27
33
  assets: [{
28
34
  id: "transition-cross-dissolve",
@@ -75,12 +81,14 @@ const analyzers = liveMode
75
81
  speechCommand: process.env.FRAMEKIT_SPEECH_ANALYZER,
76
82
  audioCommand: process.env.FRAMEKIT_AUDIO_ANALYZER,
77
83
  visualCommand: process.env.FRAMEKIT_VISUAL_ANALYZER,
84
+ metadataCommand: process.env.FRAMEKIT_METADATA_ANALYZER,
78
85
  timeoutMs: parseTimeout(process.env.FRAMEKIT_ANALYZER_TIMEOUT_MS),
79
86
  })
80
87
  : {
81
88
  speechAnalyzer: new FixtureSpeechAnalyzer(),
82
89
  audioAnalyzer: new FixtureAudioAnalyzer(),
83
90
  visualAnalyzer: new FixtureVisualAnalyzer(),
91
+ metadataAnalyzer: new FixtureMetadataAnalyzer(),
84
92
  };
85
93
  const runtime = new AgentVideoRuntime(editor, analyzers);
86
94
  const nativeEditor = liveMode
@@ -116,6 +124,7 @@ const videoExporter = liveMode && !headlessFinalCut && process.env.FRAMEKIT_FINA
116
124
  })
117
125
  : undefined;
118
126
  const server = createMcpServer(runtime, {
127
+ processMode: liveMode && !headlessFinalCut ? "headed" : "headless",
119
128
  connectionStatus: () => connection?.getStatus(),
120
129
  nativeEditor,
121
130
  disposableNative,