M13.14: agent-interface audit (every command over MCP, control channel and exec --list; automation ids for every widget)
- command.describe / list_commands {schemas} give each command's params JSON Schema;
MCP describe_command, add_effect, list_effects and get_state (app.capabilities)
- effectcraft-cli exec --list [--schemas]
- headless UI audit: every panel kind's interactive egui widgets are covered by
automation ids (fixed: timeline navigator, label swatch, bar trim edges, group and
property name cells)
- command lookup is indexed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5cf37921ef
commit
0d5f60c4b7
@@ -317,3 +317,58 @@ fn run_script_round_trip() {
|
||||
let (c, err) = call(&mut bare, "run_script", json!({"code": "1"}));
|
||||
assert!(err && c[0]["text"].as_str().unwrap().contains("not available"), "{c:?}");
|
||||
}
|
||||
|
||||
/// The agent-interface audit (MCP side): every registered engine command is listed by
|
||||
/// `list_commands` with a label, params doc and JSON Schema, described by `describe_command`,
|
||||
/// and routed by `execute_command` (an unknown parameter is rejected by that very command
|
||||
/// without running it).
|
||||
#[test]
|
||||
fn every_engine_command_is_reachable_over_mcp() {
|
||||
let mut s = server();
|
||||
let tools = rpc(&mut s, 1, "tools/list", json!({}))["tools"].as_array().unwrap().clone();
|
||||
let names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect();
|
||||
for want in ["list_commands", "describe_command", "execute_command", "add_effect", "list_effects", "get_state", "render_frame", "get_layer", "set_property"]
|
||||
{
|
||||
assert!(names.contains(&want), "{want}");
|
||||
}
|
||||
let listed = call_json(&mut s, "list_commands", json!({"schemas": true}));
|
||||
let listed: std::collections::HashMap<&str, &Value> = listed.as_array().unwrap().iter().map(|c| (c["id"].as_str().unwrap(), c)).collect();
|
||||
let specs = effectcraft_engine::command_specs();
|
||||
assert_eq!(listed.len(), specs.len());
|
||||
for spec in specs {
|
||||
let c = listed.get(spec.id).unwrap_or_else(|| panic!("{} not listed", spec.id));
|
||||
assert!(!spec.label.trim().is_empty(), "{}: no label", spec.id);
|
||||
assert!(spec.params.trim_start().starts_with('{'), "{}: params doc {:?}", spec.id, spec.params);
|
||||
assert_eq!(c["schema"]["type"], "object", "{}", spec.id);
|
||||
assert!(c["schema"]["properties"].is_object(), "{}", spec.id);
|
||||
let d = call_json(&mut s, "describe_command", json!({"command": spec.id}));
|
||||
assert_eq!(d["schema"], c["schema"], "{}", spec.id);
|
||||
let (content, err) = call(&mut s, "execute_command", json!({"command": spec.id, "params": {"__audit": 1}}));
|
||||
let text = content[0]["text"].as_str().unwrap_or_default();
|
||||
assert!(err && text.contains("unknown parameter") && text.contains(spec.id), "{}: {text}", spec.id);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn high_level_tools_add_effect_and_report_state() {
|
||||
let mut s = server();
|
||||
call_json(&mut s, "execute_command", json!({"command": "comp.new", "params": {"name": "A", "width": 64, "height": 48, "duration": 1}}));
|
||||
let l = call_json(&mut s, "execute_command", json!({"command": "layer.newSolid", "params": {"color": "#808080"}}))["layer"].clone();
|
||||
let fx = call_json(&mut s, "list_effects", json!({"filter": "gaussian"}));
|
||||
assert!(fx.as_array().unwrap().iter().any(|e| e["id"] == "ec.blur.gaussian" && e["gpu"].is_boolean()), "{fx}");
|
||||
let r = call_json(&mut s, "add_effect", json!({"layer": l, "effect": "Gaussian Blur", "values": {"blurriness": 7}}));
|
||||
assert_eq!(r["path"], "effects/#1", "{r}");
|
||||
assert!(r["params"].as_array().unwrap().iter().any(|p| p["path"] == "effects/#1/blurriness" && p["value"] == 7.0), "{r}");
|
||||
// A second effect lands at #2.
|
||||
let r = call_json(&mut s, "add_effect", json!({"layer": l, "effect": "ec.color.levels"}));
|
||||
assert_eq!(r["path"], "effects/#2", "{r}");
|
||||
let p = call_json(&mut s, "get_property", json!({"layer": l, "path": "effects/#1/blurriness"}));
|
||||
assert_eq!(p["value"], 7.0, "{p}");
|
||||
let st = call_json(&mut s, "get_state", json!({}));
|
||||
assert!(st["state"].is_object() && st["app"]["commands"].as_u64().unwrap() > 500, "{st}");
|
||||
assert!(st["app"]["effects"]["total"].as_u64().unwrap() > 200, "{st}");
|
||||
assert!(st["app"]["parity"]["summary"].as_str().unwrap().contains("parity"), "{st}");
|
||||
// Unknown effects fail cleanly.
|
||||
let (c, err) = call(&mut s, "add_effect", json!({"layer": l, "effect": "No Such Effect"}));
|
||||
assert!(err && c[0]["text"].as_str().unwrap().contains("unknown effect"), "{c:?}");
|
||||
}
|
||||
|
||||
@@ -117,7 +117,8 @@ fn params_of(v: Option<&Value>) -> Result<Value> {
|
||||
// ------------------------------------------------------------------ engine tools
|
||||
|
||||
fn list_commands(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
let r = b.exec("command.list", obj(&[("filter", get(a, "filter")), ("enabledOnly", get(a, "enabled_only"))]))?;
|
||||
let schemas = get(a, "schemas").and_then(Value::as_bool).unwrap_or(false).then_some(json!(true));
|
||||
let r = b.exec("command.list", obj(&[("filter", get(a, "filter")), ("enabledOnly", get(a, "enabled_only")), ("schemas", schemas.as_ref())]))?;
|
||||
// Drop empty fields to keep the listing compact.
|
||||
let list: Vec<Value> = r
|
||||
.as_array()
|
||||
@@ -140,6 +141,53 @@ fn execute_command(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
json_reply(b.exec(id, params)?)
|
||||
}
|
||||
|
||||
fn describe_command(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
let id = get(a, "command").or(get(a, "id")).and_then(Value::as_str).ok_or_else(|| Error::BadArgs("missing `command` (e.g. `layer.newText`)".into()))?;
|
||||
json_reply(b.exec("command.describe", json!({"command": id}))?)
|
||||
}
|
||||
|
||||
fn list_effects(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
json_reply(b.exec("effect.list", obj(&[("filter", get(a, "filter"))]))?)
|
||||
}
|
||||
|
||||
/// `effect.apply` on one layer, then set parameters on the new instance by param id.
|
||||
fn add_effect(b: &mut Backend, a: &Value) -> Result<Reply> {
|
||||
let (layer, effect, comp) = (need(a, "layer")?, need(a, "effect")?, get(a, "comp"));
|
||||
let count = |t: &Value| effects_group(t).and_then(|g| g.get("children")).and_then(Value::as_array).map_or(0, Vec::len);
|
||||
let before = b.exec("layer.tree", obj(&[("layer", Some(layer)), ("comp", comp)]))?;
|
||||
let index = count(&before) + 1;
|
||||
let mut p = obj(&[("effect", Some(effect)), ("comp", comp)]);
|
||||
p["layers"] = json!([layer]);
|
||||
b.exec("effect.apply", p)?;
|
||||
let prefix = format!("effects/#{index}");
|
||||
let mut set = vec![];
|
||||
if let Some(vals) = get(a, "values").and_then(Value::as_object) {
|
||||
for (k, v) in vals {
|
||||
let path = format!("{prefix}/{k}");
|
||||
b.exec("prop.set", obj(&[("layer", Some(layer)), ("comp", comp), ("path", Some(&json!(path))), ("value", Some(v))]))?;
|
||||
set.push(path);
|
||||
}
|
||||
}
|
||||
let tree = b.exec("layer.tree", obj(&[("layer", Some(layer)), ("comp", comp)]))?;
|
||||
let inst = effects_group(&tree).and_then(|g| g.get("children")).and_then(Value::as_array).and_then(|c| c.get(index - 1)).cloned();
|
||||
let mut params = vec![];
|
||||
if let Some(i) = &inst {
|
||||
flatten(i, &mut params);
|
||||
}
|
||||
json_reply(json!({"layer": tree["id"], "index": index, "path": prefix, "name": inst.as_ref().map(|i| i["name"].clone()), "set": set, "params": params}))
|
||||
}
|
||||
|
||||
/// The `effects` group of a `layer.tree` reply.
|
||||
fn effects_group(tree: &Value) -> Option<&Value> {
|
||||
tree["properties"]["children"].as_array()?.iter().find(|c| c["path"] == "effects")
|
||||
}
|
||||
|
||||
fn get_state(b: &mut Backend, _: &Value) -> Result<Reply> {
|
||||
let state = b.exec("editor.state", json!({}))?;
|
||||
let caps = b.exec("app.capabilities", json!({}))?;
|
||||
json_reply(json!({"state": state, "app": caps}))
|
||||
}
|
||||
|
||||
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});
|
||||
@@ -399,13 +447,21 @@ static TOOLS: &[ToolDef] = &[
|
||||
schema(
|
||||
json!({
|
||||
"filter": {"type": "string", "description": "Only commands whose id or label contains this text (case-insensitive)."},
|
||||
"enabled_only": {"type": "boolean", "description": "Only commands that can run right now."}
|
||||
"enabled_only": {"type": "boolean", "description": "Only commands that can run right now."},
|
||||
"schemas": {"type": "boolean", "description": "Also return each command's parameter JSON Schema (`schema`)."}
|
||||
}),
|
||||
&[],
|
||||
)
|
||||
},
|
||||
run: list_commands,
|
||||
},
|
||||
ToolDef {
|
||||
name: "describe_command",
|
||||
description: "One command in full: id, label, menu path, shortcut, the `params` doc, a JSON Schema of its parameters (`schema`: properties, required, additionalProperties) and whether it can run now (`why` if not). Use before execute_command when unsure of the parameters; execute_command rejects unknown keys.",
|
||||
bridge_only: false,
|
||||
schema: || schema(json!({"command": {"type": "string", "description": "Command id, e.g. `layer.newText`."}}), &["command"]),
|
||||
run: describe_command,
|
||||
},
|
||||
ToolDef {
|
||||
name: "execute_command",
|
||||
description: "Run any engine command by id with JSON params; edits are undoable. Examples: comp.new {\"name\":\"Main\",\"width\":1920,\"height\":1080,\"frameRate\":30,\"duration\":5}; layer.newText {\"text\":\"Hello\",\"size\":120,\"fill\":\"#ffffff\"} (returns {\"layer\":id}); layer.newSolid {\"color\":\"#3366ff\"}; layer.newShape; effect.apply {\"layer\":3,\"effect\":\"Gaussian Blur\"}; time.set {\"time\":2.5}; layer.select {\"layers\":[3]}. Layers are referenced by id, \"#n\" or name; times are seconds.",
|
||||
@@ -513,6 +569,36 @@ static TOOLS: &[ToolDef] = &[
|
||||
},
|
||||
run: add_keyframe,
|
||||
},
|
||||
ToolDef {
|
||||
name: "add_effect",
|
||||
description: "Apply an effect to a layer and optionally set its parameters in one undoable call. `effect` is an id (`ec.blur.gaussian`) or After Effects name (`Gaussian Blur`; see list_effects); `values` maps parameter ids to values, e.g. {\"blurriness\": 12}. Returns the instance `path` (`effects/#n`, for set_property / add_keyframe) and its parameters with their paths and current values.",
|
||||
bridge_only: false,
|
||||
schema: || {
|
||||
schema(
|
||||
json!({
|
||||
"layer": layer_s(), "comp": comp_s(),
|
||||
"effect": {"type": "string", "description": "Effect id or name, e.g. `Gaussian Blur`, `Glow`, `Curves`, `ec.color.levels`."},
|
||||
"values": {"type": "object", "description": "Parameter id -> value (ids are in the returned `params` paths), e.g. {\"blurriness\": 12}.", "additionalProperties": true}
|
||||
}),
|
||||
&["layer", "effect"],
|
||||
)
|
||||
},
|
||||
run: add_effect,
|
||||
},
|
||||
ToolDef {
|
||||
name: "list_effects",
|
||||
description: "The effect registry: id, After Effects name, category, GPU and 32-bpc support. Narrow with `filter` (id, name or category text). Apply with add_effect.",
|
||||
bridge_only: false,
|
||||
schema: || schema(json!({"filter": {"type": "string", "description": "Only effects whose id, name or category contains this text."}}), &[]),
|
||||
run: list_effects,
|
||||
},
|
||||
ToolDef {
|
||||
name: "get_state",
|
||||
description: "Where things stand: the editor state (active comp, current time, selected layers/keys/items, open comps, tool, work area) plus what this build can do (`app`: version, command and effect counts, GPU effects, import/export formats, After Effects parity summary). Cheap; call it to re-orient after a series of edits.",
|
||||
bridge_only: false,
|
||||
schema: || schema(json!({}), &[]),
|
||||
run: get_state,
|
||||
},
|
||||
ToolDef {
|
||||
name: "render_frame",
|
||||
description: "Render a composition frame (default: the active comp at the current time) and return it as a PNG image, longest side `max_side` (default 960, 0 = full size). `path` also writes the PNG to disk; `inline: false` returns only the metadata. Use it to check your work.",
|
||||
|
||||
Reference in New Issue
Block a user