hanzo-mcp 1.1.23

Hanzo MCP server — a hanzo-mcp binary serving 15 hand-written tools (fs, exec, code, git, fetch, workspace, computer, browser, think, memory, plan, tasks, mode, hanzo, search) over JSON-RPC
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
/// Unified UI control tool for HIP-0300 architecture
///
/// Cross-platform native API support:
/// - macOS: Quartz/CoreGraphics (fastest)
/// - Linux: X11
/// - Windows: winapi
///
/// Performance targets (native mode):
/// - Click: <5ms
/// - Keypress: <2ms
/// - Screenshot: <50ms

use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::collections::HashMap;
use std::sync::Arc;

#[cfg(target_os = "macos")]
mod macos;

#[cfg(target_os = "linux")]
mod linux;

#[cfg(target_os = "windows")]
mod windows;

/// Platform-independent action types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum UiAction {
    // Mouse
    Click,
    DoubleClick,
    RightClick,
    MiddleClick,
    Move,
    MoveRelative,
    Drag,
    DragRelative,
    Scroll,
    // Keyboard
    Type,
    Write,
    Press,
    KeyDown,
    KeyUp,
    Hotkey,
    // Screen
    Screenshot,
    ScreenshotRegion,
    // Window
    GetActiveWindow,
    ListWindows,
    FocusWindow,
    // Screen info
    GetScreens,
    ScreenSize,
    Position,
    // Settings
    Sleep,
    SetPause,
    SetFailsafe,
    // Batch
    Batch,
    // Info
    Info,
}

impl Default for UiAction {
    fn default() -> Self {
        Self::Info
    }
}

impl std::str::FromStr for UiAction {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self> {
        match s.to_lowercase().as_str() {
            "click" => Ok(Self::Click),
            "double_click" | "doubleclick" => Ok(Self::DoubleClick),
            "right_click" | "rightclick" => Ok(Self::RightClick),
            "middle_click" | "middleclick" => Ok(Self::MiddleClick),
            "move" => Ok(Self::Move),
            "move_relative" | "moverelative" => Ok(Self::MoveRelative),
            "drag" => Ok(Self::Drag),
            "drag_relative" | "dragrelative" => Ok(Self::DragRelative),
            "scroll" => Ok(Self::Scroll),
            "type" => Ok(Self::Type),
            "write" => Ok(Self::Write),
            "press" => Ok(Self::Press),
            "key_down" | "keydown" => Ok(Self::KeyDown),
            "key_up" | "keyup" => Ok(Self::KeyUp),
            "hotkey" => Ok(Self::Hotkey),
            "screenshot" => Ok(Self::Screenshot),
            "screenshot_region" | "screenshotregion" => Ok(Self::ScreenshotRegion),
            "get_active_window" | "getactivewindow" => Ok(Self::GetActiveWindow),
            "list_windows" | "listwindows" => Ok(Self::ListWindows),
            "focus_window" | "focuswindow" => Ok(Self::FocusWindow),
            "get_screens" | "getscreens" => Ok(Self::GetScreens),
            "screen_size" | "screensize" => Ok(Self::ScreenSize),
            "position" => Ok(Self::Position),
            "sleep" => Ok(Self::Sleep),
            "set_pause" | "setpause" => Ok(Self::SetPause),
            "set_failsafe" | "setfailsafe" => Ok(Self::SetFailsafe),
            "batch" => Ok(Self::Batch),
            "info" => Ok(Self::Info),
            _ => Err(anyhow!("Unknown action: {}", s)),
        }
    }
}

/// Arguments for UI tool
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ComputerToolArgs {
    #[serde(default)]
    pub action: String,
    // Coordinates
    pub x: Option<i32>,
    pub y: Option<i32>,
    pub dx: Option<i32>,
    pub dy: Option<i32>,
    pub end_x: Option<i32>,
    pub end_y: Option<i32>,
    // Text/keys
    pub text: Option<String>,
    pub key: Option<String>,
    pub keys: Option<Vec<String>>,
    // Options
    #[serde(default = "default_button")]
    pub button: String,
    pub amount: Option<i32>,
    #[serde(default = "default_duration")]
    pub duration: f64,
    #[serde(default = "default_interval")]
    pub interval: f64,
    pub region: Option<Vec<i32>>,
    #[serde(default)]
    pub clear: bool,
    // Window
    pub title: Option<String>,
    // Name (for screenshot file)
    pub name: Option<String>,
    // Width/height
    pub width: Option<i32>,
    pub height: Option<i32>,
    // Value for settings
    pub value: Option<f64>,
    // Batch
    pub actions: Option<Vec<Value>>,
}

fn default_button() -> String {
    "left".to_string()
}

fn default_duration() -> f64 {
    0.25
}

fn default_interval() -> f64 {
    0.02
}

/// Window information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WindowInfo {
    pub app: Option<String>,
    pub title: String,
    pub x: i32,
    pub y: i32,
    pub width: i32,
    pub height: i32,
}

/// Platform capabilities
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformInfo {
    pub platform: String,
    pub native_available: bool,
    pub backends: HashMap<String, bool>,
}

/// Native control trait - implemented per platform
/// Aligned with TypeScript AutoGUIAdapter interface
pub trait NativeControl: Send + Sync {
    // Configuration
    /// Get platform info
    fn platform_info(&self) -> PlatformInfo;

    // Screen Information
    /// Get mouse position
    fn mouse_position(&self) -> Result<(i32, i32)>;

    /// Get screen size
    fn screen_size(&self) -> Result<(i32, i32)>;

    // Mouse Control
    /// Click at position
    fn click(&self, x: i32, y: i32, button: &str) -> Result<()>;

    /// Double click
    fn double_click(&self, x: i32, y: i32) -> Result<()>;

    /// Move mouse
    fn move_to(&self, x: i32, y: i32) -> Result<()>;

    /// Drag from current to target
    fn drag(&self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, button: &str) -> Result<()>;

    /// Scroll
    fn scroll(&self, amount: i32, x: Option<i32>, y: Option<i32>) -> Result<()>;

    // Keyboard Control
    /// Press key down
    fn key_down(&self, key: &str) -> Result<()>;

    /// Release key
    fn key_up(&self, key: &str) -> Result<()>;

    /// Press and release key
    fn press(&self, key: &str) -> Result<()>;

    /// Press key combination
    fn hotkey(&self, keys: &[String]) -> Result<()>;

    /// Type character
    fn type_char(&self, c: char) -> Result<()>;

    /// Type text
    fn type_text(&self, text: &str, interval: f64) -> Result<()>;

    // Screen Capture
    /// Take screenshot
    fn screenshot(&self, region: Option<&[i32]>) -> Result<Vec<u8>>;

    /// Get pixel color at position
    fn get_pixel(&self, x: i32, y: i32) -> Result<(u8, u8, u8)>;

    // Window Management
    /// Get active window
    fn get_active_window(&self) -> Result<WindowInfo>;

    /// List all windows
    fn list_windows(&self) -> Result<Vec<WindowInfo>>;

    /// Focus/activate window by title
    fn focus_window(&self, title: &str) -> Result<bool>;

    /// Minimize window by title
    fn minimize_window(&self, title: &str) -> Result<bool>;

    /// Maximize window by title
    fn maximize_window(&self, title: &str) -> Result<bool>;

    /// Resize window by title
    fn resize_window(&self, title: &str, width: i32, height: i32) -> Result<bool>;

    /// Move window by title
    fn move_window(&self, title: &str, x: i32, y: i32) -> Result<bool>;

    /// Close window by title
    fn close_window(&self, title: &str) -> Result<bool>;
}

/// Get the native control implementation for current platform
fn get_native_control() -> Box<dyn NativeControl> {
    #[cfg(target_os = "macos")]
    {
        Box::new(macos::MacOSControl::new())
    }

    #[cfg(target_os = "linux")]
    {
        Box::new(linux::LinuxControl::new())
    }

    #[cfg(target_os = "windows")]
    {
        Box::new(windows::WindowsControl::new())
    }

    #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
    {
        panic!("Unsupported platform");
    }
}

/// UI Tool implementation
pub struct ComputerTool {
    control: Arc<dyn NativeControl>,
    defined_regions: HashMap<String, (i32, i32, i32, i32)>,
    pause: f64,
    failsafe: bool,
}

impl ComputerTool {
    pub fn new() -> Self {
        Self {
            control: Arc::from(get_native_control()),
            defined_regions: HashMap::new(),
            pause: 0.1,
            failsafe: true,
        }
    }

    pub async fn execute(&mut self, args: ComputerToolArgs) -> Result<String> {
        let action: UiAction = if args.action.is_empty() {
            UiAction::Info
        } else {
            args.action.parse()?
        };

        // Clone Arc for use in spawn_blocking closures
        let ctrl = Arc::clone(&self.control);

        let result = match action {
            // Fast native operations - no spawn_blocking needed
            UiAction::Click => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                let button = args.button.clone();
                tokio::task::spawn_blocking(move || ctrl.click(x, y, &button)).await??;
                json!({"success": true, "clicked": [x, y], "button": args.button})
            }

            UiAction::DoubleClick => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                // Double click has internal sleep - must use spawn_blocking
                tokio::task::spawn_blocking(move || ctrl.double_click(x, y)).await??;
                json!({"success": true, "double_clicked": [x, y]})
            }

            UiAction::RightClick => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                tokio::task::spawn_blocking(move || ctrl.click(x, y, "right")).await??;
                json!({"success": true, "right_clicked": [x, y]})
            }

            UiAction::MiddleClick => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                tokio::task::spawn_blocking(move || ctrl.click(x, y, "middle")).await??;
                json!({"success": true, "middle_clicked": [x, y]})
            }

            UiAction::Move => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                tokio::task::spawn_blocking(move || ctrl.move_to(x, y)).await??;
                json!({"success": true, "moved_to": [x, y]})
            }

            UiAction::MoveRelative => {
                let dx = args.dx.ok_or_else(|| anyhow!("dx required"))?;
                let dy = args.dy.ok_or_else(|| anyhow!("dy required"))?;
                // mouse_position uses osascript on macOS - blocking
                let (cx, cy) = tokio::task::spawn_blocking({
                    let ctrl = Arc::clone(&ctrl);
                    move || ctrl.mouse_position()
                }).await??;
                tokio::task::spawn_blocking(move || ctrl.move_to(cx + dx, cy + dy)).await??;
                json!({"success": true, "moved_by": [dx, dy]})
            }

            UiAction::Drag => {
                let x = args.x.ok_or_else(|| anyhow!("x required"))?;
                let y = args.y.ok_or_else(|| anyhow!("y required"))?;
                let (start_x, start_y) = tokio::task::spawn_blocking({
                    let ctrl = Arc::clone(&ctrl);
                    move || ctrl.mouse_position()
                }).await??;
                let end_x = args.end_x.unwrap_or(x);
                let end_y = args.end_y.unwrap_or(y);
                let button = args.button.clone();
                // Drag has internal sleeps - must use spawn_blocking
                tokio::task::spawn_blocking(move || {
                    ctrl.drag(start_x, start_y, end_x, end_y, &button)
                }).await??;
                json!({"success": true, "dragged_to": [end_x, end_y]})
            }

            UiAction::DragRelative => {
                let dx = args.dx.ok_or_else(|| anyhow!("dx required"))?;
                let dy = args.dy.ok_or_else(|| anyhow!("dy required"))?;
                let (cx, cy) = tokio::task::spawn_blocking({
                    let ctrl = Arc::clone(&ctrl);
                    move || ctrl.mouse_position()
                }).await??;
                let button = args.button.clone();
                tokio::task::spawn_blocking(move || {
                    ctrl.drag(cx, cy, cx + dx, cy + dy, &button)
                }).await??;
                json!({"success": true, "dragged_by": [dx, dy]})
            }

            UiAction::Scroll => {
                let amount = args.amount.ok_or_else(|| anyhow!("amount required"))?;
                let x = args.x;
                let y = args.y;
                tokio::task::spawn_blocking(move || ctrl.scroll(amount, x, y)).await??;
                json!({"success": true, "scrolled": amount})
            }

            UiAction::Type => {
                let text = args.text.ok_or_else(|| anyhow!("text required"))?;
                let len = text.len();
                let interval = args.interval;
                // type_text has internal sleeps - must use spawn_blocking
                tokio::task::spawn_blocking(move || ctrl.type_text(&text, interval)).await??;
                json!({"success": true, "typed": len})
            }

            UiAction::Write => {
                let text = args.text.ok_or_else(|| anyhow!("text required"))?;
                let len = text.len();
                if args.clear {
                    // Select all and clear
                    #[cfg(target_os = "macos")]
                    let keys = vec!["command".to_string(), "a".to_string()];
                    #[cfg(not(target_os = "macos"))]
                    let keys = vec!["ctrl".to_string(), "a".to_string()];
                    tokio::task::spawn_blocking({
                        let ctrl = Arc::clone(&ctrl);
                        move || ctrl.hotkey(&keys)
                    }).await??;
                    tokio::time::sleep(std::time::Duration::from_millis(50)).await;
                }
                let interval = args.interval;
                tokio::task::spawn_blocking(move || ctrl.type_text(&text, interval)).await??;
                json!({"success": true, "wrote": len, "cleared": args.clear})
            }

            UiAction::Press => {
                let key = args.key.ok_or_else(|| anyhow!("key required"))?;
                let key_clone = key.clone();
                tokio::task::spawn_blocking(move || ctrl.press(&key_clone)).await??;
                json!({"success": true, "pressed": key})
            }

            UiAction::KeyDown => {
                let key = args.key.ok_or_else(|| anyhow!("key required"))?;
                let key_clone = key.clone();
                tokio::task::spawn_blocking(move || ctrl.key_down(&key_clone)).await??;
                json!({"success": true, "key_down": key})
            }

            UiAction::KeyUp => {
                let key = args.key.ok_or_else(|| anyhow!("key required"))?;
                let key_clone = key.clone();
                tokio::task::spawn_blocking(move || ctrl.key_up(&key_clone)).await??;
                json!({"success": true, "key_up": key})
            }

            UiAction::Hotkey => {
                let keys = args.keys.ok_or_else(|| anyhow!("keys required"))?;
                let combo = keys.join("+");
                tokio::task::spawn_blocking(move || ctrl.hotkey(&keys)).await??;
                json!({"success": true, "hotkey": combo})
            }

            UiAction::Screenshot | UiAction::ScreenshotRegion => {
                let region: Option<Vec<i32>> = args.region.clone();
                // Screenshot uses subprocess - must use spawn_blocking
                let data = tokio::task::spawn_blocking(move || {
                    ctrl.screenshot(region.as_deref())
                }).await??;

                // If name provided, save to file
                if let Some(name) = args.name {
                    let path = if name.starts_with('/') || name.starts_with('~') {
                        shellexpand::tilde(&name).to_string()
                    } else {
                        format!("{}/{}", std::env::temp_dir().display(), name)
                    };
                    let path = if !path.ends_with(".png") {
                        format!("{}.png", path)
                    } else {
                        path
                    };
                    // Async file write
                    tokio::fs::write(&path, &data).await?;
                    json!({
                        "success": true,
                        "format": "png",
                        "size": data.len(),
                        "path": path
                    })
                } else {
                    use base64::{Engine, engine::general_purpose::STANDARD};
                    let b64 = STANDARD.encode(&data);
                    json!({
                        "success": true,
                        "format": "png",
                        "size": data.len(),
                        "base64": b64
                    })
                }
            }

            UiAction::GetActiveWindow => {
                // Uses osascript/xdotool - must use spawn_blocking
                let info = tokio::task::spawn_blocking(move || {
                    ctrl.get_active_window()
                }).await??;
                json!(info)
            }

            UiAction::ListWindows => {
                // Uses osascript/xdotool - must use spawn_blocking
                let windows = tokio::task::spawn_blocking(move || {
                    ctrl.list_windows()
                }).await??;
                json!({"windows": windows, "count": windows.len()})
            }

            UiAction::FocusWindow => {
                let title = args.title.or(args.text).ok_or_else(|| anyhow!("title required"))?;
                let title_clone = title.clone();
                // Uses osascript/xdotool - must use spawn_blocking
                let success = tokio::task::spawn_blocking(move || {
                    ctrl.focus_window(&title_clone)
                }).await??;
                json!({"success": success, "focused": title})
            }

            UiAction::GetScreens => {
                // screen_size is fast native call, but wrap for consistency
                let (w, h) = tokio::task::spawn_blocking(move || {
                    ctrl.screen_size()
                }).await??;
                json!([{"name": "Primary", "resolution": format!("{}x{}", w, h), "main": true}])
            }

            UiAction::ScreenSize => {
                let (w, h) = tokio::task::spawn_blocking(move || {
                    ctrl.screen_size()
                }).await??;
                json!({"width": w, "height": h})
            }

            UiAction::Position => {
                // mouse_position uses osascript on macOS - must use spawn_blocking
                let (x, y) = tokio::task::spawn_blocking(move || {
                    ctrl.mouse_position()
                }).await??;
                json!({"x": x, "y": y})
            }

            UiAction::Sleep => {
                let secs = args.value.ok_or_else(|| anyhow!("value required"))?;
                // Use async sleep - does not block runtime
                tokio::time::sleep(std::time::Duration::from_secs_f64(secs)).await;
                json!({"success": true, "slept": secs})
            }

            UiAction::SetPause => {
                let val = args.value.ok_or_else(|| anyhow!("value required"))?;
                self.pause = val;
                json!({"success": true, "pause": self.pause})
            }

            UiAction::SetFailsafe => {
                let val = args.value.ok_or_else(|| anyhow!("value required"))?;
                self.failsafe = val != 0.0;
                json!({"success": true, "failsafe": self.failsafe})
            }

            UiAction::Batch => {
                let actions = args.actions.ok_or_else(|| anyhow!("actions required"))?;
                let start = std::time::Instant::now();
                let mut results = Vec::new();

                for (i, action_val) in actions.iter().enumerate() {
                    let action_args: ComputerToolArgs = serde_json::from_value(action_val.clone())
                        .unwrap_or_default();

                    match Box::pin(self.execute(action_args)).await {
                        Ok(_) => {
                            results.push(json!({"index": i, "success": true}));
                        }
                        Err(e) => {
                            results.push(json!({"index": i, "error": e.to_string()}));
                        }
                    }
                }

                let elapsed = start.elapsed().as_millis();
                json!({
                    "success": true,
                    "count": results.len(),
                    "elapsed_ms": elapsed,
                    "results": results
                })
            }

            UiAction::Info => {
                // Clone for multiple spawn_blocking calls
                let ctrl2 = Arc::clone(&ctrl);
                let (mx, my) = tokio::task::spawn_blocking(move || {
                    ctrl.mouse_position()
                }).await?.unwrap_or((0, 0));
                let ctrl3 = Arc::clone(&ctrl2);
                let (sw, sh) = tokio::task::spawn_blocking(move || {
                    ctrl2.screen_size()
                }).await?.unwrap_or((0, 0));
                let platform_info = ctrl3.platform_info();

                json!({
                    "screen": {"width": sw, "height": sh},
                    "mouse": {"x": mx, "y": my},
                    "platform": platform_info,
                    "pause": self.pause,
                    "failsafe": self.failsafe,
                    "regions": self.defined_regions.keys().collect::<Vec<_>>()
                })
            }
        };

        Ok(serde_json::to_string(&result)?)
    }
}

/// MCP Tool Definition
#[derive(Debug, Serialize, Deserialize)]
pub struct ComputerToolDefinition {
    pub name: String,
    pub description: String,
    pub input_schema: Value,
}

impl ComputerToolDefinition {
    pub fn new() -> Self {
        let platform = std::env::consts::OS;
        let backend = match platform {
            "macos" => "quartz",
            "linux" => "x11",
            "windows" => "win32",
            _ => "unknown",
        };

        Self {
            name: "computer".to_string(),
            description: format!(
                r#"Control local computer with native API acceleration.

PLATFORM: {}
BACKENDS: {}

MOUSE (< 5ms native):
- click(x, y) / double_click / right_click / middle_click
- move(x, y) / move_relative(dx, dy)
- drag(x, y) / drag_relative(dx, dy)
- scroll(amount, x, y)

KEYBOARD (< 2ms native):
- type(text, interval): Type text
- write(text, clear): Type with optional clear
- press(key): Press and release key
- key_down(key) / key_up(key): Hold/release
- hotkey(keys): Key combination ["command", "c"]

SCREEN (< 50ms native):
- screenshot() / screenshot_region(region)
- get_screens(): List displays
- screen_size() / position()

WINDOWS:
- get_active_window(): Frontmost window info
- list_windows(): All windows with bounds
- focus_window(title): Activate window

BATCH:
- batch(actions): Execute multiple actions

INFO:
- info()

Examples:
    ui(action="click", x=100, y=200)
    ui(action="type", text="Hello")
    ui(action="hotkey", keys=["command", "c"])
    ui(action="screenshot")
    ui(action="batch", actions=[
        {{"action": "click", "x": 100, "y": 200}},
        {{"action": "type", "text": "test"}}
    ])"#,
                platform, backend
            ),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "action": {
                        "type": "string",
                        "description": "Action to perform",
                        "default": "info"
                    },
                    "x": {"type": "integer", "description": "X coordinate"},
                    "y": {"type": "integer", "description": "Y coordinate"},
                    "dx": {"type": "integer", "description": "Delta X"},
                    "dy": {"type": "integer", "description": "Delta Y"},
                    "end_x": {"type": "integer", "description": "End X for drag"},
                    "end_y": {"type": "integer", "description": "End Y for drag"},
                    "text": {"type": "string", "description": "Text to type"},
                    "key": {"type": "string", "description": "Key to press"},
                    "keys": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Keys for hotkey"
                    },
                    "button": {
                        "type": "string",
                        "description": "Mouse button",
                        "default": "left"
                    },
                    "amount": {"type": "integer", "description": "Scroll amount"},
                    "duration": {"type": "number", "description": "Duration", "default": 0.25},
                    "interval": {"type": "number", "description": "Type interval", "default": 0.02},
                    "region": {
                        "type": "array",
                        "items": {"type": "integer"},
                        "description": "Region [x,y,w,h]"
                    },
                    "clear": {"type": "boolean", "description": "Clear before write", "default": false},
                    "title": {"type": "string", "description": "Window title"},
                    "name": {"type": "string", "description": "Screenshot filename"},
                    "value": {"type": "number", "description": "Value for settings"},
                    "actions": {
                        "type": "array",
                        "items": {"type": "object"},
                        "description": "Batch actions"
                    }
                }
            }),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_info_action() {
        let mut tool = ComputerTool::new();
        let args = ComputerToolArgs {
            action: "info".to_string(),
            ..Default::default()
        };

        let result = tool.execute(args).await;
        assert!(result.is_ok());
        let output = result.unwrap();
        assert!(output.contains("screen"));
        assert!(output.contains("mouse"));
    }

    #[tokio::test]
    async fn test_position_action() {
        let mut tool = ComputerTool::new();
        let args = ComputerToolArgs {
            action: "position".to_string(),
            ..Default::default()
        };

        let result = tool.execute(args).await;
        assert!(result.is_ok());
        let output = result.unwrap();
        assert!(output.contains("x"));
        assert!(output.contains("y"));
    }

    #[tokio::test]
    async fn test_screen_size_action() {
        let mut tool = ComputerTool::new();
        let args = ComputerToolArgs {
            action: "screen_size".to_string(),
            ..Default::default()
        };

        let result = tool.execute(args).await;
        assert!(result.is_ok());
        let output = result.unwrap();
        assert!(output.contains("width"));
        assert!(output.contains("height"));
    }
}