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:
@@ -207,6 +207,8 @@ struct Inner {
|
||||
notes: OnceLock<Arc<crate::notes::Notes>>,
|
||||
/// What Jarvis did outside its answers (admin.spec.md, "Activity").
|
||||
activity: OnceLock<Arc<crate::activity::Activity>>,
|
||||
/// PC control, when it is available (admin.spec.md, "PC control").
|
||||
pc: OnceLock<Arc<crate::pc::Pc>>,
|
||||
/// Speech requests whose end someone waits for (`say_to_end`), by request id.
|
||||
speech_waits: Mutex<HashMap<String, tokio::sync::oneshot::Sender<PlaybackEnd>>>,
|
||||
/// The spoken transcription notice of the current voice session.
|
||||
@@ -334,6 +336,7 @@ impl DiscordCore {
|
||||
notice: Mutex::new(JoinNotice::default()),
|
||||
activity: OnceLock::new(),
|
||||
notes: OnceLock::new(),
|
||||
pc: OnceLock::new(),
|
||||
});
|
||||
tokio::spawn(player_task(Arc::downgrade(&inner), player_rx));
|
||||
tokio::spawn(worker_task(Arc::downgrade(&inner), worker_events));
|
||||
@@ -597,6 +600,11 @@ impl DiscordCore {
|
||||
let _ = self.inner.activity.set(activity);
|
||||
}
|
||||
|
||||
/// PC control for the brain's pcControl tool; without it its actions are refused.
|
||||
pub fn set_pc(&self, pc: Arc<crate::pc::Pc>) {
|
||||
let _ = self.inner.pc.set(pc);
|
||||
}
|
||||
|
||||
/// Run a scheduled task in the brain (read-only tools, not spoken) and wait for its answer.
|
||||
pub async fn run_task(&self, id: &str, user: u64, text: &str) -> Option<String> {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
@@ -1018,6 +1026,26 @@ async fn worker_task(core: std::sync::Weak<Inner>, mut rx: mpsc::UnboundedReceiv
|
||||
inner.worker.screen_action_result(&a.id, result);
|
||||
});
|
||||
}
|
||||
WorkerEvent::PcAction(a) => {
|
||||
let inner = inner.clone();
|
||||
tokio::spawn(async move {
|
||||
let started = std::time::Instant::now();
|
||||
let pc = inner.pc.get().cloned();
|
||||
let req = a.clone();
|
||||
let out = tokio::task::spawn_blocking(move || pc.map(|pc| pc.act(&req))).await.ok().flatten();
|
||||
let out = out.unwrap_or_else(|| crate::pc::Outcome {
|
||||
reply: serde_json::json!({"ok": false, "error": "이 PC에서는 PC 제어를 쓸 수 없습니다"}),
|
||||
code: "unavailable".into(), activity: None });
|
||||
// The action, its result code and the time only: never a title, element or text.
|
||||
debug_log!("conversation", "pc {} {} {} ms={}", a.id, a.action.chars().take(10).collect::<String>(),
|
||||
out.code, started.elapsed().as_millis());
|
||||
if let (Some(r), Some(activity)) = (&out.activity, inner.activity.get()) {
|
||||
let by = a.user.parse().ok().map(|u| format!("{u} {}", name_of(&inner, u)));
|
||||
activity.record(&r.kind, &r.target, by, r.ok, r.note.clone());
|
||||
}
|
||||
inner.worker.pc_action_result(&a.id, out.reply);
|
||||
});
|
||||
}
|
||||
WorkerEvent::ScheduleAction(a) => {
|
||||
let result = match inner.schedules.get() {
|
||||
Some(store) => {
|
||||
|
||||
Reference in New Issue
Block a user