cats 0.1.18

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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
//! File management tools for file operations
//!
//! This module provides tools for file and directory management operations
//! like delete, move, and copy with simple interfaces.

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

/// Tool for deleting files or directories
pub struct DeletePathTool {
    name: String,
}

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

    /// Parse parameters from ToolArgs
    fn parse_params(&self, args: &ToolArgs) -> Result<serde_json::Value, ToolError> {
        // Try to parse as JSON first
        if let Some(json_str) = args.get_named_arg("json") {
            return serde_json::from_str(json_str).map_err(|e| ToolError::Json(e));
        }

        // Check if we have structured named arguments
        if !args.named_args.is_empty() {
            return Ok(serde_json::to_value(&args.named_args).map_err(|e| ToolError::Json(e))?);
        }

        // Fall back to positional arguments for backward compatibility
        if args.len() >= 1 {
            let mut params = serde_json::Map::new();
            params.insert(
                "path".to_string(),
                serde_json::Value::String(args.get_arg(0).unwrap().clone()),
            );

            if args.len() >= 2 {
                if let Ok(recursive) = args.get_arg(1).unwrap().parse::<bool>() {
                    params.insert("recursive".to_string(), serde_json::Value::Bool(recursive));
                }
            }

            return Ok(serde_json::Value::Object(params));
        }

        Err(ToolError::InvalidArgs {
            message: "Insufficient parameters".to_string(),
        })
    }
}

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

    fn description(&self) -> &str {
        "Delete a file or directory"
    }

    fn signature(&self) -> &str {
        "delete_path(path: str, recursive?: bool)"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        let params = self.parse_params(args)?;

        let obj = params.as_object().ok_or_else(|| ToolError::InvalidArgs {
            message: "Parameters must be an object".to_string(),
        })?;

        if !obj.contains_key("path") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: path".to_string(),
            });
        }

        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let params = self.parse_params(args)?;
        let obj = params
            .as_object()
            .ok_or_else(|| anyhow::anyhow!("Invalid parameters"))?;

        let path_str = obj
            .get("path")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid path parameter"))?;

        let recursive = obj
            .get("recursive")
            .and_then(|v| v.as_bool())
            .unwrap_or(false);

        let path = PathBuf::from(path_str);

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

        let is_dir = path.is_dir();
        let is_file = path.is_file();

        // Safety check for important directories
        let path_name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");

        // Use centralized filter configuration for protected directories instead of a hardcoded list.
        // Always protect "src" by default, and also protect any directory listed in the search filtering exclude_dirs.
        let filter = crate::tools::old::search::ConfigurableFilter::new(None);
        let mut protected = false;

        if path_name == "src" {
            protected = true;
        }

        if !protected {
            if let Some(ex_dirs) = &filter.config.exclude_dirs {
                if ex_dirs.iter().any(|d| d == path_name) {
                    protected = true;
                }
            }
        }

        if is_dir && protected {
            return Ok(ToolResult::error(format!(
                "Safety check: Refusing to delete important directory '{}'. Use recursive=true explicitly if needed.",
                path_name
            )));
        }

        // Perform the deletion
        if is_file {
            fs::remove_file(&path).map_err(|e| anyhow::anyhow!("Failed to delete file: {}", e))?;
        } else if is_dir {
            if recursive {
                fs::remove_dir_all(&path)
                    .map_err(|e| anyhow::anyhow!("Failed to delete directory: {}", e))?;
            } else {
                // Try to remove empty directory
                fs::remove_dir(&path)
                    .map_err(|e| anyhow::anyhow!("Failed to delete directory (not empty?): {}. Use recursive=true for non-empty directories.", e))?;
            }
        }

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            // If we deleted the currently open file, clear it from state
            if state_guard.current_file.as_ref() == Some(&path) {
                state_guard.current_file = None;
            }
            state_guard.push_history(format!(
                "Deleted {}: {}",
                if is_dir { "directory" } else { "file" },
                path.display()
            ));
        }

        Ok(ToolResult::success_with_data(
            format!(
                "Successfully deleted {}: {}",
                if is_dir { "directory" } else { "file" },
                path.display()
            ),
            serde_json::json!({
                "path": path.to_string_lossy(),
                "type": if is_dir { "directory" } else { "file" },
                "recursive": recursive,
                "deleted": true
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "Full path to the file or directory to delete"
                },
                "recursive": {
                    "type": "boolean",
                    "description": "Whether to delete directories and their contents recursively",
                    "default": false
                }
            },
            "required": ["path"]
        })
    }
}

/// Tool for moving/renaming files or directories
pub struct MovePathTool {
    name: String,
}

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

    /// Parse parameters from ToolArgs
    fn parse_params(&self, args: &ToolArgs) -> Result<serde_json::Value, ToolError> {
        // Try to parse as JSON first
        if let Some(json_str) = args.get_named_arg("json") {
            return serde_json::from_str(json_str).map_err(|e| ToolError::Json(e));
        }

        // Check if we have structured named arguments
        if !args.named_args.is_empty() {
            return Ok(serde_json::to_value(&args.named_args).map_err(|e| ToolError::Json(e))?);
        }

        // Fall back to positional arguments for backward compatibility
        if args.len() >= 2 {
            let mut params = serde_json::Map::new();
            params.insert(
                "source".to_string(),
                serde_json::Value::String(args.get_arg(0).unwrap().clone()),
            );
            params.insert(
                "destination".to_string(),
                serde_json::Value::String(args.get_arg(1).unwrap().clone()),
            );
            return Ok(serde_json::Value::Object(params));
        }

        Err(ToolError::InvalidArgs {
            message: "Insufficient parameters".to_string(),
        })
    }
}

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

    fn description(&self) -> &str {
        "Move or rename a file or directory"
    }

    fn signature(&self) -> &str {
        "move_path(source: str, destination: str)"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        let params = self.parse_params(args)?;

        let obj = params.as_object().ok_or_else(|| ToolError::InvalidArgs {
            message: "Parameters must be an object".to_string(),
        })?;

        if !obj.contains_key("source") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: source".to_string(),
            });
        }

        if !obj.contains_key("destination") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: destination".to_string(),
            });
        }

        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let params = self.parse_params(args)?;
        let obj = params
            .as_object()
            .ok_or_else(|| anyhow::anyhow!("Invalid parameters"))?;

        let source_str = obj
            .get("source")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid source parameter"))?;

        let dest_str = obj
            .get("destination")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid destination parameter"))?;

        let source = PathBuf::from(source_str);
        let destination = PathBuf::from(dest_str);

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

        // Check if destination already exists
        if destination.exists() {
            return Ok(ToolResult::error(format!(
                "Destination already exists: {}",
                destination.display()
            )));
        }

        // Create parent directories for destination if needed
        if let Some(parent) = destination.parent() {
            fs::create_dir_all(parent).map_err(|e| {
                anyhow::anyhow!("Failed to create destination parent directories: {}", e)
            })?;
        }

        let is_dir = source.is_dir();

        // Perform the move
        fs::rename(&source, &destination)
            .map_err(|e| anyhow::anyhow!("Failed to move path: {}", e))?;

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            // If we moved the currently open file, update the path in state
            if state_guard.current_file.as_ref() == Some(&source) {
                state_guard.current_file = Some(destination.clone());
            }
            state_guard.push_history(format!(
                "Moved {} from {} to {}",
                if is_dir { "directory" } else { "file" },
                source.display(),
                destination.display()
            ));
        }

        Ok(ToolResult::success_with_data(
            format!(
                "Successfully moved {} from {} to {}",
                if is_dir { "directory" } else { "file" },
                source.display(),
                destination.display()
            ),
            serde_json::json!({
                "source": source.to_string_lossy(),
                "destination": destination.to_string_lossy(),
                "type": if is_dir { "directory" } else { "file" },
                "moved": true
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "source": {
                    "type": "string",
                    "description": "Full path to the source file or directory"
                },
                "destination": {
                    "type": "string",
                    "description": "Full path to the destination"
                }
            },
            "required": ["source", "destination"]
        })
    }
}

/// Tool for copying files or directories
pub struct CopyPathTool {
    name: String,
}

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

    /// Parse parameters from ToolArgs
    fn parse_params(&self, args: &ToolArgs) -> Result<serde_json::Value, ToolError> {
        // Try to parse as JSON first
        if let Some(json_str) = args.get_named_arg("json") {
            return serde_json::from_str(json_str).map_err(|e| ToolError::Json(e));
        }

        // Check if we have structured named arguments
        if !args.named_args.is_empty() {
            return Ok(serde_json::to_value(&args.named_args).map_err(|e| ToolError::Json(e))?);
        }

        // Fall back to positional arguments for backward compatibility
        if args.len() >= 2 {
            let mut params = serde_json::Map::new();
            params.insert(
                "source".to_string(),
                serde_json::Value::String(args.get_arg(0).unwrap().clone()),
            );
            params.insert(
                "destination".to_string(),
                serde_json::Value::String(args.get_arg(1).unwrap().clone()),
            );

            if args.len() >= 3 {
                if let Ok(recursive) = args.get_arg(2).unwrap().parse::<bool>() {
                    params.insert("recursive".to_string(), serde_json::Value::Bool(recursive));
                }
            }

            return Ok(serde_json::Value::Object(params));
        }

        Err(ToolError::InvalidArgs {
            message: "Insufficient parameters".to_string(),
        })
    }
}

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

    fn description(&self) -> &str {
        "Copy a file or directory"
    }

    fn signature(&self) -> &str {
        "copy_path(source: str, destination: str, recursive?: bool)"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        let params = self.parse_params(args)?;

        let obj = params.as_object().ok_or_else(|| ToolError::InvalidArgs {
            message: "Parameters must be an object".to_string(),
        })?;

        if !obj.contains_key("source") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: source".to_string(),
            });
        }

        if !obj.contains_key("destination") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: destination".to_string(),
            });
        }

        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let params = self.parse_params(args)?;
        let obj = params
            .as_object()
            .ok_or_else(|| anyhow::anyhow!("Invalid parameters"))?;

        let source_str = obj
            .get("source")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid source parameter"))?;

        let dest_str = obj
            .get("destination")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid destination parameter"))?;

        let recursive = obj
            .get("recursive")
            .and_then(|v| v.as_bool())
            .unwrap_or(true); // Default to true for directories

        let source = PathBuf::from(source_str);
        let destination = PathBuf::from(dest_str);

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

        // Check if destination already exists
        if destination.exists() {
            return Ok(ToolResult::error(format!(
                "Destination already exists: {}",
                destination.display()
            )));
        }

        let is_dir = source.is_dir();
        let is_file = source.is_file();

        // Create parent directories for destination if needed
        if let Some(parent) = destination.parent() {
            fs::create_dir_all(parent).map_err(|e| {
                anyhow::anyhow!("Failed to create destination parent directories: {}", e)
            })?;
        }

        if is_file {
            // Copy file
            fs::copy(&source, &destination)
                .map_err(|e| anyhow::anyhow!("Failed to copy file: {}", e))?;
        } else if is_dir {
            if !recursive {
                return Ok(ToolResult::error(
                    "Cannot copy directory without recursive=true".to_string(),
                ));
            }

            // Copy directory recursively
            self.copy_dir_recursive(&source, &destination)
                .map_err(|e| anyhow::anyhow!("Failed to copy directory: {}", e))?;
        }

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            state_guard.push_history(format!(
                "Copied {} from {} to {}",
                if is_dir { "directory" } else { "file" },
                source.display(),
                destination.display()
            ));
        }

        Ok(ToolResult::success_with_data(
            format!(
                "Successfully copied {} from {} to {}",
                if is_dir { "directory" } else { "file" },
                source.display(),
                destination.display()
            ),
            serde_json::json!({
                "source": source.to_string_lossy(),
                "destination": destination.to_string_lossy(),
                "type": if is_dir { "directory" } else { "file" },
                "recursive": recursive,
                "copied": true
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "source": {
                    "type": "string",
                    "description": "Full path to the source file or directory"
                },
                "destination": {
                    "type": "string",
                    "description": "Full path to the destination"
                },
                "recursive": {
                    "type": "boolean",
                    "description": "Whether to copy directories recursively",
                    "default": true
                }
            },
            "required": ["source", "destination"]
        })
    }
}

impl CopyPathTool {
    /// Recursively copy directory contents
    fn copy_dir_recursive(&self, source: &PathBuf, destination: &PathBuf) -> Result<()> {
        // Create the destination directory
        fs::create_dir_all(destination)?;

        // Copy all entries
        for entry in fs::read_dir(source)? {
            let entry = entry?;
            let entry_path = entry.path();
            let entry_name = entry.file_name();
            let dest_path = destination.join(entry_name);

            if entry_path.is_dir() {
                // Recursively copy subdirectory
                self.copy_dir_recursive(&entry_path, &dest_path)?;
            } else {
                // Copy file
                fs::copy(&entry_path, &dest_path)?;
            }
        }

        Ok(())
    }
}

/// Tool for creating directories
pub struct CreateDirectoryTool {
    name: String,
}

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

    /// Parse parameters from ToolArgs
    fn parse_params(&self, args: &ToolArgs) -> Result<serde_json::Value, ToolError> {
        // Try to parse as JSON first
        if let Some(json_str) = args.get_named_arg("json") {
            return serde_json::from_str(json_str).map_err(|e| ToolError::Json(e));
        }

        // Check if we have structured named arguments
        if !args.named_args.is_empty() {
            return Ok(serde_json::to_value(&args.named_args).map_err(|e| ToolError::Json(e))?);
        }

        // Fall back to positional arguments for backward compatibility
        if args.len() >= 1 {
            let mut params = serde_json::Map::new();
            params.insert(
                "path".to_string(),
                serde_json::Value::String(args.get_arg(0).unwrap().clone()),
            );
            return Ok(serde_json::Value::Object(params));
        }

        Err(ToolError::InvalidArgs {
            message: "Insufficient parameters".to_string(),
        })
    }
}

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

    fn description(&self) -> &str {
        "Create a new directory (and parent directories if needed)"
    }

    fn signature(&self) -> &str {
        "create_directory(path: str)"
    }

    fn validate_args(&self, args: &ToolArgs) -> Result<(), ToolError> {
        let params = self.parse_params(args)?;

        let obj = params.as_object().ok_or_else(|| ToolError::InvalidArgs {
            message: "Parameters must be an object".to_string(),
        })?;

        if !obj.contains_key("path") {
            return Err(ToolError::InvalidArgs {
                message: "Missing required parameter: path".to_string(),
            });
        }

        Ok(())
    }

    fn execute(&mut self, args: &ToolArgs, state: &Arc<Mutex<ToolState>>) -> Result<ToolResult> {
        let params = self.parse_params(args)?;
        let obj = params
            .as_object()
            .ok_or_else(|| anyhow::anyhow!("Invalid parameters"))?;

        let path_str = obj
            .get("path")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow::anyhow!("Invalid path parameter"))?;

        let path = PathBuf::from(path_str);

        // Check if directory already exists
        if path.exists() {
            return Ok(ToolResult::error(format!(
                "Directory already exists: {}",
                path.display()
            )));
        }

        // Create the directory (and parents)
        fs::create_dir_all(&path)
            .map_err(|e| anyhow::anyhow!("Failed to create directory: {}", e))?;

        // Update state
        {
            let mut state_guard = state
                .lock()
                .map_err(|e| anyhow::anyhow!("Failed to lock state: {}", e))?;
            state_guard.push_history(format!("Created directory: {}", path.display()));
        }

        Ok(ToolResult::success_with_data(
            format!("Successfully created directory: {}", path.display()),
            serde_json::json!({
                "path": path.to_string_lossy(),
                "type": "directory",
                "created": true
            }),
        ))
    }

    fn get_parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "Full path to the directory to create"
                }
            },
            "required": ["path"]
        })
    }
}

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

    #[test]
    fn test_delete_path_tool_file() {
        let temp_dir = TempDir::new().unwrap();

        // Create test file with absolute path
        let test_file = temp_dir.path().join("test_delete.txt");
        fs::write(&test_file, "test content").unwrap();

        let mut tool = DeletePathTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));

        let args = ToolArgs::with_named_args(
            vec![],
            vec![("path".to_string(), test_file.to_string_lossy().to_string())]
                .into_iter()
                .collect(),
        );

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

        // Verify file was deleted
        assert!(!test_file.exists());
    }

    #[test]
    fn test_move_path_tool() {
        let temp_dir = TempDir::new().unwrap();

        // Create test file with absolute path
        let source = temp_dir.path().join("source.txt");
        fs::write(&source, "test content").unwrap();
        let destination = temp_dir.path().join("destination.txt");

        let mut tool = MovePathTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));

        let args = ToolArgs::with_named_args(
            vec![],
            vec![
                ("source".to_string(), source.to_string_lossy().to_string()),
                (
                    "destination".to_string(),
                    destination.to_string_lossy().to_string(),
                ),
            ]
            .into_iter()
            .collect(),
        );

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

        // Verify file was moved
        assert!(!source.exists());
        assert!(destination.exists());

        let content = fs::read_to_string(&destination).unwrap();
        assert_eq!(content, "test content");
    }

    #[test]
    fn test_copy_path_tool() {
        let temp_dir = TempDir::new().unwrap();

        // Create test file with absolute path
        let source = temp_dir.path().join("source.txt");
        fs::write(&source, "test content").unwrap();
        let destination = temp_dir.path().join("copy.txt");

        let mut tool = CopyPathTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));

        let args = ToolArgs::with_named_args(
            vec![],
            vec![
                ("source".to_string(), source.to_string_lossy().to_string()),
                (
                    "destination".to_string(),
                    destination.to_string_lossy().to_string(),
                ),
            ]
            .into_iter()
            .collect(),
        );

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

        // Verify file was copied
        assert!(source.exists());
        assert!(destination.exists());

        let content = fs::read_to_string(&destination).unwrap();
        assert_eq!(content, "test content");
    }

    #[test]
    fn test_create_directory_tool() {
        let temp_dir = TempDir::new().unwrap();

        let mut tool = CreateDirectoryTool::new();
        let state = Arc::new(Mutex::new(ToolState::new()));

        // Use absolute path for the directory to be created
        let dir_path = temp_dir.path().join("new_dir/sub_dir");

        let args = ToolArgs::with_named_args(
            vec![],
            vec![("path".to_string(), dir_path.to_string_lossy().to_string())]
                .into_iter()
                .collect(),
        );

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

        // Verify directory was created
        assert!(dir_path.exists());
        assert!(dir_path.is_dir());
    }
}