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