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:
@@ -31,6 +31,8 @@ pub struct Services {
|
||||
pub schedules: std::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
|
||||
/// Announces new collected items (admin.spec.md, "News notifications").
|
||||
pub news: std::sync::Mutex<Option<tokio::task::JoinHandle<()>>>,
|
||||
/// PC control's emergency-stop hotkey while PC control is available (admin.spec.md, "PC control").
|
||||
pub pc_hotkey: std::sync::Mutex<Option<crate::pc::Hotkey>>,
|
||||
}
|
||||
|
||||
/// The bot browser of a run (admin.spec.md, "Bot browser").
|
||||
@@ -82,6 +84,9 @@ impl Services {
|
||||
n.abort();
|
||||
let _ = n.await;
|
||||
}
|
||||
if let Some(h) = self.pc_hotkey.lock().unwrap().take() {
|
||||
h.end();
|
||||
}
|
||||
self.game.stop();
|
||||
self.core.close().await;
|
||||
self.worker.close();
|
||||
@@ -155,8 +160,10 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
hub.set_secrets_in_use(secrets_in_use(&token, &mcp_env, kma_key.as_deref()));
|
||||
}
|
||||
|
||||
// PC control: agent-desktop's hash is checked once per start (admin.spec.md, "PC control").
|
||||
let pc_exe = crate::pc::check(&settings);
|
||||
let (base_url, model) = llm.start(&settings).await?;
|
||||
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model, &settings) {
|
||||
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model, &settings, pc_exe.is_some()) {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Err(after_llm_stop(&llm, format!("could not write the brain settings: {e}")).await.into()),
|
||||
};
|
||||
@@ -214,7 +221,19 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
let chat_calls = conversation::ChatCalls::from_settings(&settings);
|
||||
let schedule_channel = settings.schedule_channel;
|
||||
let news_settings = settings.clone();
|
||||
let pc = pc_exe.as_ref().map(|exe| {
|
||||
let g = game.clone();
|
||||
crate::pc::Pc::new(settings.clone(), Box::new(crate::pc::Cli::new(exe, data_dir)), crate::pc::emergency(),
|
||||
Box::new(move || g.name()))
|
||||
});
|
||||
let stop_hotkey = settings.pc_control.stop_hotkey.clone();
|
||||
let (core, core_events) = DiscordCore::new(settings, token, worker.clone(), worker_events);
|
||||
let pc_hotkey = std::sync::Mutex::new(None);
|
||||
if let Some(pc) = pc {
|
||||
core.set_pc(Arc::new(pc));
|
||||
*pc_hotkey.lock().unwrap() = crate::pc::Hotkey::start(&stop_hotkey, crate::pc::emergency());
|
||||
crate::info_log!("conversation", "PC control available (agent-desktop {})", crate::pc::AGENT_DESKTOP_VERSION);
|
||||
}
|
||||
let schedule_store = Arc::new(crate::schedule::Store::new(data_dir));
|
||||
core.set_schedules(schedule_store.clone());
|
||||
let activity = Arc::new(crate::activity::Activity::new(data_dir));
|
||||
@@ -237,7 +256,7 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
Arc::new(core.clone()), activity))));
|
||||
let on = { let g = game.clone(); Arc::new(move || g.on()) };
|
||||
let perf = std::sync::Mutex::new(Some(tokio::spawn(perf_loop(perf_settings, llm.clone(), Arc::new(worker.clone()), on, RETRY_AFTER))));
|
||||
Ok(Services { core, events, worker, worker_process, missed, llm, browser, game, perf, schedules, news })
|
||||
Ok(Services { core, events, worker, worker_process, missed, llm, browser, game, perf, schedules, news, pc_hotkey })
|
||||
}
|
||||
|
||||
/// The voice worker writes its recordings where this names (voice_worker.spec.md, "Recordings").
|
||||
|
||||
Reference in New Issue
Block a user