M14.4: scripting with an After Effects-style JavaScript object model
New crate effectcraft-script (L4): boa runtime with app/Project/CompItem/ Layer/PropertyGroup/Property/TextDocument/MarkerValue/RenderQueue/File object model over engine commands (undoable, undo groups), AE match-name table, file/network security gate. Entry points: script.run command, File > Scripts > Run Script File (.jsx/.js), Window > Script Console, effectcraft-cli script, MCP run_script. Engine: project.delete/duplicate, prop.renameGroup/setGroupEnabled/removeGroup/duplicateGroup/moveGroup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e911cc5c93
commit
78cd313d3c
@@ -54,6 +54,7 @@ fn initialize_and_list_tools() {
|
||||
for want in [
|
||||
"list_commands",
|
||||
"execute_command",
|
||||
"run_script",
|
||||
"get_project",
|
||||
"get_comp",
|
||||
"get_layer",
|
||||
@@ -263,3 +264,30 @@ fn bridge_rejects_non_loopback() {
|
||||
assert!(Backend::bridge("10.0.0.1:9877").is_err());
|
||||
assert!(Backend::bridge("localhost:9877").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_script_round_trip() {
|
||||
let mut sess = Session::default();
|
||||
effectcraft_script::install(&mut sess);
|
||||
let mut s = McpServer::new(Backend::headless(sess));
|
||||
let r = call_json(
|
||||
&mut s,
|
||||
"run_script",
|
||||
json!({"code": "var c = app.project.items.addComp('Scripted', 320, 180, 1, 2, 24);\nc.layers.addText('Hi');\nwriteLn('made ' + c.name);\nc.numLayers"}),
|
||||
);
|
||||
assert_eq!(r["ok"], json!(true), "{r}");
|
||||
assert_eq!(r["result"], json!(1));
|
||||
assert_eq!(r["output"], json!("made Scripted"));
|
||||
// The edit is visible to the other tools.
|
||||
let p = call_json(&mut s, "get_project", json!({}));
|
||||
assert!(p.to_string().contains("Scripted"), "{p}");
|
||||
// Errors come back with their line.
|
||||
let r = call_json(&mut s, "run_script", json!({"code": "var a = 1;\nundefinedFn();", "name": "bad.jsx"}));
|
||||
assert_eq!(r["ok"], json!(false));
|
||||
assert_eq!(r["error"]["line"], json!(2));
|
||||
assert_eq!(r["error"]["file"], json!("bad.jsx"));
|
||||
// Without a scripting engine the command explains itself.
|
||||
let mut bare = server();
|
||||
let (c, err) = call(&mut bare, "run_script", json!({"code": "1"}));
|
||||
assert!(err && c[0]["text"].as_str().unwrap().contains("not available"), "{c:?}");
|
||||
}
|
||||
|
||||
@@ -140,6 +140,15 @@ fn execute_command(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
json_reply(b.exec(id, params)?)
|
||||
}
|
||||
|
||||
fn run_script(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
let code = get(a, "code").and_then(Value::as_str).ok_or_else(|| Error::BadArgs("missing `code` (JavaScript)".into()))?;
|
||||
let mut p = json!({"code": code});
|
||||
if let Some(n) = get(a, "name") {
|
||||
p["name"] = n.clone();
|
||||
}
|
||||
json_reply(b.exec("script.run", p)?)
|
||||
}
|
||||
|
||||
fn get_project(b: &mut Backend, _: &Value) -> Result<Reply> {
|
||||
json_reply(b.exec("project.summary", json!({}))?)
|
||||
}
|
||||
@@ -386,6 +395,21 @@ static TOOLS: &[ToolDef] = &[
|
||||
},
|
||||
run: execute_command,
|
||||
},
|
||||
ToolDef {
|
||||
name: "run_script",
|
||||
description: "Run JavaScript with an After Effects-style scripting object model (app, app.project, items.addComp, comp.layers.addSolid/addText/addShape/addNull/addCamera/addLight, layer.property(\"ADBE Transform Group\").property(\"ADBE Position\").setValueAtTime(t, v), Effects.addProperty(\"ADBE Gaussian Blur 2\"), expressions, markers, renderQueue…). Every edit is an undoable engine command; app.beginUndoGroup/endUndoGroup make one undo step. Returns {ok, result (last expression value), output (writeLn/$.writeln/alert text), error: {message, line, column} | null}. File access is limited to the project folder unless the user allows scripts to write files.",
|
||||
bridge_only: false,
|
||||
schema: || {
|
||||
schema(
|
||||
json!({
|
||||
"code": {"type": "string", "description": "JavaScript source, e.g. `var c = app.project.items.addComp(\"Main\", 1920, 1080, 1, 5, 30); c.layers.addText(\"Hi\"); c.numLayers`."},
|
||||
"name": {"type": "string", "description": "Script name used in error messages (default `script`)."}
|
||||
}),
|
||||
&["code"],
|
||||
)
|
||||
},
|
||||
run: run_script,
|
||||
},
|
||||
ToolDef {
|
||||
name: "get_project",
|
||||
description: "Project overview: file path, dirty flag, bit depth, every item (id, name, type Composition/Footage/Solid/Folder, size, duration, layer count), the active comp id, current time (s), selected layers and the undo stack.",
|
||||
|
||||
Reference in New Issue
Block a user