Agents: control clients can't change the agent settings

A window started with --control and no automation roots answers its
control requests unconfined, so `prefs.agents` saved any readRoot,
writeRoot or controlPort such a client sent. The agent folders it
widened then held for every later agent session.

`prefs.agents` now refuses a change whenever automation sent the
request (a control or MCP request, or a pass that carries injected
input), as `automation_is_acting` already does for commands that open
another app. Reading the settings still works. The params text, its
MCP mirror and docs/mcp.md say so.
This commit is contained in:
dotCooCoo committed 2026-12-04 11:11:17 -08:00
1 parent d742a49341
commit 9251d4a129
5 files changed
+31 -5

No files matched your search

+1 -1
View File
@@ -175,7 +175,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"prefs.agents",
"AI Integrations",
"",
"{controlPort?: 0–65535, readRoot?: string, writeRoot?: string, whenAppClosed?: launch|headless|error} the agent settings of Preferences › AI Integrations (agents in the open window through the ArtCraft Launcher's switch); given keys are saved where vectorcraft-cli mcp reads them, refused from an agent's request → {settings, status: {port, launchFlags, error}, allowed, mcpFlag}; an error in the web build and in a run without preferences",
"{controlPort?: 0–65535, readRoot?: string, writeRoot?: string, whenAppClosed?: launch|headless|error} the agent settings of Preferences › AI Integrations (agents in the open window through the ArtCraft Launcher's switch); given keys are saved where vectorcraft-cli mcp reads them, refused from an agent's or a control client's request → {settings, status: {port, launchFlags, error}, allowed, mcpFlag}; an error in the web build and in a run without preferences",
),
("edit.keyboardShortcuts", "Keyboard Shortcuts…", "Cmd+Alt+Shift+K", "{}"),
(
+4 -2
View File
@@ -147,8 +147,10 @@ const KEYS: [&str; 4] = ["controlPort", "readRoot", "writeRoot", "whenAppClosed"
/// `prefs.agents`: the agent settings of Preferences › AI Integrations, the link's status and the
/// launcher's switch. `{controlPort?, readRoot?, writeRoot?, whenAppClosed?}` changes and saves those
/// settings first. Agents can't change them: their requests run confined to the agent folders, and
/// widening those is the person's choice.
/// widening those is the person's choice. A control client started without automation roots can't
/// change them either.
pub(crate) fn command(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
let automated = app.automation_is_acting() || file_access::current().is_some();
let Some(agents) = app.agents.as_mut() else {
return Err("agents can't use this window: it keeps no preferences (VECTORCRAFT_NO_PREFS), or it is a nightly".into());
};
@@ -157,7 +159,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, p: &Value) -> Result<Value, Stri
if let Some(unknown) = given.keys().find(|k| !KEYS.contains(&k.as_str())) {
return Err(format!("unknown agent setting `{unknown}` ({})", KEYS.join(", ")));
}
if file_access::current().is_some() {
if automated {
return Err("agents can't change the agent settings: the person sets them in Preferences › AI Integrations".into());
}
let mut next = serde_json::to_value(agents.settings()).map_err(|e| e.to_string())?;
+24
View File
@@ -133,3 +133,27 @@ fn prefs_agents_saves_and_agents_cannot_change_it() {
assert!(file_access::confine(Some(&roots), || app.run("prefs.agents", json!({}))).is_ok());
let _ = std::fs::remove_dir_all(&base);
}
// A control client started without automation roots runs unconfined, and it still can't change the
// agent settings: only the person sets them.
#[test]
fn prefs_agents_refuses_changes_from_an_unconfined_control_client() {
let base = folders("prefs-unconfined");
let (app, saved) = app_with_agents(&base, AgentSwitch::fixed(true, false));
let (tx, rx) = std::sync::mpsc::channel();
let mut app = app.with_control(rx);
let ctx = app.ui_ctx.clone().unwrap_or_default();
let mut request = |params: Value| {
let (req, reply) = craft::automation::ControlRequest::new("engine.execute", json!({"command": "prefs.agents", "params": params}));
tx.send(req).unwrap();
app.run_control(&ctx);
reply.try_recv().unwrap()
};
let widened = request(json!({"readRoot": s(base.clone())}));
assert_eq!(widened["ok"], false, "{widened}");
assert!(widened["error"].as_str().is_some_and(|e| e.contains("can't change the agent settings")), "{widened}");
assert!(saved.lock().unwrap().is_empty(), "nothing was saved");
let read = request(json!({}));
assert_ne!(read["ok"], false, "{read}");
let _ = std::fs::remove_dir_all(&base);
}
+1 -1
View File
@@ -176,7 +176,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"prefs.agents",
"AI Integrations",
"",
"{controlPort?: 0–65535, readRoot?: string, writeRoot?: string, whenAppClosed?: launch|headless|error} the agent settings of Preferences › AI Integrations (agents in the open window through the ArtCraft Launcher's switch); given keys are saved where vectorcraft-cli mcp reads them, refused from an agent's request → {settings, status: {port, launchFlags, error}, allowed, mcpFlag}; an error in the web build and in a run without preferences",
"{controlPort?: 0–65535, readRoot?: string, writeRoot?: string, whenAppClosed?: launch|headless|error} the agent settings of Preferences › AI Integrations (agents in the open window through the ArtCraft Launcher's switch); given keys are saved where vectorcraft-cli mcp reads them, refused from an agent's or a control client's request → {settings, status: {port, launchFlags, error}, allowed, mcpFlag}; an error in the web build and in a run without preferences",
),
("edit.keyboardShortcuts", "Keyboard Shortcuts…", "Cmd+Alt+Shift+K", "{}"),
(
+1 -1
View File
@@ -47,7 +47,7 @@ only the folders given on its command line, as before.
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
VectorCraft without a window. The same settings are the UI command `prefs.agents {controlPort?, readRoot?,
writeRoot?, whenAppClosed?}`, which agents' own requests can read but not change. Started with `--control`,
writeRoot?, whenAppClosed?}`, which agents' own requests and `--control` clients can read but not change. Started with `--control`,
the window serves that channel for the whole run instead, and the page says so.
### Command catalogue (headless vs remote)