cats 0.1.24

Coding Agent ToolS - A comprehensive toolkit for building AI-powered coding agents
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
//! File navigation tools
//!
//! Provides windowed file viewing, line navigation, and file creation

use super::state::ToolState;
use crate::core::{Tool, ToolArgs, ToolError, ToolResult};
use anyhow::Result;
use std::fs;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};

/// Default window size used by other windowing utilities
pub const DEFAULT_WINDOW_SIZE: usize = 100;

/// Default window size specifically for the "open" tool (configurable via simpaticoder.toml)
pub const OPEN_TOOL_DEFAULT_WINDOW_SIZE: usize = 1000;

/// Windowed file representation following SWE-agent pattern
#[derive(Debug, Clone)]
pub struct WindowedFile {
    pub path: PathBuf,
    pub content: Vec<String>,
    pub window_start: usize,
    pub window_size: usize,
}

impl WindowedFile {
    /// Create a new windowed file
    pub fn new(path: PathBuf, window_size: Option<usize>) -> Result<Self, ToolError> {
        let content = fs::read_to_string(&path).map_err(|_| ToolError::FileNotFound {
            path: path.to_string_lossy().to_string(),
        })?;

        let lines: Vec<String> = content.lines().map(|s| s.to_string()).collect();

        Ok(Self {
            path,
            content: lines,
            window_start: 0,
            window_size: window_size.unwrap_or(DEFAULT_WINDOW_SIZE),
        })
    }

    /// Create from existing content
    pub fn from_content(path: PathBuf, content: Vec<String>, window_size: Option<usize>) -> Self {
        Self {
            path,
            content,
            window_start: 0,
            window_size: window_size.unwrap_or(DEFAULT_WINDOW_SIZE),
        }
    }

    /// Get current window content with line numbers
    pub fn get_window_display(&self) -> String {
        let end = std::cmp::min(self.window_start + self.window_size, self.content.len());
        let window_content = &self.content[self.window_start..end];

        let mut result = String::new();
        result.push_str(&format!(
            "File: {} ({} lines)\n",
            self.path.display(),
            self.content.len()
        ));
        result.push_str(&format!(
            "Lines {}-{} of {}:\n",
            self.window_start + 1,
            end,
            self.content.len()
        ));
        result.push_str(&"-".repeat(80));
        result.push('\n');

        for (i, line) in window_content.iter().enumerate() {
            result.push_str(&format!("{:4} | {}\n", self.window_start + i + 1, line));
        }

        result.push_str(&"-".repeat(80));
        result.push('\n');

        if self.window_start > 0 {
            result.push_str("(Use scroll_up to see previous lines)\n");
        }
        if end < self.content.len() {
            result.push_str("(Use scroll_down to see more lines)\n");
        }

        result
    }
}

/// Tool for opening files
pub struct OpenTool {
    name: String,
    /// Default window size for the open tool (if None, use OPEN_TOOL_DEFAULT_WINDOW_SIZE)
    default_window_size: Option<usize>,
}

impl OpenTool {
    /// Backward-compatible no-arg constructor (defaults to None)
    pub fn new() -> Self {
        Self {
            name: "open".to_string(),
            default_window_size: None,
        }
    }

    /// Create with explicit open tool default window size
    pub fn new_with_open_window_size(open_window_size: Option<usize>) -> Self {
        Self {
            name: "open".to_string(),
            default_window_size: open_window_size,
        }
    }

    /// Constructor that accepts an optional default window size for the open tool
    pub fn new_with_default(default_window_size: Option<usize>) -> Self {
        Self {
            name: "open".to_string(),
            default_window_size,
        }
    }
}

impl Tool for OpenTool {
    fn name(&self) -> &str {
        &self.name
    }

    fn description(&self) -> &str {
        "Opens the file at the given path in the editor. If line_number is provided, the window will be moved to include that line"
    }

    fn signature(&self) -> &str {
        r#"open "<path>" [<line_number>]"#
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        if args.is_empty() {
            return Err(ToolError::InvalidArgs {
                message: "Usage: open \"<file>\" [<line_number>]".to_string(),
            });
        }
        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let path = args.get_arg(0).unwrap();
        let path_buf = PathBuf::from(path);

        // Check if path exists
        if !path_buf.exists() {
            return Ok(ToolResult::error(format!("File not found: {}", path)));
        }

        // Get line number if provided
        let line_number: Option<usize> = args.get_arg(1).and_then(|s| s.parse().ok());

        // Check if file is already open and return current state to prevent repetitive opening
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            if let Some(current_file) = &state_guard.current_file {
                if current_file == &path_buf {
                    // File is already open
                    if let Some(line_num) = line_number {
                        // Move current open file to requested line -- do mutations in an inner scope to avoid holding
                        // a mutable borrow while also calling state_guard.push_history later.
                        let mut moved_window: Option<Vec<String>> = None;
                        let mut total_lines: Option<usize> = None;

                        if let Some(file_state) = state_guard.get_current_file_state_mut() {
                            file_state.goto_line(line_num);
                            total_lines = Some(file_state.total_lines());
                            moved_window = Some(file_state.get_window_with_line_numbers());
                        }

                        // If requested line is beyond EOF, return a warning similar to open-path behavior
                        if let Some(tl) = total_lines {
                            if line_num > tl {
                                return Ok(ToolResult::success_with_data(
                                    format!("File {} is already open (moved to line {} of {}). Warning: Line number {} is greater than total lines.",
                                        path, line_num, tl, line_num),
                                    serde_json::json!({
                                        "path": path,
                                        "already_open": true,
                                        "total_lines": tl,
                                        "current_window": moved_window.unwrap_or_default()
                                    })
                                ));
                            }
                        }

                        // Safe to push history now; mutable borrow from get_current_file_state_mut() has ended
                        state_guard.push_history(format!("Moved to line {} in {}", line_num, path));

                        let current_window = moved_window.unwrap_or_default();
                        let result_message = format!(
                            "File {} is already open (moved to line {}):\n\n{}",
                            path,
                            line_num,
                            current_window.join("\n")
                        );

                        return Ok(ToolResult::success_with_data(
                            result_message,
                            serde_json::json!({
                                "path": path,
                                "already_open": true,
                                "total_lines": total_lines.unwrap_or(0),
                                "window_content": current_window
                            }),
                        ));
                    } else {
                        if let Some(file_state) = state_guard.get_current_file_state() {
                            let current_window = file_state.get_window_with_line_numbers();
                            let result_message = format!(
                                "File {} is already open (showing current window):\n\n{}",
                                path,
                                current_window.join("\n")
                            );

                            return Ok(ToolResult::success_with_data(
                                result_message,
                                serde_json::json!({
                                    "path": path,
                                    "already_open": true,
                                    "total_lines": file_state.total_lines(),
                                    "window_content": current_window
                                }),
                            ));
                        }
                    }
                }
            }
        }

        // Read file content
        let content = fs::read_to_string(&path_buf)
            .map_err(|e| anyhow::anyhow!("Failed to read file: {}", e))?;
        let lines: Vec<String> = content.lines().map(|s| s.to_string()).collect();

        // Get line number if provided
        let line_number: Option<usize> = args.get_arg(1).and_then(|s| s.parse().ok());

        // Determine the open tool's window size (configurable)
        let open_window = self
            .default_window_size
            .unwrap_or(OPEN_TOOL_DEFAULT_WINDOW_SIZE);

        // Create windowed file with the configured window size
        let windowed_file =
            WindowedFile::from_content(path_buf.clone(), lines.clone(), Some(open_window));

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            state_guard.open_file(path_buf.clone(), lines, open_window)?;

            // Move to specified line if provided
            if let Some(line_num) = line_number {
                if let Some(file_state) = state_guard.get_current_file_state_mut() {
                    file_state.goto_line(line_num);
                    if line_num > file_state.total_lines() {
                        return Ok(ToolResult::success_with_data(
                            format!("Opened {} (moved to line {} of {}). Warning: Line number {} is greater than total lines.", 
                                path, line_num, file_state.total_lines(), line_num),
                            serde_json::json!({
                                "path": path,
                                "total_lines": file_state.total_lines(),
                                "current_window": file_state.get_window_with_line_numbers()
                            })
                        ));
                    }
                }
            }

            state_guard.push_history(format!("Opened file: {}", path));
        }

        // Get the current window content for immediate display
        let state_guard = state
            .lock()
            .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
        let current_window = if let Some(file_state) = state_guard.get_current_file_state() {
            file_state.get_window_with_line_numbers()
        } else {
            vec![]
        };
        drop(state_guard);

        // Create result message with file content
        let result_message = format!(
            "Opened file: {} ({} lines)\n\n{}",
            path,
            windowed_file.content.len(),
            current_window.join("\n")
        );

        Ok(ToolResult::success_with_data(
            result_message,
            serde_json::json!({
                "path": path,
                "total_lines": windowed_file.content.len(),
                "window_content": current_window
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "The path to the file to open"
                },
                "line_number": {
                    "type": "integer",
                    "description": "Optional line number to move the window to"
                }
            },
            "required": ["path"]
        })
    }
}

/// Tool for navigating to specific lines
pub struct GotoTool {
    name: String,
}

impl GotoTool {
    pub fn new() -> Self {
        Self {
            name: "goto".to_string(),
        }
    }
}

impl Tool for GotoTool {
    fn name(&self) -> &str {
        &self.name
    }

    fn description(&self) -> &str {
        "Moves the window to show <line_number>"
    }

    fn signature(&self) -> &str {
        "goto <line_number>"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        if args.is_empty() {
            return Err(ToolError::InvalidArgs {
                message: "Usage: goto <line_number>".to_string(),
            });
        }

        if args.get_arg(0).unwrap().parse::<usize>().is_err() {
            return Err(ToolError::InvalidArgs {
                message: "Line number must be a positive integer".to_string(),
            });
        }

        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let line_number: usize = args
            .get_arg(0)
            .unwrap()
            .parse()
            .map_err(|_| anyhow::anyhow!("Invalid line number"))?;

        let mut state_guard = state
            .lock()
            .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;

        // Check if there's a current file
        let current_file = state_guard
            .current_file
            .clone()
            .ok_or_else(|| anyhow::anyhow!("No file is currently open. Use 'open' first."))?;

        // Move to the specified line
        if let Some(file_state) = state_guard.get_current_file_state_mut() {
            let total_lines = file_state.total_lines();

            if line_number == 0 {
                return Ok(ToolResult::error("Line numbers start from 1".to_string()));
            }

            if line_number > total_lines {
                return Ok(ToolResult::error(format!(
                    "Line {} is beyond the end of the file (total lines: {})",
                    line_number, total_lines
                )));
            }

            file_state.goto_line(line_number);
            let display = file_state.get_window_with_line_numbers();

            state_guard.push_history(format!(
                "Moved to line {} in {}",
                line_number,
                current_file.display()
            ));

            let result_message = format!(
                "Moved to line {} in {}\n\n{}",
                line_number,
                current_file.display(),
                display.join("\n")
            );

            Ok(ToolResult::success_with_data(
                result_message,
                serde_json::json!({
                    "line_number": line_number,
                    "file": current_file,
                    "window": display
                }),
            ))
        } else {
            Err(anyhow::anyhow!("Failed to get file state"))
        }
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "line_number": {
                    "type": "integer",
                    "description": "The line number to move the window to",
                    "minimum": 1
                }
            },
            "required": ["line_number"]
        })
    }
}

/// Tool for scrolling within files
pub struct ScrollTool {
    name: String,
    up: bool, // true for scroll_up, false for scroll_down
}

impl ScrollTool {
    pub fn new(name: &str, up: bool) -> Self {
        Self {
            name: name.to_string(),
            up,
        }
    }
}

impl Tool for ScrollTool {
    fn name(&self) -> &str {
        &self.name
    }

    fn description(&self) -> &str {
        if self.up {
            "Moves the window up by the window size"
        } else {
            "Moves the window down by the window size"
        }
    }

    fn signature(&self) -> &str {
        &self.name
    }

    fn validate_args(&self, _args: &ToolArgs) -> Result<(), ToolError> {
        Ok(()) // Scroll tools take no arguments
    }

    fn execute(&mut self, _args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let mut state_guard = state
            .lock()
            .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;

        // Check if there's a current file
        let current_file = state_guard
            .current_file
            .clone()
            .ok_or_else(|| anyhow::anyhow!("No file is currently open. Use 'open' first."))?;

        if let Some(file_state) = state_guard.get_current_file_state_mut() {
            let old_start = file_state.window_start;

            if self.up {
                if file_state.is_at_start() {
                    return Ok(ToolResult::success("Already at the beginning of the file"));
                }
                file_state.scroll_up();
            } else {
                if file_state.is_at_end() {
                    return Ok(ToolResult::success("Already at the end of the file"));
                }
                file_state.scroll_down();
            }

            let new_start = file_state.window_start;
            let display = file_state.get_window_with_line_numbers();

            let direction = if self.up { "up" } else { "down" };
            state_guard.push_history(format!(
                "Scrolled {} in {}",
                direction,
                current_file.display()
            ));

            let result_message = format!(
                "Scrolled {} from line {} to line {} in {}\n\n{}",
                direction,
                old_start + 1,
                new_start + 1,
                current_file.display(),
                display.join("\n")
            );

            Ok(ToolResult::success_with_data(
                result_message,
                serde_json::json!({
                    "direction": direction,
                    "old_start": old_start + 1,
                    "new_start": new_start + 1,
                    "file": current_file,
                    "window": display
                }),
            ))
        } else {
            Err(anyhow::anyhow!("Failed to get file state"))
        }
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {},
            "required": []
        })
    }
}

/// Tool for creating new files
pub struct CreateTool {
    name: String,
}

impl CreateTool {
    pub fn new() -> Self {
        Self {
            name: "create".to_string(),
        }
    }
}

impl Tool for CreateTool {
    fn name(&self) -> &str {
        &self.name
    }

    fn description(&self) -> &str {
        "Creates and opens a new file with the given name"
    }

    fn signature(&self) -> &str {
        "create <filename>"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        if args.is_empty() {
            return Err(ToolError::InvalidArgs {
                message: "Usage: create <filename>".to_string(),
            });
        }
        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let filename = args.get_arg(0).unwrap();
        let path_buf = PathBuf::from(filename);

        // Check if file already exists
        if path_buf.exists() {
            return Ok(ToolResult::error(format!(
                "File already exists: {}",
                filename
            )));
        }

        // Create the file
        fs::write(&path_buf, "").map_err(|e| anyhow::anyhow!("Failed to create file: {}", e))?;

        // Open the new file
        let content = vec![]; // Empty file

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            state_guard.open_file(path_buf.clone(), content.clone(), DEFAULT_WINDOW_SIZE)?;
            state_guard.push_history(format!("Created file: {}", filename));
        }

        // Create windowed file for display
        let windowed_file = WindowedFile::from_content(path_buf, content, None);
        let display = windowed_file.get_window_display();

        Ok(ToolResult::success_with_data(
            format!("Created and opened file: {}", filename),
            serde_json::json!({
                "path": filename,
                "display": display,
                "created": true
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "filename": {
                    "type": "string",
                    "description": "The name of the file to create"
                }
            },
            "required": ["filename"]
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::io::Write;
    use tempfile::TempDir;

    fn create_test_file(dir: &TempDir, name: &str, content: &str) -> PathBuf {
        let file_path = dir.path().join(name);
        let mut file = fs::File::create(&file_path).unwrap();
        writeln!(file, "{}", content).unwrap();
        file_path
    }

    #[test]
    fn test_windowed_file_creation() {
        let temp_dir = TempDir::new().unwrap();
        let test_content = "line1\nline2\nline3\nline4\nline5";
        let file_path = create_test_file(&temp_dir, "test.txt", test_content);

        let windowed_file = WindowedFile::new(file_path, Some(3)).unwrap();
        assert_eq!(windowed_file.content.len(), 5);
        assert_eq!(windowed_file.window_size, 3);
        assert_eq!(windowed_file.window_start, 0);
    }

    #[test]
    fn test_open_tool() {
        let temp_dir = TempDir::new().unwrap();
        let test_content = "line1\nline2\nline3";
        let file_path = create_test_file(&temp_dir, "test.txt", test_content);

        let mut tool = OpenTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));
        let args = ToolArgs::from_args(&[file_path.to_str().unwrap()]);

        let result = tool.execute(&args, &state).unwrap();
        assert!(result.success);

        // Verify state was updated
        let state_guard = state.lock().unwrap();
        assert!(state_guard.current_file.is_some());
        assert_eq!(state_guard.open_files.len(), 1);
    }

    #[test]
    fn test_goto_tool() {
        let mut tool = GotoTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));

        // Test with no file open
        let args = ToolArgs::from_args(&["5"]);
        let result = tool.execute(&args, &state);
        assert!(result.is_err());

        // Open a file first
        let content: Vec<String> = (1..=10).map(|i| format!("line {}", i)).collect();
        {
            let mut state_guard = state.lock().unwrap();
            state_guard
                .open_file(PathBuf::from("test.txt"), content, DEFAULT_WINDOW_SIZE)
                .unwrap();
        }

        // Now test goto
        let result = tool.execute(&args, &state).unwrap();
        assert!(result.success);
    }

    #[test]
    fn test_open_tool_with_configured_window() {
        // Create a temporary file to test configured window size (hermetic test)
        let temp_dir = TempDir::new().unwrap();
        let test_content = "line1\nline2\nline3\nline4";
        let file_path = create_test_file(&temp_dir, "test_agent.rs", test_content);

        let mut tool = OpenTool::new_with_open_window_size(Some(1000));
        let state = Arc::new(Mutex::new(ToolState::new()));

        let args = ToolArgs::from_args(&[file_path.to_str().unwrap()]);
        let result = tool.execute(&args, &state).unwrap();
        assert!(result.success);

        let state_guard = state.lock().unwrap();
        let file_state = state_guard
            .get_current_file_state()
            .expect("file should be open");
        assert_eq!(
            file_state.window_size, 1000,
            "Open tool should set window size to configured value"
        );
    }

    #[test]
    fn test_scroll_tools() {
        let mut up_tool = ScrollTool::new("scroll_up", true);
        let mut down_tool = ScrollTool::new("scroll_down", false);
        let state = Arc::new(Mutex::new(ToolState::new()));

        // Open a file with enough content to scroll
        let content: Vec<String> = (1..=200).map(|i| format!("line {}", i)).collect();
        {
            let mut state_guard = state.lock().unwrap();
            state_guard
                .open_file(PathBuf::from("test.txt"), content, 50)
                .unwrap();
        }

        let args = ToolArgs::from_args(&[]);

        // Test scroll down
        let result = down_tool.execute(&args, &state).unwrap();
        assert!(result.success);

        // Test scroll up
        let result = up_tool.execute(&args, &state).unwrap();
        assert!(result.success);
    }

    #[test]
    fn test_create_tool() {
        let temp_dir = TempDir::new().unwrap();
        std::env::set_current_dir(temp_dir.path()).unwrap();

        let mut tool = CreateTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));
        let args = ToolArgs::from_args(&["new_file.txt"]);

        let result = tool.execute(&args, &state).unwrap();
        assert!(result.success);

        // Verify file was created
        assert!(PathBuf::from("new_file.txt").exists());

        // Verify state was updated
        let state_guard = state.lock().unwrap();
        assert!(state_guard.current_file.is_some());
    }
}