@ajsmonty/adobe-mcp 1.1.2 → 1.5.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/CHANGELOG.md +19 -0
- package/README.md +361 -119
- package/SECURITY.md +24 -1
- package/adapters/ae_more.mjs +208 -0
- package/adapters/an.mjs +96 -0
- package/adapters/assets.mjs +194 -0
- package/adapters/blender.mjs +230 -0
- package/adapters/id.mjs +250 -0
- package/adapters/ppro.mjs +4 -3
- package/adapters/ppro_more.mjs +393 -0
- package/adapters/ps_ai_more.mjs +277 -0
- package/adapters/substance.mjs +193 -0
- package/adapters/texlib.mjs +193 -0
- package/bridges/blender/adobe_mcp_bridge.py +132 -0
- package/cep/mcp-bridge/CSXS/manifest.xml +36 -2
- package/cep/mcp-bridge/main.js +48 -20
- package/cli/doctor.mjs +234 -0
- package/cli/index.mjs +67 -0
- package/cli/install.mjs +149 -0
- package/core/barrows.mjs +16 -0
- package/core/blender_pbr.py +148 -0
- package/core/bridge.mjs +166 -77
- package/core/harness.jsx +11 -6
- package/core/harness.py +34 -0
- package/core/helpers.mjs +196 -0
- package/core/platform.mjs +209 -0
- package/core/pybridge.mjs +256 -0
- package/core/telemetry.mjs +80 -0
- package/core/texlib.mjs +279 -0
- package/core/win/run_com.js +33 -0
- package/core/workspace.mjs +1 -1
- package/knowledge/knowledge.mjs +8 -5
- package/knowledge/lessons.jsonl +19 -0
- package/package.json +56 -3
- package/scripts/ae/Cinematic_3D_Composite.jsx +173 -0
- package/scripts/blender/Creature_Walk_Cinematic.py +569 -0
- package/scripts/substance/Creature_Skin_LookDev.py +148 -0
- package/server.mjs +92 -27
- package/workflow/setup.mjs +106 -0
- package/workflow/vfx.mjs +136 -0
- package/workflow/workflow.mjs +66 -21
package/core/bridge.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// adobe-mcp core bridge: routes ExtendScript to each app.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// macOS AE/PS/AI: osascript (AppleScript DoScript / do javascript).
|
|
3
|
+
// Windows AE: AfterFX.exe -r <file.jsx> (no COM server); PS/AI: COM DoJavaScriptFile via cscript.
|
|
4
|
+
// Both Premiere: command-file handoff to the mcp-bridge CEP panel.
|
|
4
5
|
import { execFile } from "node:child_process";
|
|
5
6
|
import fs from "node:fs";
|
|
6
7
|
import os from "node:os";
|
|
@@ -8,55 +9,55 @@ import path from "node:path";
|
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
9
10
|
import { logError, matchError, hintBlock } from "../knowledge/knowledge.mjs";
|
|
10
11
|
import { WORKSPACE } from "./workspace.mjs";
|
|
12
|
+
import {
|
|
13
|
+
IS_WIN,
|
|
14
|
+
IS_MAC,
|
|
15
|
+
PLATFORM_LABEL,
|
|
16
|
+
macAppName,
|
|
17
|
+
aeExecutable,
|
|
18
|
+
runningAeExecutable,
|
|
19
|
+
COM_PROGIDS,
|
|
20
|
+
isAppRunning,
|
|
21
|
+
downscalePng as platformDownscale,
|
|
22
|
+
} from "./platform.mjs";
|
|
11
23
|
|
|
12
24
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
25
|
const HARNESS = fs.readFileSync(path.join(__dirname, "harness.jsx"), "utf8");
|
|
26
|
+
const COM_RUNNER = path.join(__dirname, "win", "run_com.js");
|
|
14
27
|
|
|
15
28
|
export { WORKSPACE };
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
// The CEP panel cannot see ADOBE_MCP_WORKSPACE (it runs inside Premiere), so the command
|
|
30
|
+
// folder is always ~/AdobeMCP/ppro-bridge, wherever the asset workspace lives.
|
|
31
|
+
// The same holds for every app the panel serves: Premiere and After Effects each get their own folder.
|
|
32
|
+
export const PANEL_DIRS = {
|
|
33
|
+
ppro: path.join(os.homedir(), "AdobeMCP", "ppro-bridge"),
|
|
34
|
+
ae: path.join(os.homedir(), "AdobeMCP", "ae-bridge"),
|
|
35
|
+
};
|
|
36
|
+
export const PPRO_BRIDGE_DIR = PANEL_DIRS.ppro;
|
|
37
|
+
for (const d of Object.values(PANEL_DIRS)) fs.mkdirSync(d, { recursive: true });
|
|
18
38
|
|
|
19
39
|
// ---------------------------------------------------------------------------
|
|
20
40
|
// App registry
|
|
21
41
|
// ---------------------------------------------------------------------------
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const dirs = fs
|
|
27
|
-
.readdirSync("/Applications")
|
|
28
|
-
.filter((e) => dirPattern.test(e))
|
|
29
|
-
.sort();
|
|
30
|
-
if (dirs.length) {
|
|
31
|
-
const dir = dirs[dirs.length - 1];
|
|
32
|
-
if (dir.endsWith(".app")) return dir.replace(/\.app$/, "");
|
|
33
|
-
const inner = fs
|
|
34
|
-
.readdirSync(path.join("/Applications", dir))
|
|
35
|
-
.find((f) => f.endsWith(".app"));
|
|
36
|
-
if (inner) return inner.replace(/\.app$/, "");
|
|
37
|
-
return dir;
|
|
38
|
-
}
|
|
39
|
-
} catch {
|
|
40
|
-
/* fall through */
|
|
41
|
-
}
|
|
42
|
-
return fallback;
|
|
43
|
-
}
|
|
43
|
+
const AE_PREF_HINT =
|
|
44
|
+
' Enable AE Preferences → Scripting & Expressions → "Allow Scripts to Write Files and Access Network".';
|
|
44
45
|
|
|
45
46
|
export const APPS = {
|
|
46
47
|
ae: {
|
|
47
48
|
label: "After Effects",
|
|
48
|
-
bridge: "osascript",
|
|
49
|
-
appName: () =>
|
|
49
|
+
bridge: IS_WIN ? "afterfx" : "osascript",
|
|
50
|
+
appName: () => macAppName(/^Adobe After Effects/i, "Adobe After Effects", "AE_APP_NAME"),
|
|
50
51
|
osa: (app, jsxPath) =>
|
|
51
52
|
`tell application "${app}" to DoScript "$.evalFile('${jsxPath}')"`,
|
|
52
53
|
undoGroup: true,
|
|
53
|
-
writePrefHint:
|
|
54
|
-
' Enable AE Preferences → Scripting & Expressions → "Allow Scripts to Write Files and Access Network".',
|
|
54
|
+
writePrefHint: AE_PREF_HINT,
|
|
55
55
|
},
|
|
56
56
|
ps: {
|
|
57
57
|
label: "Photoshop",
|
|
58
|
-
bridge: "osascript",
|
|
59
|
-
appName: () =>
|
|
58
|
+
bridge: IS_WIN ? "com" : "osascript",
|
|
59
|
+
appName: () => macAppName(/^Adobe Photoshop/i, "Adobe Photoshop 2026", "PS_APP_NAME"),
|
|
60
|
+
progId: COM_PROGIDS.ps,
|
|
60
61
|
osa: (app, jsxPath) =>
|
|
61
62
|
`tell application "${app}" to do javascript "$.evalFile(new File('${jsxPath}'))"`,
|
|
62
63
|
undoGroup: false,
|
|
@@ -64,17 +65,29 @@ export const APPS = {
|
|
|
64
65
|
},
|
|
65
66
|
ai: {
|
|
66
67
|
label: "Illustrator",
|
|
67
|
-
bridge: "osascript",
|
|
68
|
-
appName: () =>
|
|
68
|
+
bridge: IS_WIN ? "com" : "osascript",
|
|
69
|
+
appName: () => macAppName(/^Adobe Illustrator/i, "Adobe Illustrator", "AI_APP_NAME"),
|
|
70
|
+
progId: COM_PROGIDS.ai,
|
|
69
71
|
osa: (app, jsxPath) =>
|
|
70
72
|
`tell application "${app}" to do javascript "$.evalFile(new File('${jsxPath}'))"`,
|
|
71
73
|
undoGroup: false,
|
|
72
74
|
writePrefHint: "",
|
|
73
75
|
},
|
|
76
|
+
id: {
|
|
77
|
+
label: "InDesign",
|
|
78
|
+
bridge: IS_WIN ? "com" : "osascript",
|
|
79
|
+
appName: () => macAppName(/^Adobe InDesign/i, "Adobe InDesign 2026", "ID_APP_NAME"),
|
|
80
|
+
progId: COM_PROGIDS.id,
|
|
81
|
+
comMode: "doscript",
|
|
82
|
+
osa: (app, jsxPath) =>
|
|
83
|
+
`tell application "${app}" to do script "$.evalFile(new File('${jsxPath}'))" language javascript`,
|
|
84
|
+
undoGroup: false,
|
|
85
|
+
writePrefHint: "",
|
|
86
|
+
},
|
|
74
87
|
ppro: {
|
|
75
88
|
label: "Premiere Pro",
|
|
76
89
|
bridge: "panel",
|
|
77
|
-
appName: () =>
|
|
90
|
+
appName: () => macAppName(/^Adobe Premiere Pro/i, "Adobe Premiere Pro 2026", "PPRO_APP_NAME"),
|
|
78
91
|
undoGroup: false,
|
|
79
92
|
writePrefHint: "",
|
|
80
93
|
},
|
|
@@ -84,12 +97,12 @@ export const APPS = {
|
|
|
84
97
|
// Execution
|
|
85
98
|
// ---------------------------------------------------------------------------
|
|
86
99
|
|
|
87
|
-
function
|
|
100
|
+
function exec(cmd, args, timeoutMs) {
|
|
88
101
|
return new Promise((resolve, reject) => {
|
|
89
102
|
execFile(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{ timeout: timeoutMs, killSignal: "SIGKILL" },
|
|
103
|
+
cmd,
|
|
104
|
+
args,
|
|
105
|
+
{ timeout: timeoutMs, killSignal: "SIGKILL", windowsHide: true },
|
|
93
106
|
(err, stdout, stderr) => {
|
|
94
107
|
if (err) {
|
|
95
108
|
err.stderr = stderr;
|
|
@@ -100,17 +113,48 @@ function osascript(script, timeoutMs) {
|
|
|
100
113
|
});
|
|
101
114
|
}
|
|
102
115
|
|
|
116
|
+
const osascript = (script, timeoutMs) => exec("osascript", ["-e", script], timeoutMs);
|
|
117
|
+
|
|
118
|
+
/** Map a launcher failure to an actionable hint. Pure, so it is unit-tested on every OS. */
|
|
119
|
+
export function launchFailureHint(app, err, timeoutMs, scriptPath) {
|
|
120
|
+
const msg = String(err.stderr || err.message || err);
|
|
121
|
+
if (err.killed || /timed?.?out/i.test(msg))
|
|
122
|
+
return ` Timed out after ${timeoutMs / 1000}s — ${app.label} may be showing a modal dialog, or raise timeout_seconds. Script kept: ${scriptPath}`;
|
|
123
|
+
// macOS AppleScript errors
|
|
124
|
+
if (/-600|isn.t running|can.t be found|-1728|-10810/i.test(msg))
|
|
125
|
+
return ` Is ${app.label} open? (Looked for app "${app.appName()}"; override with env var.)`;
|
|
126
|
+
if (/-1743|not authori[sz]ed/i.test(msg))
|
|
127
|
+
return ` macOS blocked Automation permission for ${app.label} — approve in System Settings → Privacy & Security → Automation.`;
|
|
128
|
+
// Windows COM errors (run_com.js prints COM_CREATE_FAILED / COM_CALL_FAILED 0x<hresult>)
|
|
129
|
+
if (/COM_CREATE_FAILED/.test(msg) && /800401f3|800a01ad|80040154/i.test(msg))
|
|
130
|
+
return ` ${app.label} is not registered for COM automation — is it installed? Run it once as a normal user, or set ${{ Photoshop: "PS", Illustrator: "AI", InDesign: "ID" }[app.label] || "PS"}_COM_PROGID (e.g. "Photoshop.Application.200").`;
|
|
131
|
+
if (/COM_CREATE_FAILED/.test(msg) && /80080005|800706ba|80010001/i.test(msg))
|
|
132
|
+
return ` ${app.label} did not answer COM — it may be starting up or showing a modal dialog. Try again once it is idle.`;
|
|
133
|
+
if (/COM_CREATE_FAILED/.test(msg) && /80070005/i.test(msg))
|
|
134
|
+
return ` Access denied: ${app.label} and this MCP client must run at the same privilege level (both normal, or both "Run as administrator").`;
|
|
135
|
+
if (/ENOENT/.test(msg) && /cscript/i.test(msg))
|
|
136
|
+
return " Windows Script Host (cscript.exe) is missing or disabled by policy; it is needed to reach Photoshop/Illustrator over COM.";
|
|
137
|
+
return "";
|
|
138
|
+
}
|
|
139
|
+
|
|
103
140
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
104
141
|
|
|
105
142
|
function writeHarnessed(appKey, userCode, resultPath, scriptPath) {
|
|
106
143
|
const app = APPS[appKey];
|
|
107
144
|
const undoOpen = app.undoGroup ? "app.beginUndoGroup('adobe-mcp');" : "";
|
|
108
145
|
const undoClose = app.undoGroup ? "app.endUndoGroup();" : "";
|
|
109
|
-
|
|
146
|
+
// resultPath null = panel route: the harness returns its JSON and the panel writes the file.
|
|
147
|
+
const wrapped = HARNESS.replace(/__RESULT_PATH__/g, () => (resultPath === null ? "null" : jsxString(resultPath)))
|
|
110
148
|
.replace(/__USER_CODE__/g, () => userCode)
|
|
111
149
|
.replace(/__UNDO_OPEN__/g, () => undoOpen)
|
|
112
150
|
.replace(/__UNDO_CLOSE__/g, () => undoClose);
|
|
113
|
-
|
|
151
|
+
// Windows ExtendScript reads BOM-less files in the ANSI code page; the BOM keeps non-ASCII user code intact.
|
|
152
|
+
fs.writeFileSync(scriptPath, (IS_WIN ? "\uFEFF" : "") + wrapped, "utf8");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** JS string literal with non-ASCII escaped, so paths like C:\Users\José survive any file encoding. */
|
|
156
|
+
export function jsxString(str) {
|
|
157
|
+
return JSON.stringify(String(str)).replace(/[\u007f-\uffff]/g, (c) => "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0"));
|
|
114
158
|
}
|
|
115
159
|
|
|
116
160
|
async function awaitResultFile(resultPath, timeoutMs, failMsg) {
|
|
@@ -135,14 +179,36 @@ async function awaitResultFile(resultPath, timeoutMs, failMsg) {
|
|
|
135
179
|
return parsed.result;
|
|
136
180
|
}
|
|
137
181
|
|
|
138
|
-
|
|
139
|
-
|
|
182
|
+
/** True when the MCP Bridge panel inside that app has written a heartbeat in the last 5 s. */
|
|
183
|
+
export function panelAlive(appKey) {
|
|
184
|
+
const dir = PANEL_DIRS[appKey];
|
|
185
|
+
if (!dir) return false;
|
|
140
186
|
try {
|
|
141
|
-
return Date.now() - Number(fs.readFileSync(
|
|
187
|
+
return Date.now() - Number(fs.readFileSync(path.join(dir, "heartbeat"), "utf8")) < 5000;
|
|
142
188
|
} catch {
|
|
143
189
|
return false;
|
|
144
190
|
}
|
|
145
191
|
}
|
|
192
|
+
export const pproPanelAlive = () => panelAlive("ppro");
|
|
193
|
+
|
|
194
|
+
/** Run a harnessed script through the panel: write a command file, wait for the panel's result file. */
|
|
195
|
+
async function runViaPanel(app, appKey, userCode, stamp, resultPath, scriptPath, timeoutMs) {
|
|
196
|
+
writeHarnessed(appKey, userCode, null, scriptPath);
|
|
197
|
+
const cmdPath = path.join(PANEL_DIRS[appKey], `cmd_${stamp}.json`);
|
|
198
|
+
fs.writeFileSync(cmdPath + ".tmp", JSON.stringify({ jsx: scriptPath, result: resultPath }), "utf8");
|
|
199
|
+
fs.renameSync(cmdPath + ".tmp", cmdPath); // the panel never reads a half-written command
|
|
200
|
+
try {
|
|
201
|
+
const result = await awaitResultFile(
|
|
202
|
+
resultPath,
|
|
203
|
+
timeoutMs,
|
|
204
|
+
`${app.label} panel accepted the command but no result appeared within ${timeoutMs / 1000}s. A modal dialog may be open. Script kept: ${scriptPath}`
|
|
205
|
+
);
|
|
206
|
+
fs.rmSync(scriptPath, { force: true });
|
|
207
|
+
return result;
|
|
208
|
+
} finally {
|
|
209
|
+
fs.rmSync(cmdPath, { force: true }); // never picked up (panel closed mid-wait): don't run it later
|
|
210
|
+
}
|
|
211
|
+
}
|
|
146
212
|
|
|
147
213
|
/**
|
|
148
214
|
* Run ExtendScript inside the given app. Returns the JSON-decoded result.
|
|
@@ -166,24 +232,34 @@ async function runJSXInner(appKey, userCode, timeoutMs = 120000) {
|
|
|
166
232
|
const stamp = `${Date.now()}_${Math.floor(Math.random() * 1e6)}`;
|
|
167
233
|
const resultPath = path.join(os.tmpdir(), `adobe_mcp_result_${appKey}_${stamp}.json`);
|
|
168
234
|
const scriptPath = path.join(os.tmpdir(), `adobe_mcp_script_${appKey}_${stamp}.jsx`);
|
|
235
|
+
|
|
236
|
+
// After Effects: the panel route needs no scripting preference and no Automation prompt, so it
|
|
237
|
+
// wins whenever the panel is running. ADOBE_MCP_AE_ROUTE=script forces the old route.
|
|
238
|
+
if (appKey === "ae" && process.env.ADOBE_MCP_AE_ROUTE !== "script" && panelAlive("ae"))
|
|
239
|
+
return runViaPanel(app, appKey, userCode, stamp, resultPath, scriptPath, timeoutMs);
|
|
240
|
+
if (app.bridge === "panel") {
|
|
241
|
+
if (!panelAlive(appKey))
|
|
242
|
+
throw new Error(
|
|
243
|
+
`${app.label}'s MCP Bridge panel is not running. It starts by itself when ${app.label} opens; if it doesn't, ` +
|
|
244
|
+
"open Window → Extensions → MCP Bridge. Not in the menu? Run `npx @ajsmonty/adobe-mcp install` " +
|
|
245
|
+
`(copies the panel and enables PlayerDebugMode), restart ${app.label}, then check with \`npx @ajsmonty/adobe-mcp doctor\`.`
|
|
246
|
+
);
|
|
247
|
+
return runViaPanel(app, appKey, userCode, stamp, resultPath, scriptPath, timeoutMs);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!IS_MAC && !IS_WIN)
|
|
251
|
+
throw new Error(`Adobe apps need macOS or Windows; this server is running on ${PLATFORM_LABEL}. Blender and texture tools still work here.`);
|
|
169
252
|
writeHarnessed(appKey, userCode, resultPath, scriptPath);
|
|
170
253
|
|
|
171
|
-
if (app.bridge === "osascript") {
|
|
172
|
-
const appName = app.appName();
|
|
254
|
+
if (app.bridge === "osascript" || app.bridge === "com") {
|
|
173
255
|
try {
|
|
174
|
-
await osascript(app.osa(appName, scriptPath), timeoutMs);
|
|
256
|
+
if (app.bridge === "osascript") await osascript(app.osa(app.appName(), scriptPath), timeoutMs);
|
|
257
|
+
else
|
|
258
|
+
await exec("cscript.exe", ["//nologo", "//E:JScript", COM_RUNNER, app.progId(), scriptPath, ...(app.comMode ? [app.comMode] : [])], timeoutMs);
|
|
175
259
|
} catch (err) {
|
|
176
260
|
fs.rmSync(resultPath, { force: true });
|
|
177
|
-
const msg = String(err.stderr || err.message || err);
|
|
178
|
-
|
|
179
|
-
if (err.killed || /timed?.?out/i.test(msg)) {
|
|
180
|
-
hint = ` Timed out after ${timeoutMs / 1000}s — ${app.label} may be showing a modal dialog, or raise timeout_seconds. Script kept: ${scriptPath}`;
|
|
181
|
-
} else if (/-600|isn.t running|can.t be found|-1728|-10810/i.test(msg)) {
|
|
182
|
-
hint = ` Is ${app.label} open? (Looked for app "${appName}"; override with env var.)`;
|
|
183
|
-
} else if (/-1743|not authori[sz]ed/i.test(msg)) {
|
|
184
|
-
hint = ` macOS blocked Automation permission for ${app.label} — approve in System Settings → Privacy & Security → Automation.`;
|
|
185
|
-
}
|
|
186
|
-
throw new Error(`osascript failed: ${msg.trim()}.${hint}`);
|
|
261
|
+
const msg = String(err.stderr || err.message || err).trim();
|
|
262
|
+
throw new Error(`${app.bridge === "com" ? "COM" : "osascript"} call failed: ${msg}.${launchFailureHint(app, err, timeoutMs, scriptPath)}`);
|
|
187
263
|
}
|
|
188
264
|
const result = await awaitResultFile(
|
|
189
265
|
resultPath,
|
|
@@ -194,28 +270,41 @@ async function runJSXInner(appKey, userCode, timeoutMs = 120000) {
|
|
|
194
270
|
return result;
|
|
195
271
|
}
|
|
196
272
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
273
|
+
if (app.bridge === "afterfx") {
|
|
274
|
+
// AfterFX.exe -r hands the file to the running instance. Whether it returns at once or waits
|
|
275
|
+
// for the script, the caller's timeout is measured on the result file, not the launcher.
|
|
276
|
+
// Prefer the running instance's own AfterFX.exe: -r on a different installed version would
|
|
277
|
+
// start a second After Effects.
|
|
278
|
+
const exe = (await runningAeExecutable()) || aeExecutable();
|
|
279
|
+
if (!exe)
|
|
280
|
+
throw new Error(
|
|
281
|
+
"After Effects not found under Program Files\\Adobe. Set AE_EXE to the full path of AfterFX.exe."
|
|
282
|
+
);
|
|
283
|
+
if ((await isAppRunning("ae")) === false)
|
|
284
|
+
throw new Error(`Is After Effects open? Start it (with a project, even the empty default) and retry. (Would launch: ${exe})`);
|
|
285
|
+
const started = Date.now();
|
|
286
|
+
try {
|
|
287
|
+
await exec(exe, ["-r", scriptPath], Math.min(timeoutMs, 30000));
|
|
288
|
+
} catch (err) {
|
|
289
|
+
// If AfterFX.exe -r waits for the script to finish, a long script outlives the launcher's
|
|
290
|
+
// timeout: keep waiting for the result file instead of failing.
|
|
291
|
+
if (!err.killed) {
|
|
292
|
+
fs.rmSync(resultPath, { force: true });
|
|
293
|
+
const msg = String(err.stderr || err.message || err).trim();
|
|
294
|
+
throw new Error(`AfterFX.exe -r failed: ${msg}.${launchFailureHint(app, err, timeoutMs, scriptPath)}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const result = await awaitResultFile(
|
|
298
|
+
resultPath,
|
|
299
|
+
Math.max(timeoutMs - (Date.now() - started), 15000),
|
|
300
|
+
`After Effects accepted the script but no result file appeared within ${timeoutMs / 1000}s. A modal dialog may be open.${app.writePrefHint} Script kept: ${scriptPath}`
|
|
203
301
|
);
|
|
302
|
+
fs.rmSync(scriptPath, { force: true });
|
|
303
|
+
return result;
|
|
204
304
|
}
|
|
205
|
-
const cmdPath = path.join(PPRO_BRIDGE_DIR, `cmd_${stamp}.json`);
|
|
206
|
-
fs.writeFileSync(cmdPath, JSON.stringify({ jsx: scriptPath }), "utf8");
|
|
207
|
-
const result = await awaitResultFile(
|
|
208
|
-
resultPath,
|
|
209
|
-
timeoutMs,
|
|
210
|
-
`Premiere panel accepted the command but no result appeared. A modal dialog may be open, or the JSX failed to parse. Script kept: ${scriptPath}`
|
|
211
|
-
);
|
|
212
|
-
fs.rmSync(scriptPath, { force: true });
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
305
|
|
|
216
|
-
|
|
217
|
-
export async function downscalePng(pngPath, maxWidth) {
|
|
218
|
-
await new Promise((resolve) =>
|
|
219
|
-
execFile("sips", ["-Z", String(maxWidth), pngPath], () => resolve())
|
|
220
|
-
);
|
|
306
|
+
throw new Error(`No route to ${app.label} (bridge "${app.bridge}").`);
|
|
221
307
|
}
|
|
308
|
+
|
|
309
|
+
// Shared by preview tools: downscale a PNG in place (sips on macOS, System.Drawing on Windows).
|
|
310
|
+
export const downscalePng = platformDownscale;
|
package/core/harness.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// ae-mcp ExtendScript harness.
|
|
2
2
|
// Wraps user code in a try/catch + undo group, serializes the return value
|
|
3
|
-
// to JSON (ExtendScript is ES3 — no native JSON), writes it to __RESULT_PATH__.
|
|
3
|
+
// to JSON (ExtendScript is ES3 — no native JSON), writes it to __RESULT_PATH__ and returns it.
|
|
4
4
|
(function () {
|
|
5
5
|
function __q(s) {
|
|
6
6
|
s = String(s);
|
|
@@ -59,9 +59,14 @@ __USER_CODE__
|
|
|
59
59
|
} catch (__e) {
|
|
60
60
|
__payload = '{"ok":false,"error":' + __q(__e.toString()) + ',"line":' + (Number(__e.line) || 0) + '}';
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
// Script routes (osascript, COM, AfterFX.exe) read the result file. The CEP panel route passes
|
|
63
|
+
// null and takes the returned string instead, so the app never needs file-write permission.
|
|
64
|
+
if (__RESULT_PATH__ !== null) {
|
|
65
|
+
var __f = new File(__RESULT_PATH__);
|
|
66
|
+
__f.encoding = 'UTF-8';
|
|
67
|
+
__f.open('w');
|
|
68
|
+
__f.write(__payload);
|
|
69
|
+
__f.close();
|
|
70
|
+
}
|
|
71
|
+
return __payload;
|
|
67
72
|
})();
|
package/core/harness.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# adobe-mcp Python harness (Blender + Substance 3D Painter).
|
|
2
|
+
# Runs the user's code as a module body in a fresh namespace, captures stdout, and writes
|
|
3
|
+
# {ok, result, stdout} or {ok: false, error, line, traceback} as JSON to __RESULT_PATH__.
|
|
4
|
+
# Set `result = <value>` in user code to return data (non-JSON values are str()-ed).
|
|
5
|
+
def __adobe_mcp_run():
|
|
6
|
+
import base64, contextlib, io, json, traceback
|
|
7
|
+
|
|
8
|
+
code = base64.b64decode("__USER_CODE_B64__").decode("utf-8")
|
|
9
|
+
ns = {"__name__": "__adobe_mcp__"}
|
|
10
|
+
out = io.StringIO()
|
|
11
|
+
try:
|
|
12
|
+
with contextlib.redirect_stdout(out):
|
|
13
|
+
exec(compile(code, "<adobe-mcp>", "exec"), ns)
|
|
14
|
+
res = {"ok": True, "result": ns.get("result"), "stdout": out.getvalue()[-8000:]}
|
|
15
|
+
except BaseException as e: # SystemExit from user code must still report back
|
|
16
|
+
line = None
|
|
17
|
+
if isinstance(e, SyntaxError) and e.filename == "<adobe-mcp>":
|
|
18
|
+
line = e.lineno
|
|
19
|
+
for fr in traceback.extract_tb(e.__traceback__):
|
|
20
|
+
if fr.filename == "<adobe-mcp>":
|
|
21
|
+
line = fr.lineno
|
|
22
|
+
res = {
|
|
23
|
+
"ok": False,
|
|
24
|
+
"error": "%s: %s" % (type(e).__name__, e),
|
|
25
|
+
"line": line,
|
|
26
|
+
"traceback": traceback.format_exc()[-4000:],
|
|
27
|
+
"stdout": out.getvalue()[-4000:],
|
|
28
|
+
}
|
|
29
|
+
with open(__RESULT_PATH__, "w", encoding="utf-8") as f:
|
|
30
|
+
f.write(json.dumps(res, default=str))
|
|
31
|
+
return res
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__adobe_mcp_run()
|
package/core/helpers.mjs
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Shared helpers for the production tool set (ported from the Barrows/Derrin Byrne line of adobe-mcp,
|
|
2
|
+
// adapted to core/platform.mjs). CSV rows, safe names, ExtendScript literals, encoder presets,
|
|
3
|
+
// open-app detection and the Animate (JSFL) runner.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { IS_WIN, IS_MAC, adobeRoots, findAdobeInstallDirs, macAppName, runningProcesses, isAppRunning, run } from "./platform.mjs";
|
|
8
|
+
|
|
9
|
+
/** Embed a JS value in ExtendScript/JSFL source as a literal (JSON is a valid ES3 literal). */
|
|
10
|
+
export function lit(value) {
|
|
11
|
+
return JSON.stringify(value ?? null).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Forward-slash path for ExtendScript File() on every OS. */
|
|
15
|
+
export const esPath = (p) => String(p).replace(/\\/g, "/");
|
|
16
|
+
|
|
17
|
+
/** Minimal RFC-4180 CSV/TSV parser. Returns array of row objects keyed by header. */
|
|
18
|
+
export function parseCsv(textIn) {
|
|
19
|
+
let textData = textIn.replace(/^\uFEFF/, "");
|
|
20
|
+
const firstLine = textData.split(/\r?\n/, 1)[0] || "";
|
|
21
|
+
const delim = (firstLine.match(/\t/g) || []).length > (firstLine.match(/,/g) || []).length ? "\t" : ",";
|
|
22
|
+
const rows = [];
|
|
23
|
+
let row = [], field = "", q = false;
|
|
24
|
+
for (let i = 0; i < textData.length; i++) {
|
|
25
|
+
const c = textData[i];
|
|
26
|
+
if (q) {
|
|
27
|
+
if (c === '"' && textData[i + 1] === '"') { field += '"'; i++; }
|
|
28
|
+
else if (c === '"') q = false;
|
|
29
|
+
else field += c;
|
|
30
|
+
} else if (c === '"') q = true;
|
|
31
|
+
else if (c === delim) { row.push(field); field = ""; }
|
|
32
|
+
else if (c === "\n" || c === "\r") {
|
|
33
|
+
if (c === "\r" && textData[i + 1] === "\n") i++;
|
|
34
|
+
row.push(field); field = "";
|
|
35
|
+
if (row.some((f) => f !== "")) rows.push(row);
|
|
36
|
+
row = [];
|
|
37
|
+
} else field += c;
|
|
38
|
+
}
|
|
39
|
+
row.push(field);
|
|
40
|
+
if (row.some((f) => f !== "")) rows.push(row);
|
|
41
|
+
if (!rows.length) return [];
|
|
42
|
+
const header = rows[0].map((h) => h.trim());
|
|
43
|
+
return rows.slice(1).map((r) => Object.fromEntries(header.map((h, i) => [h, (r[i] ?? "").trim()])));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Rows from either an inline array or a CSV/TSV file path. */
|
|
47
|
+
export function loadRows({ rows, csv_path }) {
|
|
48
|
+
if (Array.isArray(rows) && rows.length) return rows;
|
|
49
|
+
if (csv_path) return parseCsv(fs.readFileSync(csv_path, "utf8"));
|
|
50
|
+
throw new Error("Provide rows (array of objects) or csv_path.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function safeName(s, fallback = "item") {
|
|
54
|
+
const out = String(s ?? "").replace(/[\\/:*?"<>|\u0000-\u001f]+/g, "_").replace(/\s+/g, " ").trim().slice(0, 120);
|
|
55
|
+
return out || fallback;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Walk a folder (depth-limited), return file paths. */
|
|
59
|
+
export function walk(dir, { maxDepth = 8, maxFiles = 50000, filter } = {}) {
|
|
60
|
+
const out = [];
|
|
61
|
+
const go = (d, depth) => {
|
|
62
|
+
if (depth > maxDepth || out.length >= maxFiles) return;
|
|
63
|
+
let entries = [];
|
|
64
|
+
try { entries = fs.readdirSync(d, { withFileTypes: true }); } catch { return; }
|
|
65
|
+
for (const e of entries) {
|
|
66
|
+
if (e.name.startsWith(".")) continue;
|
|
67
|
+
const full = path.join(d, e.name);
|
|
68
|
+
if (e.isDirectory()) go(full, depth + 1);
|
|
69
|
+
else if (!filter || filter(full)) out.push(full);
|
|
70
|
+
if (out.length >= maxFiles) return;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
go(dir, 0);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Find Adobe encoder presets (.epr) by name or path. Searches app folders + user preset folders. */
|
|
78
|
+
export function findEprPresets(query) {
|
|
79
|
+
if (query && /\.epr$/i.test(query) && fs.existsSync(query)) return [query];
|
|
80
|
+
const roots = [];
|
|
81
|
+
for (const root of adobeRoots()) {
|
|
82
|
+
try {
|
|
83
|
+
for (const d of fs.readdirSync(root)) if (/Premiere Pro|Media Encoder/i.test(d)) roots.push(path.join(root, d));
|
|
84
|
+
} catch { /* ignore */ }
|
|
85
|
+
}
|
|
86
|
+
const docs = path.join(os.homedir(), "Documents", "Adobe");
|
|
87
|
+
for (const sub of ["Adobe Media Encoder", "Premiere Pro"]) roots.push(path.join(docs, sub));
|
|
88
|
+
const all = [];
|
|
89
|
+
for (const r of roots) all.push(...walk(r, { maxDepth: 9, maxFiles: 20000, filter: (f) => /\.epr$/i.test(f) }));
|
|
90
|
+
if (!query) return all;
|
|
91
|
+
const q = query.toLowerCase().replace(/\.epr$/, "");
|
|
92
|
+
const exact = all.filter((f) => path.basename(f, ".epr").toLowerCase() === q);
|
|
93
|
+
return exact.length ? exact : all.filter((f) => path.basename(f).toLowerCase().includes(q));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function resolvePreset(query, fallbackTest) {
|
|
97
|
+
const found = findEprPresets(query);
|
|
98
|
+
if (query && found.length) return found[0];
|
|
99
|
+
if (query) {
|
|
100
|
+
const names = [...new Set(findEprPresets().map((f) => path.basename(f, ".epr")))].slice(0, 60);
|
|
101
|
+
throw new Error(`No encoder preset matching "${query}". Some available: ${names.join(", ") || "(none found — pass a full .epr path)"}`);
|
|
102
|
+
}
|
|
103
|
+
const fb = findEprPresets().find(fallbackTest || ((f) => /Match Source.*High bitrate/i.test(f)));
|
|
104
|
+
if (!fb) throw new Error("No encoder preset found — pass preset (a name or full .epr path).");
|
|
105
|
+
return fb;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Which Adobe apps are open right now ({ae: true, ps: false, ...}); all false if the process list can't be read. */
|
|
109
|
+
export async function runningApps() {
|
|
110
|
+
const procs = await runningProcesses();
|
|
111
|
+
const res = {};
|
|
112
|
+
for (const k of ["ae", "ps", "ai", "id", "ppro", "an", "ame"]) res[k] = !!(await isAppRunning(k, procs));
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Animate (JSFL). Animate has no AppleScript/COM entry point; it runs a .jsfl
|
|
118
|
+
// file handed to it on the command line, so results come back via a file.
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
const JSFL_HARNESS = `(function () {
|
|
121
|
+
function __q(s) { s = String(s); var o = '"'; for (var i = 0; i < s.length; i++) { var c = s.charAt(i), n = s.charCodeAt(i);
|
|
122
|
+
if (c == '"') o += '\\\\"'; else if (c == '\\\\') o += '\\\\\\\\'; else if (c == '\\n') o += '\\\\n'; else if (c == '\\r') o += '\\\\r';
|
|
123
|
+
else if (c == '\\t') o += '\\\\t'; else if (n < 32) o += ' '; else o += c; } return o + '"'; }
|
|
124
|
+
function __json(v, d) { d = d || 0; if (d > 8) return '"[max depth]"'; if (v === null || v === undefined) return 'null';
|
|
125
|
+
var t = typeof v; if (t == 'number') return isFinite(v) ? String(v) : 'null'; if (t == 'boolean') return String(v);
|
|
126
|
+
if (t == 'string') return __q(v); if (t == 'function') return '"[function]"';
|
|
127
|
+
if (v instanceof Array) { var a = []; for (var i = 0; i < v.length; i++) a.push(__json(v[i], d + 1)); return '[' + a.join(',') + ']'; }
|
|
128
|
+
var p = []; for (var k in v) { try { p.push(__q(k) + ':' + __json(v[k], d + 1)); } catch (e) {} } return '{' + p.join(',') + '}'; }
|
|
129
|
+
var __out;
|
|
130
|
+
try { var __r = (function () {
|
|
131
|
+
__USER_CODE__
|
|
132
|
+
})(); __out = '{"ok":true,"result":' + __json(__r) + '}'; }
|
|
133
|
+
catch (e) { __out = '{"ok":false,"error":' + __q(e) + ',"line":' + (Number(e.lineNumber) || 0) + '}'; }
|
|
134
|
+
FLfile.write(FLfile.platformPathToURI(__RESULT_PATH__), __out);
|
|
135
|
+
})();
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
/** Animate's launcher: Animate.exe on Windows, the .app bundle on macOS (null if not installed). */
|
|
139
|
+
export function animateLocation() {
|
|
140
|
+
if (IS_WIN) {
|
|
141
|
+
if (process.env.AN_EXE) return process.env.AN_EXE;
|
|
142
|
+
for (const d of findAdobeInstallDirs(/^Adobe Animate/i).reverse()) {
|
|
143
|
+
const exe = path.join(d, "Animate.exe");
|
|
144
|
+
if (fs.existsSync(exe)) return exe;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
if (!IS_MAC) return null;
|
|
149
|
+
if (process.env.AN_APP_PATH) return process.env.AN_APP_PATH;
|
|
150
|
+
const name = macAppName(/^Adobe Animate/i, null, "AN_APP_NAME");
|
|
151
|
+
if (!name) return null;
|
|
152
|
+
for (const p of [`/Applications/${name}/${name}.app`, `/Applications/${name}.app`]) if (fs.existsSync(p)) return p;
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
157
|
+
|
|
158
|
+
export async function runJSFL(userCode, timeoutMs = 120000) {
|
|
159
|
+
const stamp = `${Date.now()}_${Math.floor(Math.random() * 1e6)}`;
|
|
160
|
+
const resultPath = path.join(os.tmpdir(), `adobe_mcp_result_an_${stamp}.json`);
|
|
161
|
+
const scriptPath = path.join(os.tmpdir(), `adobe_mcp_script_an_${stamp}.jsfl`);
|
|
162
|
+
const loc = animateLocation();
|
|
163
|
+
if (!loc)
|
|
164
|
+
throw new Error(
|
|
165
|
+
IS_WIN
|
|
166
|
+
? "Could not find Animate.exe under Program Files\\Adobe. Set AN_EXE to its full path."
|
|
167
|
+
: IS_MAC
|
|
168
|
+
? "Could not find Adobe Animate in /Applications. Set AN_APP_PATH to the .app path."
|
|
169
|
+
: "Adobe Animate needs macOS or Windows."
|
|
170
|
+
);
|
|
171
|
+
// UTF-8 BOM so Animate reads non-ASCII paths and text correctly; the result path is ASCII-escaped too.
|
|
172
|
+
fs.writeFileSync(
|
|
173
|
+
scriptPath,
|
|
174
|
+
"\uFEFF" + JSFL_HARNESS.replace("__RESULT_PATH__", () => lit(resultPath).replace(/[\u007f-\uffff]/g, (c) => "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0"))).replace("__USER_CODE__", () => userCode),
|
|
175
|
+
"utf8"
|
|
176
|
+
);
|
|
177
|
+
const r = IS_WIN
|
|
178
|
+
? await run(loc, [scriptPath], { timeout: Math.min(timeoutMs, 60000) })
|
|
179
|
+
: await run("open", ["-a", loc, scriptPath], { timeout: 30000 });
|
|
180
|
+
if (!r.ok && !r.err?.killed) throw new Error(`Could not hand the script to Animate: ${(r.stderr || r.err?.message || "").trim()}`);
|
|
181
|
+
const deadline = Date.now() + timeoutMs;
|
|
182
|
+
while (Date.now() < deadline) {
|
|
183
|
+
if (fs.existsSync(resultPath)) {
|
|
184
|
+
const raw = fs.readFileSync(resultPath, "utf8");
|
|
185
|
+
if (raw.length) {
|
|
186
|
+
fs.rmSync(resultPath, { force: true });
|
|
187
|
+
fs.rmSync(scriptPath, { force: true });
|
|
188
|
+
const parsed = JSON.parse(raw);
|
|
189
|
+
if (!parsed.ok) throw new Error(`JSFL error${parsed.line ? ` (line ${parsed.line})` : ""}: ${parsed.error}`);
|
|
190
|
+
return parsed.result;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
await sleep(150);
|
|
194
|
+
}
|
|
195
|
+
throw new Error(`Animate did not return a result within ${timeoutMs / 1000}s. Is Animate open, with no dialog showing? Script kept: ${scriptPath}`);
|
|
196
|
+
}
|