mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
Merge pull request #10850 from dotCooCoo/fix/prefs-agents-control-clients
Agents: control clients can't change the agent settings
This commit is contained in:
5 files changed
+31
-5
No files matched your search
@@ -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", "{}"),
|
||||
(
|
||||
|
||||
@@ -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())?;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
@@ -53,7 +53,7 @@ launch, or authentication.
|
||||
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. Once input injected through
|
||||
writeRoot?, whenAppClosed?}`, which agents' own requests and `--control` clients can read but not change. Once input injected through
|
||||
the control channel has reached the open Preferences window, OK and Apply in that window put the agent
|
||||
settings back as they were read and save none of them; the person changes them in a Preferences window
|
||||
they open again. An OK or Apply sent by a control request is refused when it would change an agent setting,
|
||||
|
||||
Reference in new issue
Block a user