@causyne/agent 1.20.29 → 1.20.31

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.
@@ -1,102 +1,369 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import os from 'os';
3
- import { spawn } from 'child_process';
4
-
5
-
6
- const MAC_RESOLVE_API = "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting";
7
- const MAC_RESOLVE_LIB = "/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so";
8
-
9
-
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { spawn } from 'node:child_process';
10
6
  const PYTHON_SCRIPT = readFileSync(new URL('../tool-scripts/resolve_automator.py', import.meta.url), 'utf8');
11
-
12
- export const resolveAutomator = {
13
- schema: {
14
- name: 'resolve.act',
15
- description: 'Automate DaVinci Resolve Studio for native Cinema Workflows. Requires Resolve to be running with External Scripting: Local enabled.',
16
- parameters: {
17
- type: 'object',
18
- properties: {
19
- action: {
20
- type: 'string',
21
- enum: ['checkConnection', 'setupColorManagement', 'importAndAssemble']
22
- },
23
- mediaPath: {
24
- type: 'string',
25
- description: 'Absolute path to media directory to import'
26
- },
27
- color_space_mode: {
28
- type: 'string',
29
- enum: ['automatic', 'custom'],
30
- description: 'Use automatic (Resolve auto-detects based on metadata) or custom.'
31
- },
32
- fps: {
33
- type: 'string',
34
- description: 'Timeline framerate (e.g. 23.976) or "auto" to detect from clip metadata'
35
- },
36
- resolution_x: {
37
- type: 'string',
38
- description: 'Timeline width or "auto"'
39
- },
40
- resolution_y: {
41
- type: 'string',
42
- description: 'Timeline height or "auto"'
43
- }
44
- },
45
- required: ['action']
7
+ export function buildResolvePlatformConfig(platform = os.platform(), baseEnv = process.env, extraModuleDirs = []) {
8
+ if (platform === 'win32') {
9
+ const programData = baseEnv.PROGRAMDATA || 'C:\\ProgramData';
10
+ const programFiles = baseEnv.ProgramFiles || 'C:\\Program Files';
11
+ const scriptApi = `${programData}\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting`;
12
+ const scriptLib = `${programFiles}\\Blackmagic Design\\DaVinci Resolve\\fusionscript.dll`;
13
+ const modulesDir = `${scriptApi}\\Modules\\`;
14
+ const appBinary = `${programFiles}\\Blackmagic Design\\DaVinci Resolve\\Resolve.exe`;
15
+ const pathSep = ';';
16
+ const pyParts = [...extraModuleDirs, baseEnv.PYTHONPATH || '', modulesDir].filter(Boolean);
17
+ return {
18
+ platform,
19
+ scriptApi,
20
+ scriptLib,
21
+ modulesDir,
22
+ appBinary,
23
+ pythonBin: 'python',
24
+ pathSep,
25
+ env: {
26
+ ...baseEnv,
27
+ RESOLVE_SCRIPT_API: scriptApi,
28
+ RESOLVE_SCRIPT_LIB: scriptLib,
29
+ PYTHONPATH: pyParts.join(pathSep)
30
+ }
31
+ };
46
32
  }
47
- },
48
- async execute(args) {
49
- if (os.platform() !== 'darwin') {
50
- return { success: false, error: "Currently, only macOS is fully supported for this Resolve script pipeline." };
33
+ if (platform === 'darwin') {
34
+ const scriptApi = '/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting';
35
+ const scriptLib = '/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so';
36
+ const modulesDir = `${scriptApi}/Modules/`;
37
+ const appBinary = '/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/MacOS/Resolve';
38
+ const pathSep = ':';
39
+ const pyParts = [...extraModuleDirs, baseEnv.PYTHONPATH || '', modulesDir].filter(Boolean);
40
+ return {
41
+ platform,
42
+ scriptApi,
43
+ scriptLib,
44
+ modulesDir,
45
+ appBinary,
46
+ pythonBin: 'python3',
47
+ pathSep,
48
+ env: {
49
+ ...baseEnv,
50
+ RESOLVE_SCRIPT_API: scriptApi,
51
+ RESOLVE_SCRIPT_LIB: scriptLib,
52
+ PYTHONPATH: pyParts.join(pathSep)
53
+ }
54
+ };
51
55
  }
56
+ const scriptApi = '/opt/resolve/Developer/Scripting';
57
+ const scriptLib = '/opt/resolve/libs/Fusion/fusionscript.so';
58
+ const modulesDir = `${scriptApi}/Modules/`;
59
+ const appBinary = '/opt/resolve/bin/resolve';
60
+ const pathSep = ':';
61
+ const pyParts = [...extraModuleDirs, baseEnv.PYTHONPATH || '', modulesDir].filter(Boolean);
62
+ return {
63
+ platform,
64
+ scriptApi,
65
+ scriptLib,
66
+ modulesDir,
67
+ appBinary,
68
+ pythonBin: 'python3',
69
+ pathSep,
70
+ env: {
71
+ ...baseEnv,
72
+ RESOLVE_SCRIPT_API: scriptApi,
73
+ RESOLVE_SCRIPT_LIB: scriptLib,
74
+ PYTHONPATH: pyParts.join(pathSep)
75
+ }
76
+ };
77
+ }
78
+ export const MOCK_DAVINCI_RESOLVE_SCRIPT_PY = `# Simulated DaVinciResolveScript module for cross-platform verification
79
+ class _MockClip:
80
+ def __init__(self, path):
81
+ self.path = path
82
+ self.lut = None
83
+ self.cdl = None
84
+ def GetClipProperty(self, prop):
85
+ if prop == "FPS":
86
+ return "24"
87
+ if prop == "Resolution":
88
+ return "3840x2160"
89
+ return ""
90
+ def SetLUT(self, node_idx, lut_path):
91
+ self.lut = (node_idx, lut_path)
92
+ return True
93
+ def SetCDL(self, cdl_map):
94
+ self.cdl = cdl_map
95
+ return True
52
96
 
53
- const payload = JSON.stringify(args);
54
-
55
- return new Promise((resolvePromise) => {
56
- const env = {
57
- ...process.env,
58
- RESOLVE_SCRIPT_API: MAC_RESOLVE_API,
59
- RESOLVE_SCRIPT_LIB: MAC_RESOLVE_LIB,
60
- PYTHONPATH: `${process.env.PYTHONPATH || ''}:${MAC_RESOLVE_API}/Modules/`
61
- };
62
-
63
-
64
- const pyBin = "python3";
97
+ class _MockTimeline:
98
+ def __init__(self, name="Causyne_Master_Timeline"):
99
+ self.name = name
100
+ self.timecode = "01:00:00:00"
101
+ self.markers = {}
102
+ self.clips = [_MockClip("default_clip.mov")]
103
+ def GetName(self):
104
+ return self.name
105
+ def GetTrackCount(self, track_type):
106
+ return 2 if track_type in ("video", "audio") else 1
107
+ def GetCurrentTimecode(self):
108
+ return self.timecode
109
+ def SetCurrentTimecode(self, tc):
110
+ self.timecode = tc
111
+ return True
112
+ def AddMarker(self, frame_id, color, name, note, duration, custom_data=""):
113
+ self.markers[frame_id] = {"color": color, "name": name, "note": note, "duration": duration}
114
+ return True
115
+ def GetItemListInTrack(self, track_type, index):
116
+ return list(self.clips)
65
117
 
66
-
67
- const child = spawn(pyBin, ['-', payload], { env });
118
+ class _MockMediaPool:
119
+ def __init__(self, project):
120
+ self.project = project
121
+ def ImportMedia(self, paths):
122
+ clips = [_MockClip(p) for p in paths]
123
+ if self.project.timeline:
124
+ self.project.timeline.clips.extend(clips)
125
+ return clips
126
+ def CreateEmptyTimeline(self, name):
127
+ self.project.timeline = _MockTimeline(name)
128
+ return self.project.timeline
129
+ def AppendToTimeline(self, clips):
130
+ if not self.project.timeline:
131
+ self.project.timeline = _MockTimeline("Causyne_Automated_Timeline")
132
+ self.project.timeline.clips.extend(clips)
133
+ return clips
68
134
 
69
- let outputData = '';
70
- let errorData = '';
135
+ class _MockProject:
136
+ def __init__(self):
137
+ self.name = "Causyne_Cinema_Project"
138
+ self.settings = {
139
+ "timelineFrameRate": "24",
140
+ "timelineResolutionWidth": "3840",
141
+ "timelineResolutionHeight": "2160",
142
+ "colorScienceMode": "davinciYRGBColorManaged"
143
+ }
144
+ self.timeline = _MockTimeline()
145
+ self.media_pool = _MockMediaPool(self)
146
+ self.render_settings = {}
147
+ def GetName(self):
148
+ return self.name
149
+ def GetSetting(self, key):
150
+ return self.settings.get(key, "")
151
+ def SetSetting(self, key, val):
152
+ self.settings[key] = str(val)
153
+ return True
154
+ def GetMediaPool(self):
155
+ return self.media_pool
156
+ def GetCurrentTimeline(self):
157
+ return self.timeline
158
+ def LoadRenderPreset(self, name):
159
+ self.render_settings["Preset"] = name
160
+ return True
161
+ def SetRenderSettings(self, settings):
162
+ self.render_settings.update(settings)
163
+ return True
164
+ def AddRenderJob(self):
165
+ return "resolve_render_job_001"
166
+ def StartRendering(self, job_ids):
167
+ return True
71
168
 
72
- child.stdout.on('data', (data) => {
73
- outputData += data.toString();
74
- });
169
+ class _MockProjectManager:
170
+ def __init__(self):
171
+ self.project = _MockProject()
172
+ def GetCurrentProject(self):
173
+ return self.project
75
174
 
76
- child.stderr.on('data', (data) => {
77
- errorData += data.toString();
78
- });
175
+ class _MockResolveApp:
176
+ def __init__(self):
177
+ self.pm = _MockProjectManager()
178
+ def GetProjectManager(self):
179
+ return self.pm
79
180
 
80
- child.on('close', (code) => {
81
- if (outputData.trim()) {
82
- try {
83
- const lines = outputData.trim().split('\n');
84
- const jsonLine = lines.find(l => l.trim().startsWith('{') && l.trim().endsWith('}'));
85
- if (jsonLine) {
86
- resolvePromise(JSON.parse(jsonLine));
87
- return;
88
- }
89
- } catch (e) {}
181
+ def scriptapp(name):
182
+ if name == "Resolve":
183
+ return _MockResolveApp()
184
+ return None
185
+ `;
186
+ export async function runResolveBridge(args, options = {}) {
187
+ const simulate = Boolean(options.simulate || args.simulate || process.env.CAUSYNE_SIMULATE_RESOLVE === '1');
188
+ let tempMockDir = null;
189
+ try {
190
+ const extraDirs = [];
191
+ if (simulate) {
192
+ tempMockDir = await fs.mkdtemp(path.join(os.tmpdir(), 'causyne-resolve-sim-'));
193
+ await fs.writeFile(path.join(tempMockDir, 'DaVinciResolveScript.py'), MOCK_DAVINCI_RESOLVE_SCRIPT_PY, 'utf8');
194
+ extraDirs.push(tempMockDir);
90
195
  }
91
- resolvePromise({
92
- success: false,
93
- error: errorData.trim() || outputData.trim() || `Python process exited with code ${code}`
196
+ const platformCfg = buildResolvePlatformConfig(options.platform ?? os.platform(), process.env, extraDirs);
197
+ const payload = JSON.stringify(args);
198
+ const pyBin = os.platform() === 'win32' ? platformCfg.pythonBin : 'python3';
199
+ return await new Promise((resolvePromise) => {
200
+ const child = spawn(pyBin, ['-', payload], { env: platformCfg.env });
201
+ let outputData = '';
202
+ let errorData = '';
203
+ child.stdout.on('data', (data) => {
204
+ outputData += data.toString();
205
+ });
206
+ child.stderr.on('data', (data) => {
207
+ errorData += data.toString();
208
+ });
209
+ child.on('error', (err) => {
210
+ resolvePromise({
211
+ success: false,
212
+ error: `Failed to spawn Python interpreter (${pyBin}): ${err.message}`
213
+ });
214
+ });
215
+ child.on('close', (code) => {
216
+ if (outputData.trim()) {
217
+ try {
218
+ const lines = outputData.trim().split('\n');
219
+ const jsonLine = lines.find(l => l.trim().startsWith('{') && l.trim().endsWith('}'));
220
+ if (jsonLine) {
221
+ resolvePromise(JSON.parse(jsonLine));
222
+ return;
223
+ }
224
+ }
225
+ catch {
226
+ // Fall through to error return
227
+ }
228
+ }
229
+ resolvePromise({
230
+ success: false,
231
+ error: errorData.trim() || outputData.trim() || `Python process exited with code ${String(code)}`
232
+ });
233
+ });
234
+ child.stdin.write(PYTHON_SCRIPT);
235
+ child.stdin.end();
94
236
  });
95
- });
96
-
97
- const decodedScript = PYTHON_SCRIPT;
98
- child.stdin.write(decodedScript);
99
- child.stdin.end();
100
- });
101
- }
237
+ }
238
+ finally {
239
+ if (tempMockDir) {
240
+ await fs.rm(tempMockDir, { recursive: true, force: true }).catch(() => { });
241
+ }
242
+ }
243
+ }
244
+ export const resolveAutomator = {
245
+ schema: {
246
+ name: 'resolve.act',
247
+ description: 'Automate DaVinci Resolve Studio across macOS, Windows, and Linux for native cinema workflows: active timeline inspection, DaVinci YRGB Color Management (RCM), media pool import & timeline assembly, playhead clip insertion, timeline markers, LUT/CDL color grading, and Deliver render queue automation.',
248
+ parameters: {
249
+ type: 'object',
250
+ properties: {
251
+ action: {
252
+ type: 'string',
253
+ enum: [
254
+ 'checkConnection',
255
+ 'inspectActive',
256
+ 'setupColorManagement',
257
+ 'importAndAssemble',
258
+ 'insertClipAtPlayhead',
259
+ 'addMarker',
260
+ 'applyLutOrGrade',
261
+ 'renderTimeline'
262
+ ]
263
+ },
264
+ mediaPath: {
265
+ type: 'string',
266
+ description: 'Absolute path to media file or directory to import into the Media Pool.'
267
+ },
268
+ color_space_mode: {
269
+ type: 'string',
270
+ enum: ['automatic', 'custom'],
271
+ description: 'Use automatic (Resolve auto-detects clip color space) or custom RCM.'
272
+ },
273
+ input_color_space: {
274
+ type: 'string',
275
+ description: 'Input color space for custom RCM (e.g. "ARRI LogC3", "Sony S-Log3/S-Gamut3.Cine").'
276
+ },
277
+ timeline_color_space: {
278
+ type: 'string',
279
+ description: 'Working timeline color space (default "DaVinci WG/Intermediate").'
280
+ },
281
+ output_color_space: {
282
+ type: 'string',
283
+ description: 'Output color space (default "Rec.709 Gamma 2.4").'
284
+ },
285
+ fps: {
286
+ type: 'string',
287
+ description: 'Timeline framerate (e.g. "23.976", "24") or "auto".'
288
+ },
289
+ resolution_x: {
290
+ type: 'string',
291
+ description: 'Timeline width (e.g. "3840", "1920") or "auto".'
292
+ },
293
+ resolution_y: {
294
+ type: 'string',
295
+ description: 'Timeline height (e.g. "2160", "1080") or "auto".'
296
+ },
297
+ timelineName: {
298
+ type: 'string',
299
+ description: 'Timeline name when creating a new timeline.'
300
+ },
301
+ timecode: {
302
+ type: 'string',
303
+ description: 'Target playhead timecode (e.g. "01:00:05:00").'
304
+ },
305
+ frameId: {
306
+ type: 'integer',
307
+ description: 'Frame offset for addMarker.'
308
+ },
309
+ markerName: {
310
+ type: 'string',
311
+ description: 'Marker title.'
312
+ },
313
+ markerColor: {
314
+ type: 'string',
315
+ description: 'Marker color (e.g. "Blue", "Red", "Green", "Yellow").'
316
+ },
317
+ markerNote: {
318
+ type: 'string',
319
+ description: 'Marker note text.'
320
+ },
321
+ lutPath: {
322
+ type: 'string',
323
+ description: 'Path to .cube LUT file for applyLutOrGrade.'
324
+ },
325
+ nodeIndex: {
326
+ type: 'integer',
327
+ description: '1-based serial node index for LUT/CDL application.'
328
+ },
329
+ cdl: {
330
+ type: 'object',
331
+ description: 'CDL grade parameters { slope, offset, power, saturation }.',
332
+ properties: {
333
+ slope: { type: 'string' },
334
+ offset: { type: 'string' },
335
+ power: { type: 'string' },
336
+ saturation: { type: 'string' }
337
+ }
338
+ },
339
+ presetName: {
340
+ type: 'string',
341
+ description: 'Deliver page render preset name for renderTimeline.'
342
+ },
343
+ targetDir: {
344
+ type: 'string',
345
+ description: 'Output directory for renderTimeline.'
346
+ },
347
+ customName: {
348
+ type: 'string',
349
+ description: 'Custom output filename for renderTimeline.'
350
+ },
351
+ startRender: {
352
+ type: 'boolean',
353
+ description: 'Whether to immediately trigger rendering after adding job (default true).'
354
+ },
355
+ simulate: {
356
+ type: 'boolean',
357
+ description: 'Run against the built-in DaVinciResolveScript simulator when DaVinci Resolve is not installed.'
358
+ }
359
+ },
360
+ required: ['action']
361
+ }
362
+ },
363
+ async execute(args) {
364
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
365
+ return { success: false, error: 'Expected DaVinci Resolve action arguments' };
366
+ }
367
+ return await runResolveBridge(args);
368
+ }
102
369
  };