From 53365705f5b4b61f32bea21a2063b19f598e6cdf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 09:27:04 -0800 Subject: [PATCH 1/2] Agents: a headless agent session with no usable agent folder gets no file access When VectorCraft is closed and the closed-app choice is a headless session, the session is confined to the agent folders. If no folder is set and the default one can't be made, the shared router passes no folders, and the session started with no automation roots, so its file commands could open and save anywhere the user can. It now gets roots that grant nothing. The decision uses the router's own consent result from the same lookup, so the ordinary headless fallback (agents off, or Allow Agent Control off) keeps the command line's folders as before. docs/mcp.md says what such a session can do. --- crates/mcp/src/agents.rs | 15 +++++++++++++-- crates/mcp/src/tests/agents.rs | 25 +++++++++++++++++++++++++ docs/mcp.md | 3 ++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/mcp/src/agents.rs b/crates/mcp/src/agents.rs index 8f7a8bc8b4..8fdc5ca5d5 100644 --- a/crates/mcp/src/agents.rs +++ b/crates/mcp/src/agents.rs @@ -18,6 +18,7 @@ use std::io::{BufRead, BufReader, ErrorKind, Read, Write}; use std::net::{SocketAddr, TcpStream}; use std::path::{Path, PathBuf}; use std::rc::Rc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex, PoisonError}; use std::time::{Duration, Instant}; @@ -284,7 +285,15 @@ impl LiveBackend { pub fn new(cfg: LiveConfig) -> Self { let LiveConfig { config_dir, read_settings, when_closed, read_roots, write_root, launch, launch_timeout, allowed, default_folder, headless } = cfg; - let consent = move |dir: &Path| Consent::new(allowed(), read_settings(dir)); + // The router's own decision on the last lookup (it asks for consent, then makes the + // headless session, under one lock), so the session's file access follows that decision. + let agents_in = Arc::new(AtomicBool::new(false)); + let decided = Arc::clone(&agents_in); + let consent = move |dir: &Path| { + let consent = Consent::new(allowed(), read_settings(dir)); + decided.store(consent.allowed && consent.settings.allow_agent_control, Ordering::SeqCst); + consent + }; let connect = |w: &shared::Window| -> Result { let mut window = Window::new(w.port, w.token.clone()); window.connect()?; @@ -292,7 +301,9 @@ impl LiveBackend { }; let make_headless = move |wanted: &HeadlessFolders| -> Result { let roots = if wanted.read.is_empty() && wanted.write.is_none() { - None + // Agents the person let in are confined to the agent folders: when none can be + // used (the default one can't be made), the session gets no file access. + if agents_in.load(Ordering::SeqCst) { Some(AutomationRoots::none()) } else { None } } else { let read: Vec<&Path> = wanted.read.iter().map(PathBuf::as_path).collect(); let write: Vec<&Path> = wanted.write.as_deref().into_iter().collect(); diff --git a/crates/mcp/src/tests/agents.rs b/crates/mcp/src/tests/agents.rs index 4be7aa0e05..5a9c7a774e 100644 --- a/crates/mcp/src/tests/agents.rs +++ b/crates/mcp/src/tests/agents.rs @@ -151,6 +151,31 @@ fn a_connection_file_with_nothing_listening_follows_the_closed_app_choice() { assert!(e.contains("outside the read root"), "{e}"); } +// The agent folder can't be made (its parent is a file): the headless session the person chose for +// a closed app gets no file access, rather than access to everything. +#[test] +fn a_headless_agent_session_without_usable_folders_reads_and_writes_nothing() { + let dir = TempFolder::new("agents-no-folder"); + std::fs::write(dir.file("blocker"), b"").unwrap(); + let mut b = live(&dir, || true, settings_headless, dir.file("blocker").join("Agents")); + assert!(!b.has_ui()); + let folders = b.call(FOLDERS_METHOD, json!({})).unwrap(); + assert_ne!(folders["unrestricted"], true, "{folders}"); + let outside = dir.file("outside.svg"); + std::fs::write(&outside, r#""#).unwrap(); + let e = b.call("app.open", json!({"path": outside.to_string_lossy()})).unwrap_err(); + assert!(e.contains("read authority is absent"), "{e}"); + + // With Allow Agent Control off, the session is the ordinary headless fallback, as before. + fn control_off(dir: &Path) -> AgentSettings { + let mut s = settings_headless(dir); + s.allow_agent_control = false; + s + } + let mut b = live(&dir, || true, control_off, dir.file("blocker").join("Agents")); + assert_eq!(b.call(FOLDERS_METHOD, json!({})).unwrap()["unrestricted"], true); +} + /// A canonical path as the automation roots show it: without Windows' `\\?\` prefix. fn shown(p: PathBuf) -> String { let s = p.to_string_lossy().into_owned(); diff --git a/docs/mcp.md b/docs/mcp.md index 8b91d156aa..a48c11edcb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -42,7 +42,8 @@ does: open VectorCraft and wait for it (the default), run the call in a session the agent folders, or answer with an error that asks to open VectorCraft. `--when-closed launch|headless|error` overrides the choice for one server. A session that went headless stays headless, so documents don't move under the agent. While agents may not use VectorCraft, plain `mcp` runs headless with -only the folders given on its command line, as before. +only the folders given on its command line, as before. If no agent folder is set and the default folder cannot +be created, a headless agent session has no file access. Its `agent_folders` response lists no folders. Preferences › AI Integrations shows the switch's state, the port agents connect on, Control Port (0: any free port), the two folders and the closed-app choice. Without the `AI-MCP` flag it only says that agents use From 991925227b62dd8dd447b40c9efd59bd0a830754 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 10:07:24 -0800 Subject: [PATCH 2/2] Tests: a headless agent session without folders also refuses a save The test for a headless agent session with no usable agent folder now also saves to a path outside the agent folders, checks that the error names the missing write authority, and checks that no file was written. --- crates/mcp/src/tests/agents.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/mcp/src/tests/agents.rs b/crates/mcp/src/tests/agents.rs index 5a9c7a774e..0453cd552f 100644 --- a/crates/mcp/src/tests/agents.rs +++ b/crates/mcp/src/tests/agents.rs @@ -165,6 +165,10 @@ fn a_headless_agent_session_without_usable_folders_reads_and_writes_nothing() { std::fs::write(&outside, r#""#).unwrap(); let e = b.call("app.open", json!({"path": outside.to_string_lossy()})).unwrap_err(); assert!(e.contains("read authority is absent"), "{e}"); + let saved = dir.file("saved.svg"); + let e = b.call("app.save", json!({"path": saved.to_string_lossy()})).unwrap_err(); + assert!(e.contains("write authority is absent"), "{e}"); + assert!(!saved.exists(), "the refused save must not write the file"); // With Allow Agent Control off, the session is the ordinary headless fallback, as before. fn control_off(dir: &Path) -> AgentSettings {