mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-05 16:31:19 -05:00
feat(automation): a project an agent opens in the window reads footage only in the agent folders
Closes the window's one gap against headless agent sessions (#4387): while an agent's request or queued input runs, a project it opens wraps the session's footage source in the agent folders' ConfinedFootage. The next project the person opens reads footage as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -199,10 +199,12 @@ fn agent_scope(folders: &craft_control::agents::AgentFolders) -> Result<effectcr
|
||||
let confinement = effectcraft_automation::agents::confinement_for(folders).map_err(|e| e.to_string())?;
|
||||
let answer = effectcraft_automation::agents::folders_answer(Some(&confinement));
|
||||
let check = confinement.clone();
|
||||
let reads = confinement.clone();
|
||||
Ok(effectcraft_ui_egui::control::AgentScope {
|
||||
gate: confinement.gate(),
|
||||
check_write: Box::new(move |path| check.check(path, Access::Write).map(drop).map_err(|e| e.to_string())),
|
||||
folders: answer,
|
||||
footage: std::sync::Arc::new(move |inner| std::sync::Arc::new(effectcraft_automation::confine::ConfinedFootage::new(inner, reads.clone()))),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -301,8 +301,18 @@ pub struct Session {
|
||||
/// Checks each command before it runs while set ([`Session::execute`]): the desktop app sets it
|
||||
/// while it runs an agent's request, so the agent stays inside its agent folders.
|
||||
pub command_gate: Option<CommandGate>,
|
||||
/// Set with the [`Session::command_gate`] while an agent's request or input runs (it stays set
|
||||
/// while the gate is taken for the command itself): a project opened then
|
||||
/// reads its footage through this wrapper (the agent folders), as a headless agent session does
|
||||
/// (#4387). The person's next project reads through [`Session::footage`] as before.
|
||||
pub agent_footage: Option<FootageWrap>,
|
||||
/// The footage source from before an agent's project wrapped it ([`Session::agent_footage`]).
|
||||
pub unconfined_footage: Option<Arc<dyn FootageSource>>,
|
||||
}
|
||||
|
||||
/// Wraps the session's footage source for a project an agent opened ([`Session::agent_footage`]).
|
||||
pub type FootageWrap = Arc<dyn Fn(Arc<dyn FootageSource>) -> Arc<dyn FootageSource> + Send + Sync>;
|
||||
|
||||
/// A check run before a command (id, params), with the session to look things up in: `Err` refuses
|
||||
/// the command with that reason. While it runs, the session has no gate, so the commands it runs
|
||||
/// to look things up aren't checked again.
|
||||
@@ -440,6 +450,8 @@ impl Default for Session {
|
||||
script_calls: ScriptCalls::default(),
|
||||
output_guards: Default::default(),
|
||||
command_gate: None,
|
||||
agent_footage: None,
|
||||
unconfined_footage: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +232,15 @@ impl Session {
|
||||
}
|
||||
self.drop_crypto_probe();
|
||||
self.layer_cache.clear();
|
||||
// A project an agent opens reads its footage only inside the agent folders; the next one
|
||||
// the person opens reads it as before.
|
||||
if let Some(own) = self.unconfined_footage.take() {
|
||||
self.footage = own;
|
||||
}
|
||||
if let Some(wrap) = self.agent_footage.clone() {
|
||||
self.unconfined_footage = Some(self.footage.clone());
|
||||
self.footage = wrap(self.footage.clone());
|
||||
}
|
||||
self.project = Arc::new(p);
|
||||
// The set of footage effects read the channels of is sent again, even when it is empty.
|
||||
self.aux_footage = None;
|
||||
|
||||
@@ -171,7 +171,7 @@ mod tests {
|
||||
|
||||
fn scope(_: &AgentFolders) -> Result<AgentScope, String> {
|
||||
let gate: effectcraft_engine::CommandGate = Arc::new(|_: &mut effectcraft_engine::Session, _: &str, _: &Value| Ok(()));
|
||||
Ok(AgentScope { gate, check_write: Box::new(|_| Ok(())), folders: json!({}) })
|
||||
Ok(AgentScope { gate, check_write: Box::new(|_| Ok(())), folders: json!({}), footage: Arc::new(|f| f) })
|
||||
}
|
||||
|
||||
fn agents(dir: &std::path::Path, switch: AgentSwitch) -> Agents {
|
||||
|
||||
@@ -65,13 +65,17 @@ impl EffectcraftApp {
|
||||
// pass has applied it (`agent_input`).
|
||||
let queued = self.synthetic.len();
|
||||
let gate = req.agent.as_ref().map(|scope| scope.gate.clone());
|
||||
let footage = req.agent.as_ref().map(|scope| scope.footage.clone());
|
||||
// The person's own channel (`--control`) isn't confined, even while an agent's input waits.
|
||||
let outer = std::mem::replace(&mut self.session.command_gate, gate.clone());
|
||||
let outer = (std::mem::replace(&mut self.session.command_gate, gate.clone()), std::mem::replace(&mut self.session.agent_footage, footage.clone()));
|
||||
let outcome = control::handle(self, ctx, &req, now);
|
||||
self.session.command_gate = outer;
|
||||
if gate.is_some() && self.synthetic.len() > queued {
|
||||
self.agent_input = gate;
|
||||
self.session.command_gate = self.agent_input.clone();
|
||||
(self.session.command_gate, self.session.agent_footage) = outer;
|
||||
if let Some(gate) = gate
|
||||
&& self.synthetic.len() > queued
|
||||
{
|
||||
self.session.command_gate = Some(gate.clone());
|
||||
self.session.agent_footage = footage.clone();
|
||||
self.agent_input = Some((gate, footage));
|
||||
}
|
||||
match outcome {
|
||||
control::Outcome::Done(v) => {
|
||||
@@ -499,6 +503,7 @@ impl EffectcraftApp {
|
||||
// The agent's input has all been applied: what runs next is the person's again.
|
||||
if self.synthetic.is_empty() && self.agent_input.take().is_some() {
|
||||
self.session.command_gate = None;
|
||||
self.session.agent_footage = None;
|
||||
}
|
||||
// `AfterInput` replies wait for the final (non-discarded) pass that applied the last
|
||||
// synthetic event: a hidden request is answered only after its forced pass, and a pass
|
||||
|
||||
@@ -71,6 +71,8 @@ pub struct AgentScope {
|
||||
pub check_write: Box<dyn Fn(&str) -> Result<(), String> + Send + Sync>,
|
||||
/// The `agent_folders` answer: the folders the requests may use.
|
||||
pub folders: Value,
|
||||
/// The footage a project they open reads: only inside the agent folders (#4387).
|
||||
pub footage: effectcraft_engine::FootageWrap,
|
||||
}
|
||||
|
||||
impl ControlRequest {
|
||||
|
||||
@@ -390,9 +390,9 @@ pub struct EffectcraftApp {
|
||||
/// Agents in the open window through the ArtCraft Launcher's switch ([`agents::Agents`]).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) agents: Option<agents::Agents>,
|
||||
/// The gate of the agent whose queued input is still being applied: the commands that input
|
||||
/// runs are the agent's, and stay inside its agent folders.
|
||||
pub(crate) agent_input: Option<effectcraft_engine::CommandGate>,
|
||||
/// The gate and footage wrapper of the agent whose queued input is still being applied: the
|
||||
/// commands that input runs are the agent's, and stay inside its agent folders.
|
||||
pub(crate) agent_input: Option<(effectcraft_engine::CommandGate, Option<effectcraft_engine::FootageWrap>)>,
|
||||
pub(crate) deferred: Vec<(ControlRequest, f64)>,
|
||||
/// Requests a tick left to the next one when it ran out of [`EffectcraftApp::control_budget`],
|
||||
/// in the order they came, with their retry deadline once they ran (#3328).
|
||||
|
||||
@@ -718,7 +718,7 @@ fn agent_scope(root: &std::path::Path) -> Arc<control::AgentScope> {
|
||||
let gate_inside = inside.clone();
|
||||
let gate: effectcraft_engine::CommandGate =
|
||||
Arc::new(move |_: &mut Session, _: &str, params: &serde_json::Value| params.get("path").and_then(|p| p.as_str()).map_or(Ok(()), &gate_inside));
|
||||
Arc::new(control::AgentScope { gate, check_write: Box::new(inside), folders: json!({"write_folder": root}) })
|
||||
Arc::new(control::AgentScope { gate, check_write: Box::new(inside), folders: json!({"write_folder": root}), footage: Arc::new(|f| f) })
|
||||
}
|
||||
|
||||
/// Queues an agent's request with `scope`; its reply.
|
||||
@@ -735,6 +735,34 @@ fn send_agent(
|
||||
reply
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_project_an_agent_opens_reads_footage_through_its_folders_and_the_persons_next_does_not() {
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let own = app.session.footage.clone();
|
||||
let agent_dir = tempfile::tempdir().unwrap();
|
||||
let project = agent_dir.path().canonicalize().unwrap().join("agent.ecproj");
|
||||
app.session.execute("file.saveAs", json!({"path": project.to_string_lossy()})).unwrap();
|
||||
// The agent's footage source stands in for the desktop app's `ConfinedFootage`.
|
||||
let confined: Arc<dyn effectcraft_engine::render::FootageSource> = Arc::new(effectcraft_engine::render::NoFootage);
|
||||
let wrapped = confined.clone();
|
||||
let mut scope = Arc::into_inner(agent_scope(agent_dir.path())).unwrap();
|
||||
scope.footage = Arc::new(move |_| wrapped.clone());
|
||||
let scope = Arc::new(scope);
|
||||
let open = json!({"command": "file.open", "params": {"path": project.to_string_lossy()}});
|
||||
let reply = send_agent(&mut app, &scope, "engine.execute", open.clone());
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert_eq!(reply.try_recv().unwrap()["ok"], true);
|
||||
assert!(Arc::ptr_eq(&app.session.footage, &confined), "the agent's project reads footage outside its folders");
|
||||
assert!(app.session.agent_footage.is_none(), "the agent's footage wrapper outlived its request");
|
||||
// The person opens a project: its footage is read as before.
|
||||
let reply = send(&mut app, "engine.execute", open);
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert_eq!(reply.try_recv().unwrap()["ok"], true);
|
||||
assert!(Arc::ptr_eq(&app.session.footage, &own), "the person's project reads footage through the agent's folders");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_agents_request_stays_inside_its_agent_folders() {
|
||||
let ctx = headless();
|
||||
|
||||
+4
-3
@@ -46,13 +46,14 @@ switch names EffectCraft (behind the suite's `AI-MCP` flag):
|
||||
never uses the window. So do `--autosave` and the project options (`--project`, `--demo`,
|
||||
`--empty`).
|
||||
- **Agent folders.** Agent requests open files only from the agent folders and save only into
|
||||
them, in the window too (one exception: in the window, footage that a project opened from the agent
|
||||
folder already names is read wherever it is; #4387): the Automation Read and Write Folders on the Agents page, or
|
||||
them, in the window too: the Automation Read and Write Folders on the Agents page, or
|
||||
`Documents/ArtCraft/Agents/EffectCraft` (created when first used) when they are empty. The checks
|
||||
are the same as for `--automation-read-root` / `--automation-write-root` (see
|
||||
[MCP conventions](mcp.md#confining-file-access)). They cover each command an agent runs, and the
|
||||
commands its queued keys and clicks run until they have been applied. A screenshot or frame
|
||||
without a file comes back inline. A folder that can't be used means no file access, never
|
||||
without a file comes back inline. A project an agent opens reads its footage only inside the
|
||||
agent folders, as a headless session does: footage outside them shows as missing until the person
|
||||
opens a project themselves. A folder that can't be used means no file access, never
|
||||
unrestricted access, and the Agents page says why. The `agent_folders` tool names the folders the
|
||||
session really uses. Agents can't change the agent settings; only the person can.
|
||||
`--automation-read-root` / `--automation-write-root` on plain `mcp` bind calls to the window too:
|
||||
|
||||
Reference in New Issue
Block a user