feat(app): PC control through agent-desktop, with the emergency stop and the anti-cheat block
app/src/pc.rs runs every pc_action from the worker (admin.spec.md, "PC control"): one agent-desktop 1.2.0 run per command with a 15 s limit and its state in the data folder, never --force or raw input, typed text only through stdin. Each action is decided by permissions::decide for its asker (not registered, never, ask without consent), then refused during the emergency stop, while an anti-cheat game runs (Vanguard, EAC, BattlEye, FACEIT, GameGuard, XIGNCODE3 and the person's list), on an administrator window and in a password field. Results carry the window and its elements read again (200 at most, cut to 120 chars), agent-desktop's error codes become Korean reasons, and each action is recorded as pc.<action> with the program's file name only. The emergency stop is a global hotkey (pcControl.stopHotkey, default Ctrl+Shift+F12) on its own message loop; it kills the running command and blocks everything but reading until pressed again or lifted on the PC control screen. features.pcControl (on by default, nothing happens until someone is registered) and the pinned exe hash decide whether the brain gets the tool. The installer ships agent-desktop.exe from the pinned release archive, both hashes checked. Tested with a fake agent-desktop (342 lib tests pass) and cargo check for x86_64-pc-windows-gnu; not yet run against real agent-desktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,8 @@ pub struct FeatureSettings {
|
||||
pub notes: bool,
|
||||
/// Screen viewing (admin.spec.md, "Screen viewing").
|
||||
pub screen: bool,
|
||||
/// Operating programs through agent-desktop (admin.spec.md, "PC control").
|
||||
pub pc_control: bool,
|
||||
}
|
||||
|
||||
/// Game detection (admin.spec.md, "Game detection"): on by default; the person's own games and
|
||||
@@ -187,6 +189,11 @@ pub struct PcControlSettings {
|
||||
pub run: Level,
|
||||
/// Programs never seen on the screen (file names, ".exe" may be left out).
|
||||
pub screen_exclude: Vec<String>,
|
||||
/// Programs with an anti-cheat the person added (file names, ".exe" may be left out): while one
|
||||
/// runs, nothing but reading is done (admin.spec.md, "PC control").
|
||||
pub anti_cheat_games: Vec<String>,
|
||||
/// The emergency stop's global hotkey (`Ctrl+Shift+F12`).
|
||||
pub stop_hotkey: String,
|
||||
}
|
||||
|
||||
/// An MCP server the brain starts (stdio). The values of `env` are in the secrets, never here.
|
||||
@@ -276,14 +283,15 @@ impl Default for Settings {
|
||||
response: PolicySettings::default(),
|
||||
memory: Map::new(),
|
||||
llm: LlmSettings { url: None, port: 8080, context: 32768 },
|
||||
features: FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true },
|
||||
features: FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true, pc_control: true },
|
||||
mcp_servers: vec![],
|
||||
collect: CollectSettings { keep_days: 30, targets: vec![], notify_channel: None, digest_hour: 9 },
|
||||
game: GameSettings { detect: true, games: vec![], not_games: vec![], other_room_gb: 1.0, reserve_gb: 8.0, revert_seconds: 30, pause_in_game: false },
|
||||
schedule_channel: None,
|
||||
pc_control: PcControlSettings { allowed_users: vec![], view: Level::Auto, click: Level::Ask,
|
||||
type_text: Level::Ask, run: Level::Ask,
|
||||
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into() },
|
||||
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into(),
|
||||
anti_cheat_games: vec![], stop_hotkey: crate::pc::DEFAULT_STOP_HOTKEY.into() },
|
||||
close_to_tray: false,
|
||||
location: Some(DEFAULT_LOCATION.into()),
|
||||
}
|
||||
@@ -627,6 +635,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
schedule: get_bool(f, "schedule", "features", d.features.schedule)?,
|
||||
notes: get_bool(f, "notes", "features", d.features.notes)?,
|
||||
screen: get_bool(f, "screen", "features", d.features.screen)?,
|
||||
pc_control: get_bool(f, "pcControl", "features", d.features.pc_control)?,
|
||||
}
|
||||
},
|
||||
mcp_servers: parse_mcp_servers(raw)?,
|
||||
@@ -660,20 +669,27 @@ fn parse_pc_control(raw: &Map<String, Value>, d: &PcControlSettings) -> Result<P
|
||||
Some(_) => err(format!("pcControl.{key} must be auto, ask or never")),
|
||||
}
|
||||
};
|
||||
let programs = |key: &str, default: &[String]| -> Result<Vec<String>, SettingsError> {
|
||||
let v: Vec<String> = get_str_list(p, key, "pcControl", default)?.into_iter()
|
||||
.map(|e| e.trim().to_owned()).filter(|e| !e.is_empty()).collect();
|
||||
if v.len() > 100 || v.iter().any(|e| e.chars().count() > 100 || e.contains(['\\', '/'])) {
|
||||
return err(format!("pcControl.{key} must be at most 100 program names (no folders)"));
|
||||
}
|
||||
Ok(v)
|
||||
};
|
||||
let stop_hotkey = get_str(p, "stopHotkey", "pcControl", &d.stop_hotkey)?.trim().to_owned();
|
||||
if crate::pc::parse_hotkey(&stop_hotkey).is_none() {
|
||||
return err("pcControl.stopHotkey must be modifiers and a key, such as Ctrl+Shift+F12");
|
||||
}
|
||||
Ok(PcControlSettings {
|
||||
allowed_users: snowflake_list(p, "allowedUsers", "pcControl")?,
|
||||
view: level("view", d.view)?,
|
||||
click: level("click", d.click)?,
|
||||
type_text: level("type", d.type_text)?,
|
||||
run: level("run", d.run)?,
|
||||
screen_exclude: {
|
||||
let v: Vec<String> = get_str_list(p, "screenExclude", "pcControl", &d.screen_exclude)?.into_iter()
|
||||
.map(|e| e.trim().to_owned()).filter(|e| !e.is_empty()).collect();
|
||||
if v.len() > 100 || v.iter().any(|e| e.chars().count() > 100 || e.contains(['\\', '/'])) {
|
||||
return err("pcControl.screenExclude must be at most 100 program names (no folders)");
|
||||
}
|
||||
v
|
||||
},
|
||||
screen_exclude: programs("screenExclude", &d.screen_exclude)?,
|
||||
anti_cheat_games: programs("antiCheatGames", &d.anti_cheat_games)?,
|
||||
stop_hotkey,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1054,13 +1070,13 @@ mod tests {
|
||||
#[test]
|
||||
fn features_and_mcp_servers_are_read_and_checked() {
|
||||
let s = parse_settings(&json!({}));
|
||||
assert_eq!(s.unwrap().features, FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true });
|
||||
assert_eq!(s.unwrap().features, FeatureSettings { weather: true, web_search: true, meals: true, collect: true, browser: true, browser_share: false, schedule: true, notes: true, screen: true, pc_control: true });
|
||||
let s = parse_settings(&json!({
|
||||
"features": {"weather": false, "meals": false, "browserShare": true, "schedule": false, "notes": false, "screen": false},
|
||||
"features": {"weather": false, "meals": false, "browserShare": true, "schedule": false, "notes": false, "screen": false, "pcControl": false},
|
||||
"mcpServers": [{"name": "brave", "command": "npx", "args": ["-y", "brave"], "env": ["BRAVE_API_KEY", " "]},
|
||||
{"name": "time-2", "command": "uvx", "enabled": false}]
|
||||
})).unwrap();
|
||||
assert_eq!(s.features, FeatureSettings { weather: false, web_search: true, meals: false, collect: true, browser: true, browser_share: true, schedule: false, notes: false, screen: false });
|
||||
assert_eq!(s.features, FeatureSettings { weather: false, web_search: true, meals: false, collect: true, browser: true, browser_share: true, schedule: false, notes: false, screen: false, pc_control: false });
|
||||
assert_eq!(s.mcp_servers, vec![
|
||||
McpServerSettings { name: "brave".into(), command: "npx".into(), args: vec!["-y".into(), "brave".into()],
|
||||
env: vec!["BRAVE_API_KEY".into()], enabled: true },
|
||||
@@ -1071,13 +1087,23 @@ mod tests {
|
||||
assert!(pc.allowed_users.is_empty());
|
||||
assert_eq!((pc.view, pc.click, pc.type_text, pc.run), (Level::Auto, Level::Ask, Level::Ask, Level::Ask));
|
||||
assert!(pc.screen_exclude.contains(&"KeePassXC".to_owned()), "password managers are never seen by default");
|
||||
assert!(pc.anti_cheat_games.is_empty());
|
||||
assert_eq!(pc.stop_hotkey, "Ctrl+Shift+F12");
|
||||
let pc = parse_settings(&json!({"pcControl": {"allowedUsers": ["123456789012345678"], "view": "never",
|
||||
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""]}})).unwrap().pc_control;
|
||||
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""],
|
||||
"antiCheatGames": ["MyShooter"], "stopHotkey": "Ctrl+Shift+Nope"}})).unwrap_err();
|
||||
assert!(pc.0.contains("pcControl.stopHotkey"), "{pc}");
|
||||
let pc = parse_settings(&json!({"pcControl": {"allowedUsers": ["123456789012345678"], "view": "never",
|
||||
"click": "auto", "type": "never", "run": "auto", "screenExclude": [" bank.exe ", ""],
|
||||
"antiCheatGames": ["MyShooter"], "stopHotkey": " ctrl+alt+s "}})).unwrap().pc_control;
|
||||
assert_eq!(pc.allowed_users, vec![123456789012345678]);
|
||||
assert_eq!(pc.screen_exclude, vec!["bank.exe".to_owned()]);
|
||||
assert_eq!(pc.anti_cheat_games, vec!["MyShooter".to_owned()]);
|
||||
assert_eq!(pc.stop_hotkey, "ctrl+alt+s");
|
||||
assert_eq!((pc.view, pc.click, pc.type_text, pc.run), (Level::Never, Level::Auto, Level::Never, Level::Auto));
|
||||
for bad in [json!({"pcControl": {"click": "yes"}}), json!({"pcControl": {"allowedUsers": ["1"]}}),
|
||||
json!({"pcControl": {"screenExclude": ["C:\\bank\\bank.exe"]}}), json!({"pcControl": {"screenExclude": "x"}})] {
|
||||
json!({"pcControl": {"screenExclude": ["C:\\bank\\bank.exe"]}}), json!({"pcControl": {"screenExclude": "x"}}),
|
||||
json!({"pcControl": {"antiCheatGames": ["D:\\games\\x.exe"]}}), json!({"pcControl": {"stopHotkey": "F12"}})] {
|
||||
assert!(parse_settings(&bad).unwrap_err().0.contains("pcControl."), "{bad}");
|
||||
}
|
||||
// A schedule channel must be a registered one that Jarvis may send in.
|
||||
|
||||
Reference in New Issue
Block a user