@morshoto/framekit 0.1.0
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 +67 -0
- package/bin/framekit.mjs +26 -0
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +116 -0
- package/dist-package/adapters/final-cut/typescript/src/assets.js +112 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +379 -0
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +282 -0
- package/dist-package/adapters/final-cut/typescript/src/export.js +382 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +503 -0
- package/dist-package/adapters/final-cut/typescript/src/index.js +11 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +415 -0
- package/dist-package/adapters/final-cut/typescript/src/native-operation.js +18 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +3134 -0
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +102 -0
- package/dist-package/adapters/final-cut/typescript/src/session.js +171 -0
- package/dist-package/apps/cli/src/main.js +130 -0
- package/dist-package/apps/mcp-server/src/main.js +146 -0
- package/dist-package/apps/mcp-server/src/server.js +617 -0
- package/dist-package/packages/runtime/src/capabilities.js +24 -0
- package/dist-package/packages/runtime/src/context/context-engine.js +142 -0
- package/dist-package/packages/runtime/src/diff/diff.js +145 -0
- package/dist-package/packages/runtime/src/domain/types.js +1 -0
- package/dist-package/packages/runtime/src/editing/intent.js +83 -0
- package/dist-package/packages/runtime/src/index.js +8 -0
- package/dist-package/packages/runtime/src/runtime.js +890 -0
- package/dist-package/packages/runtime/src/snapshot-digest.js +24 -0
- package/dist-package/packages/runtime/src/speech/filler-removal.js +87 -0
- package/dist-package/packages/runtime/src/verification/verification.js +113 -0
- package/dist-package/packages/testkit/src/fixture-analyzers.js +39 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +520 -0
- package/dist-package/packages/testkit/src/index.js +2 -0
- package/package.json +64 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { copyFile, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
const execFile = promisify(execFileCallback);
|
|
7
|
+
/** Imports a validated FCPXML artifact as a new Final Cut project. */
|
|
8
|
+
export class FinalCutProjectPublisher {
|
|
9
|
+
enabled;
|
|
10
|
+
sourcePath;
|
|
11
|
+
executor;
|
|
12
|
+
liveState;
|
|
13
|
+
waitMs;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.enabled = options.enabled ?? false;
|
|
16
|
+
this.sourcePath = options.sourcePath;
|
|
17
|
+
this.executor = options.executor ?? runAppleScript;
|
|
18
|
+
this.liveState = options.liveState;
|
|
19
|
+
this.waitMs = options.waitMs ?? 1_500;
|
|
20
|
+
}
|
|
21
|
+
async publishNewProject(sourceTransactionId) {
|
|
22
|
+
if (!this.enabled)
|
|
23
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project publishing is disabled; set FRAMEKIT_FINAL_CUT_NATIVE_WRITES=1");
|
|
24
|
+
const source = await readFile(this.sourcePath, "utf8");
|
|
25
|
+
if (!source.includes("<fcpxml") || !source.includes("<project")) {
|
|
26
|
+
throw new Error("FINAL_CUT_PUBLISH_VALIDATION_FAILED: source is not a valid FCPXML project artifact");
|
|
27
|
+
}
|
|
28
|
+
const projectName = projectNameFromXml(source);
|
|
29
|
+
const directory = await mkdtemp(join(tmpdir(), "framekit-finalcut-publish-"));
|
|
30
|
+
const importedPath = join(directory, basename(this.sourcePath));
|
|
31
|
+
await copyFile(this.sourcePath, importedPath);
|
|
32
|
+
try {
|
|
33
|
+
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
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
sourceTransactionId,
|
|
41
|
+
sourcePath: this.sourcePath,
|
|
42
|
+
importedPath,
|
|
43
|
+
projectName,
|
|
44
|
+
verified: true,
|
|
45
|
+
...(live?.project?.name ? { liveProject: live.project.name } : {}),
|
|
46
|
+
...(live?.sequence?.name ? { liveSequence: live.sequence.name } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await rm(directory, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function runAppleScript(script) {
|
|
55
|
+
try {
|
|
56
|
+
const result = await execFile("osascript", ["-e", script], { maxBuffer: 1_000_000 });
|
|
57
|
+
return result.stdout.trim();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
61
|
+
if (detail.includes("not authorized") || detail.includes("-1743") || detail.includes("-25211")) {
|
|
62
|
+
throw new Error(`FINAL_CUT_NATIVE_PERMISSION_REQUIRED: ${detail}`);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`FINAL_CUT_PUBLISH_AUTOMATION_FAILED: ${detail}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function importXmlScript(path) {
|
|
68
|
+
return `
|
|
69
|
+
tell application "System Events"
|
|
70
|
+
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
|
|
80
|
+
end tell
|
|
81
|
+
end tell`;
|
|
82
|
+
}
|
|
83
|
+
function projectNameFromXml(source) {
|
|
84
|
+
const match = source.match(/<project\b[^>]*\bname="([^"]+)"/);
|
|
85
|
+
if (!match?.[1])
|
|
86
|
+
throw new Error("FINAL_CUT_PUBLISH_VALIDATION_FAILED: FCPXML project has no name");
|
|
87
|
+
return decodeXml(match[1]);
|
|
88
|
+
}
|
|
89
|
+
function decodeXml(value) {
|
|
90
|
+
return value
|
|
91
|
+
.replaceAll(""", '"')
|
|
92
|
+
.replaceAll("'", "'")
|
|
93
|
+
.replaceAll("<", "<")
|
|
94
|
+
.replaceAll(">", ">")
|
|
95
|
+
.replaceAll("&", "&");
|
|
96
|
+
}
|
|
97
|
+
function appleScriptString(value) {
|
|
98
|
+
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replace(/[\\r\\n]/g, " ")}"`;
|
|
99
|
+
}
|
|
100
|
+
function delay(milliseconds) {
|
|
101
|
+
return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
|
|
102
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { withCanonicalTimelineMode } from "../../../../packages/runtime/src/index.js";
|
|
2
|
+
/** Composes the independent Final Cut live, snapshot, and mutation surfaces. */
|
|
3
|
+
export class FinalCutSessionAdapter {
|
|
4
|
+
options;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
async getIdentity() {
|
|
9
|
+
if (this.options.snapshot && this.options.live) {
|
|
10
|
+
try {
|
|
11
|
+
const live = await this.options.live.getIdentity();
|
|
12
|
+
return { name: "Final Cut Pro", version: live.version, backend: "final-cut-session" };
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { name: "Final Cut Pro", version: "FCPXML + live", backend: "final-cut-session" };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (this.options.snapshot)
|
|
19
|
+
return this.options.snapshot.getIdentity();
|
|
20
|
+
if (this.options.live)
|
|
21
|
+
return this.options.live.getIdentity();
|
|
22
|
+
return { name: "Final Cut Pro", version: "unknown", backend: "final-cut-session" };
|
|
23
|
+
}
|
|
24
|
+
async getCapabilities() {
|
|
25
|
+
const snapshot = await this.options.snapshot?.getCapabilities();
|
|
26
|
+
const mutation = await this.options.mutation?.getCapabilities();
|
|
27
|
+
const live = await optionalCapabilities(this.options.live);
|
|
28
|
+
const hasExplicitDocumentPair = Boolean(this.options.snapshot && this.options.mutation);
|
|
29
|
+
const useLiveCanonical = !this.options.snapshot && !this.options.mutation;
|
|
30
|
+
const liveSnapshot = Boolean(useLiveCanonical
|
|
31
|
+
&& live?.editor.timelineSnapshotRead
|
|
32
|
+
&& live.editor.canonicalTimelineMode !== "metadata-only"
|
|
33
|
+
&& this.options.live?.readProject);
|
|
34
|
+
const liveMutation = Boolean(liveSnapshot
|
|
35
|
+
&& live?.editor.canonicalTimelineMode === "canonical-write"
|
|
36
|
+
&& this.options.live?.apply
|
|
37
|
+
&& this.options.live.restore);
|
|
38
|
+
return withCanonicalTimelineMode({
|
|
39
|
+
editor: {
|
|
40
|
+
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)),
|
|
46
|
+
incrementalChanges: Boolean(live?.editor.incrementalChanges),
|
|
47
|
+
rollback: Boolean((hasExplicitDocumentPair && mutation?.editor.rollback) || liveMutation),
|
|
48
|
+
assetDiscovery: Boolean(snapshot?.editor.assetDiscovery || this.options.assets?.listAssets),
|
|
49
|
+
liveStateRead: Boolean(live?.editor.liveStateRead),
|
|
50
|
+
playheadWrite: Boolean(live?.editor.playheadWrite),
|
|
51
|
+
frameCapture: false,
|
|
52
|
+
playbackControl: Boolean(live?.editor.playbackControl),
|
|
53
|
+
projectCatalogRead: Boolean(snapshot?.editor.projectCatalogRead || (!this.options.snapshot && live?.editor.projectCatalogRead)),
|
|
54
|
+
projectSelection: Boolean(snapshot?.editor.projectSelection || (!this.options.snapshot && live?.editor.projectSelection)),
|
|
55
|
+
},
|
|
56
|
+
analyzers: {
|
|
57
|
+
speechTranscribe: Boolean(snapshot?.analyzers.speechTranscribe || mutation?.analyzers.speechTranscribe || live?.analyzers.speechTranscribe),
|
|
58
|
+
speechVad: Boolean(snapshot?.analyzers.speechVad || mutation?.analyzers.speechVad || live?.analyzers.speechVad),
|
|
59
|
+
audioLoudness: Boolean(snapshot?.analyzers.audioLoudness || mutation?.analyzers.audioLoudness || live?.analyzers.audioLoudness),
|
|
60
|
+
visualTrack: Boolean(snapshot?.analyzers.visualTrack || mutation?.analyzers.visualTrack || live?.analyzers.visualTrack),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async read() {
|
|
65
|
+
return this.readProject();
|
|
66
|
+
}
|
|
67
|
+
async readProject() {
|
|
68
|
+
if (this.options.snapshot)
|
|
69
|
+
return this.options.snapshot.readProject();
|
|
70
|
+
const liveCapabilities = await optionalCapabilities(this.options.live);
|
|
71
|
+
if (liveCapabilities?.editor.timelineSnapshotRead && this.options.live?.readProject) {
|
|
72
|
+
return this.options.live.readProject();
|
|
73
|
+
}
|
|
74
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut session has no snapshot provider");
|
|
75
|
+
}
|
|
76
|
+
async apply(operation, expectedRevision) {
|
|
77
|
+
if (this.options.snapshot && this.options.mutation) {
|
|
78
|
+
return this.options.mutation.apply(operation, expectedRevision);
|
|
79
|
+
}
|
|
80
|
+
const liveCapabilities = await optionalCapabilities(this.options.live);
|
|
81
|
+
if (!this.options.snapshot
|
|
82
|
+
&& !this.options.mutation
|
|
83
|
+
&& liveCapabilities?.editor.canonicalTimelineMode === "canonical-write"
|
|
84
|
+
&& this.options.live?.apply
|
|
85
|
+
&& this.options.live.restore) {
|
|
86
|
+
return this.options.live.apply(operation, expectedRevision);
|
|
87
|
+
}
|
|
88
|
+
if (this.options.snapshot) {
|
|
89
|
+
return this.options.snapshot.apply(operation, expectedRevision);
|
|
90
|
+
}
|
|
91
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut session has no mutation provider");
|
|
92
|
+
}
|
|
93
|
+
async restore(snapshot, expectedRevision) {
|
|
94
|
+
if (this.options.snapshot && this.options.mutation) {
|
|
95
|
+
await this.options.mutation.restore(snapshot, expectedRevision);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const liveCapabilities = await optionalCapabilities(this.options.live);
|
|
99
|
+
if (!this.options.snapshot
|
|
100
|
+
&& !this.options.mutation
|
|
101
|
+
&& liveCapabilities?.editor.canonicalTimelineMode === "canonical-write"
|
|
102
|
+
&& this.options.live?.apply
|
|
103
|
+
&& this.options.live.restore) {
|
|
104
|
+
await this.options.live.restore(snapshot, expectedRevision);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (this.options.snapshot) {
|
|
108
|
+
await this.options.snapshot.restore(snapshot, expectedRevision);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut session has no mutation provider");
|
|
112
|
+
}
|
|
113
|
+
async listAssets(query) {
|
|
114
|
+
const provider = this.options.assets ?? this.options.snapshot;
|
|
115
|
+
if (!provider?.listAssets)
|
|
116
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut assets");
|
|
117
|
+
return provider.listAssets(query);
|
|
118
|
+
}
|
|
119
|
+
async listProjects() {
|
|
120
|
+
if (this.options.snapshot?.listProjects)
|
|
121
|
+
return this.options.snapshot.listProjects();
|
|
122
|
+
if (!this.options.snapshot && this.options.live?.listProjects && (await optionalProjectCatalogCapability(this.options.live))) {
|
|
123
|
+
return this.options.live.listProjects();
|
|
124
|
+
}
|
|
125
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project catalog");
|
|
126
|
+
}
|
|
127
|
+
async selectProject(selection) {
|
|
128
|
+
if (this.options.snapshot?.selectProject)
|
|
129
|
+
return this.options.snapshot.selectProject(selection);
|
|
130
|
+
if (!this.options.snapshot && this.options.live?.selectProject && (await optionalProjectSelectionCapability(this.options.live))) {
|
|
131
|
+
return this.options.live.selectProject(selection);
|
|
132
|
+
}
|
|
133
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project selection");
|
|
134
|
+
}
|
|
135
|
+
async readLiveState() {
|
|
136
|
+
if (!this.options.live)
|
|
137
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut editor state");
|
|
138
|
+
return this.options.live.readLiveState();
|
|
139
|
+
}
|
|
140
|
+
async liveChangesSince(revision, waitMs = 0) {
|
|
141
|
+
if (!this.options.live)
|
|
142
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut editor state");
|
|
143
|
+
return this.options.live.liveChangesSince(revision, waitMs);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function optionalCapabilities(live) {
|
|
147
|
+
if (!live)
|
|
148
|
+
return undefined;
|
|
149
|
+
try {
|
|
150
|
+
return withCanonicalTimelineMode(await live.getCapabilities());
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function optionalProjectCatalogCapability(live) {
|
|
157
|
+
try {
|
|
158
|
+
return Boolean((await live?.getCapabilities())?.editor.projectCatalogRead);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function optionalProjectSelectionCapability(live) {
|
|
165
|
+
try {
|
|
166
|
+
return Boolean((await live?.getCapabilities())?.editor.projectSelection);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { FinalCutConnectionManager } from "../../../adapters/final-cut/typescript/src/index.js";
|
|
7
|
+
const execFile = promisify(execFileCallback);
|
|
8
|
+
async function main() {
|
|
9
|
+
const argv = process.argv.slice(2);
|
|
10
|
+
if (argv[0] === "--")
|
|
11
|
+
argv.shift();
|
|
12
|
+
const [command = "help", ...args] = argv;
|
|
13
|
+
if (command === "connect") {
|
|
14
|
+
await connectFinalCut(args);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (command === "doctor") {
|
|
18
|
+
await doctorFinalCut(args);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (command === "mcp") {
|
|
22
|
+
await runMcp(args);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
printHelp();
|
|
26
|
+
if (command !== "help")
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
}
|
|
29
|
+
async function connectFinalCut(args) {
|
|
30
|
+
if (args[0] !== "finalcut") {
|
|
31
|
+
throw new Error("Usage: framekit connect finalcut [--development] [--json]");
|
|
32
|
+
}
|
|
33
|
+
const development = args.includes("--development");
|
|
34
|
+
const json = args.includes("--json");
|
|
35
|
+
let extensionSourcePath = process.env.FRAMEKIT_EXTENSION_APP_PATH;
|
|
36
|
+
if (development) {
|
|
37
|
+
await buildDevelopmentExtension();
|
|
38
|
+
extensionSourcePath = join("/tmp", "framekit-finalcut-derived/Build/Products/Debug/FramekitFinalCutWorkflow.app");
|
|
39
|
+
}
|
|
40
|
+
const manager = new FinalCutConnectionManager({
|
|
41
|
+
extensionSourcePath,
|
|
42
|
+
restartAfterInstall: true,
|
|
43
|
+
});
|
|
44
|
+
const status = await manager.ensureConnected();
|
|
45
|
+
printStatus(status, json);
|
|
46
|
+
if (status.state !== "ready")
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
}
|
|
49
|
+
async function doctorFinalCut(args) {
|
|
50
|
+
if (args[0] !== "finalcut")
|
|
51
|
+
throw new Error("Usage: framekit doctor finalcut [--json]");
|
|
52
|
+
const status = await new FinalCutConnectionManager().ensureConnected();
|
|
53
|
+
printStatus(status, args.includes("--json"));
|
|
54
|
+
if (status.state !== "ready")
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
}
|
|
57
|
+
async function runMcp(args) {
|
|
58
|
+
const editorIndex = args.indexOf("--editor");
|
|
59
|
+
const editor = editorIndex >= 0 ? args[editorIndex + 1] : "final-cut-live";
|
|
60
|
+
const headless = args.includes("--headless");
|
|
61
|
+
if (editor !== "final-cut-live" && editor !== "fixture") {
|
|
62
|
+
throw new Error("Usage: framekit mcp [--editor final-cut-live|fixture] [--headless]");
|
|
63
|
+
}
|
|
64
|
+
if (headless && editor !== "final-cut-live") {
|
|
65
|
+
throw new Error("Usage: --headless is only supported with --editor final-cut-live");
|
|
66
|
+
}
|
|
67
|
+
const root = repoRoot();
|
|
68
|
+
const compiled = fileURLToPath(import.meta.url).endsWith(".js");
|
|
69
|
+
const entrypoint = join(root, `apps/mcp-server/src/main.${compiled ? "js" : "ts"}`);
|
|
70
|
+
const child = spawn(process.execPath, [...(compiled ? [] : ["--import", "tsx"]), entrypoint], {
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
env: {
|
|
73
|
+
...process.env,
|
|
74
|
+
FRAMEKIT_EDITOR: editor,
|
|
75
|
+
...(headless
|
|
76
|
+
? {
|
|
77
|
+
FRAMEKIT_FINAL_CUT_HEADLESS: "1",
|
|
78
|
+
FRAMEKIT_FINAL_CUT_NATIVE_WRITES: "0",
|
|
79
|
+
FRAMEKIT_AUTO_CONNECT: "1",
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
await new Promise((resolvePromise, reject) => {
|
|
85
|
+
child.once("error", reject);
|
|
86
|
+
child.once("exit", (code, signal) => {
|
|
87
|
+
process.exitCode = code ?? (signal ? 1 : 0);
|
|
88
|
+
resolvePromise();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function buildDevelopmentExtension() {
|
|
93
|
+
const buildScript = join(repoRoot(), "adapters/final-cut/swift-bridge/FinalCutWorkflowExtension/build.sh");
|
|
94
|
+
await access(buildScript);
|
|
95
|
+
await execFile("bash", [buildScript], { cwd: repoRoot(), maxBuffer: 10 * 1024 * 1024 });
|
|
96
|
+
}
|
|
97
|
+
function repoRoot() {
|
|
98
|
+
return join(dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
99
|
+
}
|
|
100
|
+
function printStatus(status, json) {
|
|
101
|
+
if (json) {
|
|
102
|
+
process.stdout.write(`${JSON.stringify(status)}\n`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
process.stdout.write(`Framekit Final Cut: ${status.state}\n`);
|
|
106
|
+
process.stdout.write(`Final Cut detected: ${status.editorDetected ? "yes" : "no"}\n`);
|
|
107
|
+
process.stdout.write(`Extension: ${status.extensionInstalled ? status.extensionPath : "not installed"}\n`);
|
|
108
|
+
process.stdout.write(`Socket: ${status.socketPath}\n`);
|
|
109
|
+
if (status.identity)
|
|
110
|
+
process.stdout.write(`Editor: ${status.identity.name} (${status.identity.backend})\n`);
|
|
111
|
+
if (status.lastError)
|
|
112
|
+
process.stdout.write(`Reason: ${status.lastError.code}: ${status.lastError.message}\n`);
|
|
113
|
+
}
|
|
114
|
+
function printHelp() {
|
|
115
|
+
process.stdout.write([
|
|
116
|
+
"Framekit local editor connection",
|
|
117
|
+
"",
|
|
118
|
+
" framekit connect finalcut [--development] [--json]",
|
|
119
|
+
" framekit doctor finalcut [--json]",
|
|
120
|
+
" framekit mcp --editor final-cut-live [--headless]",
|
|
121
|
+
"",
|
|
122
|
+
"Codex registration:",
|
|
123
|
+
" codex mcp add framekit -- framekit mcp --editor final-cut-live --headless",
|
|
124
|
+
"",
|
|
125
|
+
].join("\n"));
|
|
126
|
+
}
|
|
127
|
+
void main().catch((error) => {
|
|
128
|
+
process.stderr.write(`${String(error)}\n`);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { InMemoryEditorAdapter } from "../../../packages/testkit/src/index.js";
|
|
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";
|
|
5
|
+
import { AgentVideoRuntime } from "../../../packages/runtime/src/index.js";
|
|
6
|
+
import { createMcpServer } from "./server.js";
|
|
7
|
+
const fixture = new InMemoryEditorAdapter({
|
|
8
|
+
projectId: "project-1",
|
|
9
|
+
projectName: "Phase 2 Fixture",
|
|
10
|
+
timelineId: "timeline-1",
|
|
11
|
+
timelineName: "Main Edit",
|
|
12
|
+
clips: [
|
|
13
|
+
{ id: "clip-1", mediaId: "media-1", name: "Interview", start: 0, duration: 10, track: 1 },
|
|
14
|
+
],
|
|
15
|
+
media: [{
|
|
16
|
+
mediaId: "media-1",
|
|
17
|
+
source: "interview.wav",
|
|
18
|
+
speech: { words: [{ text: "um", start: 0, end: 0.3, confidence: 0.98, filler: true }] },
|
|
19
|
+
audio: { integratedLufs: -18, truePeakDb: -3, silenceMs: 120 },
|
|
20
|
+
visual: {
|
|
21
|
+
scenes: [{ id: "scene-1", start: 0, end: 10, label: "interview", confidence: 0.97 }],
|
|
22
|
+
subjects: [{ id: "subject-1", label: "person", confidence: 0.99, start: 0, end: 10 }],
|
|
23
|
+
motion: { score: 0.12, label: "low" },
|
|
24
|
+
keyframes: [{ time: 1, source: "interview.wav", labels: ["person", "interview"] }],
|
|
25
|
+
},
|
|
26
|
+
}],
|
|
27
|
+
assets: [{
|
|
28
|
+
id: "transition-cross-dissolve",
|
|
29
|
+
kind: "transition",
|
|
30
|
+
name: "Cross Dissolve",
|
|
31
|
+
vendor: "Framekit Fixture",
|
|
32
|
+
metadata: { durationFrames: 12 },
|
|
33
|
+
}],
|
|
34
|
+
frames: [{
|
|
35
|
+
position: { value: "24", timescale: "24" },
|
|
36
|
+
timecode: "00:00:01:00",
|
|
37
|
+
image: {
|
|
38
|
+
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
|
|
39
|
+
mimeType: "image/png",
|
|
40
|
+
width: 1,
|
|
41
|
+
height: 1,
|
|
42
|
+
},
|
|
43
|
+
}],
|
|
44
|
+
});
|
|
45
|
+
const liveMode = process.env.FRAMEKIT_EDITOR === "final-cut-live";
|
|
46
|
+
const headlessFinalCut = liveMode && process.env.FRAMEKIT_FINAL_CUT_HEADLESS === "1";
|
|
47
|
+
const fcpxmlPath = liveMode ? process.env.FRAMEKIT_FCPXML_PATH : undefined;
|
|
48
|
+
const connection = liveMode ? new FinalCutConnectionManager({ headless: headlessFinalCut }) : undefined;
|
|
49
|
+
const autoConnect = liveMode && process.env.FRAMEKIT_AUTO_CONNECT !== "0";
|
|
50
|
+
if (autoConnect)
|
|
51
|
+
connection?.startAutoConnect();
|
|
52
|
+
const liveAdapter = liveMode ? createFinalCutLiveAdapter() : undefined;
|
|
53
|
+
const nativeOperationLease = autoConnect
|
|
54
|
+
? createNativeOperationLease(() => connection?.stopAutoConnect(), () => connection?.startAutoConnect())
|
|
55
|
+
: undefined;
|
|
56
|
+
const editor = liveMode
|
|
57
|
+
? new FinalCutSessionAdapter({
|
|
58
|
+
live: liveAdapter,
|
|
59
|
+
...(fcpxmlPath
|
|
60
|
+
? (() => {
|
|
61
|
+
const document = new FcpxmlDocumentAdapter(fcpxmlPath);
|
|
62
|
+
return { snapshot: document, mutation: document };
|
|
63
|
+
})()
|
|
64
|
+
: {}),
|
|
65
|
+
assets: new FinalCutAssetRegistry({
|
|
66
|
+
roots: process.env.FRAMEKIT_FINAL_CUT_ASSET_ROOTS
|
|
67
|
+
?.split(process.platform === "win32" ? ";" : ":")
|
|
68
|
+
.map((root) => root.trim())
|
|
69
|
+
.filter(Boolean),
|
|
70
|
+
}),
|
|
71
|
+
})
|
|
72
|
+
: fixture;
|
|
73
|
+
const analyzers = liveMode
|
|
74
|
+
? createCommandAnalyzers({
|
|
75
|
+
speechCommand: process.env.FRAMEKIT_SPEECH_ANALYZER,
|
|
76
|
+
audioCommand: process.env.FRAMEKIT_AUDIO_ANALYZER,
|
|
77
|
+
visualCommand: process.env.FRAMEKIT_VISUAL_ANALYZER,
|
|
78
|
+
timeoutMs: parseTimeout(process.env.FRAMEKIT_ANALYZER_TIMEOUT_MS),
|
|
79
|
+
})
|
|
80
|
+
: {
|
|
81
|
+
speechAnalyzer: new FixtureSpeechAnalyzer(),
|
|
82
|
+
audioAnalyzer: new FixtureAudioAnalyzer(),
|
|
83
|
+
visualAnalyzer: new FixtureVisualAnalyzer(),
|
|
84
|
+
};
|
|
85
|
+
const runtime = new AgentVideoRuntime(editor, analyzers);
|
|
86
|
+
const nativeEditor = liveMode
|
|
87
|
+
? new FinalCutNativeAutomationAdapter({
|
|
88
|
+
enabled: !headlessFinalCut && process.env.FRAMEKIT_FINAL_CUT_NATIVE_WRITES === "1",
|
|
89
|
+
liveState: () => liveAdapter.readLiveState(),
|
|
90
|
+
nativeOperationLease,
|
|
91
|
+
})
|
|
92
|
+
: undefined;
|
|
93
|
+
const disposableNative = liveMode && !headlessFinalCut && !fcpxmlPath && nativeEditor
|
|
94
|
+
? new DisposableNativeEditWorkflow({
|
|
95
|
+
native: nativeEditor,
|
|
96
|
+
readCanonicalSnapshot: () => runtime.inspectProject(),
|
|
97
|
+
readCanonicalCapabilities: async () => (await runtime.inspectEditor()).capabilities,
|
|
98
|
+
})
|
|
99
|
+
: undefined;
|
|
100
|
+
const projectPublisher = liveMode && !headlessFinalCut && fcpxmlPath && process.env.FRAMEKIT_FINAL_CUT_NATIVE_WRITES === "1"
|
|
101
|
+
? new FinalCutProjectPublisher({
|
|
102
|
+
enabled: true,
|
|
103
|
+
sourcePath: fcpxmlPath,
|
|
104
|
+
liveState: () => liveAdapter.readLiveState(),
|
|
105
|
+
})
|
|
106
|
+
: undefined;
|
|
107
|
+
const videoExportProbeAvailable = liveMode && !headlessFinalCut && process.env.FRAMEKIT_FINAL_CUT_NATIVE_WRITES === "1"
|
|
108
|
+
? await isFinalCutVideoProbeAvailable()
|
|
109
|
+
: false;
|
|
110
|
+
const videoExporter = liveMode && !headlessFinalCut && process.env.FRAMEKIT_FINAL_CUT_NATIVE_WRITES === "1" && videoExportProbeAvailable
|
|
111
|
+
? new FinalCutVideoExporter({
|
|
112
|
+
enabled: true,
|
|
113
|
+
probeAvailable: true,
|
|
114
|
+
preflight: () => nativeEditor.inspect(),
|
|
115
|
+
nativeOperationLease,
|
|
116
|
+
})
|
|
117
|
+
: undefined;
|
|
118
|
+
const server = createMcpServer(runtime, {
|
|
119
|
+
connectionStatus: () => connection?.getStatus(),
|
|
120
|
+
nativeEditor,
|
|
121
|
+
disposableNative,
|
|
122
|
+
projectPublisher,
|
|
123
|
+
videoExporter,
|
|
124
|
+
});
|
|
125
|
+
const transport = new StdioServerTransport();
|
|
126
|
+
let shuttingDown = false;
|
|
127
|
+
async function shutdown(signal) {
|
|
128
|
+
if (shuttingDown)
|
|
129
|
+
return;
|
|
130
|
+
shuttingDown = true;
|
|
131
|
+
connection?.stopAutoConnect();
|
|
132
|
+
process.stderr.write(`framekit MCP server shutting down (${signal})\n`);
|
|
133
|
+
await transport.close();
|
|
134
|
+
await server.close();
|
|
135
|
+
process.exit(0);
|
|
136
|
+
}
|
|
137
|
+
process.once("SIGINT", () => void shutdown("SIGINT"));
|
|
138
|
+
process.once("SIGTERM", () => void shutdown("SIGTERM"));
|
|
139
|
+
process.stdin.once("end", () => void shutdown("stdin"));
|
|
140
|
+
await server.connect(transport);
|
|
141
|
+
function parseTimeout(value) {
|
|
142
|
+
if (!value)
|
|
143
|
+
return undefined;
|
|
144
|
+
const timeout = Number(value);
|
|
145
|
+
return Number.isFinite(timeout) && timeout > 0 ? timeout : undefined;
|
|
146
|
+
}
|