claude-codes 2.1.117

A tightly typed Rust interface for the Claude Code JSON protocol
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
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
//! Typed tool input definitions for Claude Code tools.
//!
//! This module provides strongly-typed structs for the input parameters of each
//! Claude Code tool. Using these types instead of raw `serde_json::Value` provides:
//!
//! - Compile-time type checking
//! - IDE autocompletion and documentation
//! - Self-documenting API
//!
//! # Example
//!
//! ```
//! use claude_codes::{ToolInput, BashInput};
//!
//! // Parse a tool input from JSON
//! let json = serde_json::json!({
//!     "command": "ls -la",
//!     "description": "List files in current directory"
//! });
//!
//! let input: ToolInput = serde_json::from_value(json).unwrap();
//! if let ToolInput::Bash(bash) = input {
//!     assert_eq!(bash.command, "ls -la");
//! }
//! ```

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
use std::collections::HashMap;
use std::fmt;

// ============================================================================
// Individual Tool Input Structs
// ============================================================================

/// Input for the Bash tool - executes shell commands.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BashInput {
    /// The bash command to execute (required)
    pub command: String,

    /// Human-readable description of what the command does
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Timeout in milliseconds (max 600000)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout: Option<u64>,

    /// Whether to run the command in the background
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_in_background: Option<bool>,
}

/// Input for the Read tool - reads file contents.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ReadInput {
    /// The absolute path to the file to read
    pub file_path: String,

    /// The line number to start reading from (1-indexed)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,

    /// The number of lines to read
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}

/// Input for the Write tool - writes content to a file.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WriteInput {
    /// The absolute path to the file to write
    pub file_path: String,

    /// The content to write to the file
    pub content: String,
}

/// Input for the Edit tool - performs string replacements in files.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct EditInput {
    /// The absolute path to the file to modify
    pub file_path: String,

    /// The text to replace
    pub old_string: String,

    /// The text to replace it with
    pub new_string: String,

    /// Replace all occurrences of old_string (default false)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replace_all: Option<bool>,
}

/// Input for the Glob tool - finds files matching a pattern.
///
/// The `deny_unknown_fields` attribute ensures Glob only matches exact
/// Glob inputs and doesn't accidentally match Grep inputs (which share
/// the `pattern` field but have additional Grep-specific fields).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct GlobInput {
    /// The glob pattern to match files against (e.g., "**/*.rs")
    pub pattern: String,

    /// The directory to search in (defaults to current working directory)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
}

/// Input for the Grep tool - searches file contents.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GrepInput {
    /// The regular expression pattern to search for
    pub pattern: String,

    /// File or directory to search in
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,

    /// Glob pattern to filter files (e.g., "*.js")
    #[serde(skip_serializing_if = "Option::is_none")]
    pub glob: Option<String>,

    /// File type to search (e.g., "js", "py", "rust")
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub file_type: Option<String>,

    /// Case insensitive search
    #[serde(rename = "-i", skip_serializing_if = "Option::is_none")]
    pub case_insensitive: Option<bool>,

    /// Show line numbers in output
    #[serde(rename = "-n", skip_serializing_if = "Option::is_none")]
    pub line_numbers: Option<bool>,

    /// Number of lines to show after each match
    #[serde(rename = "-A", skip_serializing_if = "Option::is_none")]
    pub after_context: Option<u32>,

    /// Number of lines to show before each match
    #[serde(rename = "-B", skip_serializing_if = "Option::is_none")]
    pub before_context: Option<u32>,

    /// Number of lines to show before and after each match
    #[serde(rename = "-C", skip_serializing_if = "Option::is_none")]
    pub context: Option<u32>,

    /// Output mode: content, files_with_matches, or count
    #[serde(skip_serializing_if = "Option::is_none")]
    pub output_mode: Option<GrepOutputMode>,

    /// Enable multiline mode
    #[serde(skip_serializing_if = "Option::is_none")]
    pub multiline: Option<bool>,

    /// Limit output to first N lines/entries
    #[serde(skip_serializing_if = "Option::is_none")]
    pub head_limit: Option<u32>,

    /// Skip first N lines/entries
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// Input for the Task tool - launches subagents.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TaskInput {
    /// A short (3-5 word) description of the task
    pub description: String,

    /// The task for the agent to perform
    pub prompt: String,

    /// The type of specialized agent to use
    pub subagent_type: SubagentType,

    /// Whether to run the agent in the background
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_in_background: Option<bool>,

    /// Optional model to use for this agent
    #[serde(skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,

    /// Maximum number of agentic turns
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_turns: Option<u32>,

    /// Optional agent ID to resume from
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resume: Option<String>,
}

/// Input for the WebFetch tool - fetches and processes web content.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WebFetchInput {
    /// The URL to fetch content from
    pub url: String,

    /// The prompt to run on the fetched content
    pub prompt: String,
}

/// Input for the WebSearch tool - searches the web.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WebSearchInput {
    /// The search query to use
    pub query: String,

    /// Only include search results from these domains
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allowed_domains: Option<Vec<String>>,

    /// Never include search results from these domains
    #[serde(skip_serializing_if = "Option::is_none")]
    pub blocked_domains: Option<Vec<String>>,
}

/// Input for the TodoWrite tool - manages task lists.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TodoWriteInput {
    /// The updated todo list
    pub todos: Vec<TodoItem>,
}

/// Status of a todo item.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TodoStatus {
    Pending,
    InProgress,
    Completed,
    /// A status not yet known to this version of the crate.
    Unknown(String),
}

impl TodoStatus {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Pending => "pending",
            Self::InProgress => "in_progress",
            Self::Completed => "completed",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for TodoStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for TodoStatus {
    fn from(s: &str) -> Self {
        match s {
            "pending" => Self::Pending,
            "in_progress" => Self::InProgress,
            "completed" => Self::Completed,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl Serialize for TodoStatus {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for TodoStatus {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s.as_str()))
    }
}

/// Output mode for the Grep tool.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GrepOutputMode {
    /// Show matching lines with context.
    Content,
    /// Show only file paths containing matches.
    FilesWithMatches,
    /// Show match counts per file.
    Count,
    /// A mode not yet known to this version of the crate.
    Unknown(String),
}

impl GrepOutputMode {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Content => "content",
            Self::FilesWithMatches => "files_with_matches",
            Self::Count => "count",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for GrepOutputMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for GrepOutputMode {
    fn from(s: &str) -> Self {
        match s {
            "content" => Self::Content,
            "files_with_matches" => Self::FilesWithMatches,
            "count" => Self::Count,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl Serialize for GrepOutputMode {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for GrepOutputMode {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s.as_str()))
    }
}

/// Type of specialized subagent for the Task tool.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SubagentType {
    /// Command execution specialist.
    Bash,
    /// Fast codebase exploration agent.
    Explore,
    /// Software architect agent for planning.
    Plan,
    /// General-purpose agent.
    GeneralPurpose,
    /// A subagent type not yet known to this version of the crate.
    Unknown(String),
}

impl SubagentType {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Bash => "Bash",
            Self::Explore => "Explore",
            Self::Plan => "Plan",
            Self::GeneralPurpose => "general-purpose",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for SubagentType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for SubagentType {
    fn from(s: &str) -> Self {
        match s {
            "Bash" => Self::Bash,
            "Explore" => Self::Explore,
            "Plan" => Self::Plan,
            "general-purpose" => Self::GeneralPurpose,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl Serialize for SubagentType {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for SubagentType {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s.as_str()))
    }
}

/// Type of Jupyter notebook cell.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NotebookCellType {
    /// Code cell.
    Code,
    /// Markdown cell.
    Markdown,
    /// A cell type not yet known to this version of the crate.
    Unknown(String),
}

impl NotebookCellType {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Code => "code",
            Self::Markdown => "markdown",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for NotebookCellType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for NotebookCellType {
    fn from(s: &str) -> Self {
        match s {
            "code" => Self::Code,
            "markdown" => Self::Markdown,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl Serialize for NotebookCellType {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for NotebookCellType {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s.as_str()))
    }
}

/// Type of edit to perform on a notebook cell.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NotebookEditMode {
    /// Replace the cell's content.
    Replace,
    /// Insert a new cell.
    Insert,
    /// Delete the cell.
    Delete,
    /// An edit mode not yet known to this version of the crate.
    Unknown(String),
}

impl NotebookEditMode {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Replace => "replace",
            Self::Insert => "insert",
            Self::Delete => "delete",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for NotebookEditMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for NotebookEditMode {
    fn from(s: &str) -> Self {
        match s {
            "replace" => Self::Replace,
            "insert" => Self::Insert,
            "delete" => Self::Delete,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl Serialize for NotebookEditMode {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for NotebookEditMode {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s.as_str()))
    }
}

/// A single todo item in a task list.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TodoItem {
    /// The task description (imperative form)
    pub content: String,

    /// Current status
    pub status: TodoStatus,

    /// The present continuous form shown during execution
    #[serde(rename = "activeForm")]
    pub active_form: String,
}

/// Input for the AskUserQuestion tool - asks the user questions.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AskUserQuestionInput {
    /// Questions to ask the user (1-4 questions)
    pub questions: Vec<Question>,

    /// User answers collected by the permission component
    #[serde(skip_serializing_if = "Option::is_none")]
    pub answers: Option<HashMap<String, String>>,

    /// Optional metadata for tracking and analytics
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<QuestionMetadata>,
}

/// A question to ask the user.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Question {
    /// The complete question to ask the user
    pub question: String,

    /// Very short label displayed as a chip/tag (max 12 chars)
    pub header: String,

    /// The available choices for this question (2-4 options)
    pub options: Vec<QuestionOption>,

    /// Whether multiple options can be selected
    #[serde(rename = "multiSelect", default)]
    pub multi_select: bool,
}

/// An option for a question.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct QuestionOption {
    /// The display text for this option
    pub label: String,

    /// Explanation of what this option means
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

/// Metadata for questions.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct QuestionMetadata {
    /// Optional identifier for the source of this question
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<String>,
}

/// Input for the NotebookEdit tool - edits Jupyter notebooks.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NotebookEditInput {
    /// The absolute path to the Jupyter notebook file
    pub notebook_path: String,

    /// The new source for the cell
    pub new_source: String,

    /// The ID of the cell to edit
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cell_id: Option<String>,

    /// The type of the cell (code or markdown)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cell_type: Option<NotebookCellType>,

    /// The type of edit to make (replace, insert, delete)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub edit_mode: Option<NotebookEditMode>,
}

/// Input for the TaskOutput tool - retrieves output from background tasks.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TaskOutputInput {
    /// The task ID to get output from
    pub task_id: String,

    /// Whether to wait for completion (default true)
    #[serde(default = "default_true")]
    pub block: bool,

    /// Max wait time in ms (default 30000, max 600000)
    #[serde(default = "default_timeout")]
    pub timeout: u64,
}

fn default_true() -> bool {
    true
}

fn default_timeout() -> u64 {
    30000
}

/// Input for the KillShell tool - kills a running background shell.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct KillShellInput {
    /// The ID of the background shell to kill
    pub shell_id: String,
}

/// Input for the Skill tool - executes a skill.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SkillInput {
    /// The skill name (e.g., "commit", "review-pr")
    pub skill: String,

    /// Optional arguments for the skill
    #[serde(skip_serializing_if = "Option::is_none")]
    pub args: Option<String>,
}

/// Input for the EnterPlanMode tool - enters planning mode.
///
/// This is an empty struct as EnterPlanMode takes no parameters.
/// The `deny_unknown_fields` attribute ensures this only matches
/// empty JSON objects `{}`, not arbitrary JSON.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct EnterPlanModeInput {}

/// Input for the ExitPlanMode tool - exits planning mode.
///
/// The `deny_unknown_fields` attribute ensures this only matches JSON objects
/// that contain known fields (or are empty), not arbitrary JSON.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct ExitPlanModeInput {
    /// Prompt-based permissions needed to implement the plan
    #[serde(rename = "allowedPrompts", skip_serializing_if = "Option::is_none")]
    pub allowed_prompts: Option<Vec<AllowedPrompt>>,

    /// Whether to push the plan to a remote Claude.ai session
    #[serde(rename = "pushToRemote", skip_serializing_if = "Option::is_none")]
    pub push_to_remote: Option<bool>,

    /// The remote session ID if pushed to remote
    #[serde(rename = "remoteSessionId", skip_serializing_if = "Option::is_none")]
    pub remote_session_id: Option<String>,

    /// The remote session URL if pushed to remote
    #[serde(rename = "remoteSessionUrl", skip_serializing_if = "Option::is_none")]
    pub remote_session_url: Option<String>,

    /// The remote session title if pushed to remote
    #[serde(rename = "remoteSessionTitle", skip_serializing_if = "Option::is_none")]
    pub remote_session_title: Option<String>,

    /// The plan content from plan mode
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan: Option<String>,
}

/// An allowed prompt permission for plan mode.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AllowedPrompt {
    /// The tool this prompt applies to
    pub tool: String,

    /// Semantic description of the action
    pub prompt: String,
}

/// Input for the MultiEdit tool - batch file edits.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MultiEditInput {
    /// The absolute path to the file to modify
    pub file_path: String,

    /// Array of edit operations to apply
    pub edits: Vec<MultiEditOperation>,
}

/// A single edit operation within a MultiEdit.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MultiEditOperation {
    /// The text to replace
    pub old_string: String,

    /// The text to replace it with
    pub new_string: String,
}

/// Input for the LS tool - lists files and directories.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct LsInput {
    /// The absolute path to the directory to list
    pub path: String,
}

/// Input for the NotebookRead tool - reads notebook cells.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NotebookReadInput {
    /// The absolute path to the notebook file
    pub notebook_path: String,
}

/// Input for the ScheduleWakeup tool - schedules delayed loop actions.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ScheduleWakeupInput {
    /// Seconds from now to wake up (clamped to [60, 3600])
    #[serde(rename = "delaySeconds")]
    pub delay_seconds: f64,

    /// Short explanation of the chosen delay
    pub reason: String,

    /// The /loop prompt to fire on wake-up
    pub prompt: String,
}

/// Input for the ToolSearch tool - fetches deferred tool schemas.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct ToolSearchInput {
    /// Query to find deferred tools
    pub query: String,

    /// Maximum number of results to return
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_results: Option<u32>,
}

// ============================================================================
// ToolInput Enum - Unified type for all tool inputs
// ============================================================================

/// Unified enum representing input for any Claude Code tool.
///
/// This enum uses `#[serde(untagged)]` to automatically deserialize based on
/// the structure of the JSON. The `Unknown` variant serves as a fallback for:
/// - New tools added in future Claude CLI versions
/// - Custom MCP tools provided by users
/// - Any tool input that doesn't match known schemas
///
/// # Example
///
/// ```
/// use claude_codes::ToolInput;
///
/// // Known tool - deserializes to specific variant
/// let bash_json = serde_json::json!({"command": "ls"});
/// let input: ToolInput = serde_json::from_value(bash_json).unwrap();
/// assert!(matches!(input, ToolInput::Bash(_)));
///
/// // Unknown tool - falls back to Unknown variant
/// let custom_json = serde_json::json!({"custom_field": "value"});
/// let input: ToolInput = serde_json::from_value(custom_json).unwrap();
/// assert!(matches!(input, ToolInput::Unknown(_)));
/// ```
///
/// # Note on Ordering
///
/// The variants are ordered from most specific (most required fields) to least
/// specific to ensure correct deserialization with `#[serde(untagged)]`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum ToolInput {
    /// Edit tool - has unique field combination (file_path, old_string, new_string)
    Edit(EditInput),

    /// Write tool - file_path + content
    Write(WriteInput),

    /// MultiEdit tool - batch file edits (file_path + edits, before Read)
    MultiEdit(MultiEditInput),

    /// AskUserQuestion tool - has questions array
    AskUserQuestion(AskUserQuestionInput),

    /// TodoWrite tool - has todos array
    TodoWrite(TodoWriteInput),

    /// Task tool - description + prompt + subagent_type
    Task(TaskInput),

    /// NotebookEdit tool - notebook_path + new_source
    NotebookEdit(NotebookEditInput),

    /// WebFetch tool - url + prompt
    WebFetch(WebFetchInput),

    /// TaskOutput tool - task_id + block + timeout
    TaskOutput(TaskOutputInput),

    /// Bash tool - has command field
    Bash(BashInput),

    /// Read tool - has file_path
    Read(ReadInput),

    /// Glob tool - has pattern field (with deny_unknown_fields, must come before Grep)
    Glob(GlobInput),

    /// Grep tool - has pattern field plus many optional fields
    Grep(GrepInput),

    /// ToolSearch tool - fetch deferred tool schemas (query + max_results)
    ToolSearch(ToolSearchInput),

    /// WebSearch tool - has query field
    WebSearch(WebSearchInput),

    /// KillShell tool - has shell_id
    KillShell(KillShellInput),

    /// Skill tool - has skill field
    Skill(SkillInput),

    /// ExitPlanMode tool
    ExitPlanMode(ExitPlanModeInput),

    /// ScheduleWakeup tool - schedule delayed wakeup (3 required fields)
    ScheduleWakeup(ScheduleWakeupInput),

    /// NotebookRead tool - read notebook cells (notebook_path required)
    NotebookRead(NotebookReadInput),

    /// LS tool - list files and directories
    LS(LsInput),

    /// EnterPlanMode tool (empty input)
    EnterPlanMode(EnterPlanModeInput),

    /// Unknown tool input - fallback for custom/new tools
    ///
    /// This variant captures any tool input that doesn't match the known schemas.
    /// Use this for:
    /// - MCP tools provided by users
    /// - New tools in future Claude CLI versions
    /// - Any custom tool integration
    Unknown(Value),
}

impl ToolInput {
    /// Returns the tool name if it can be determined from the input type.
    ///
    /// For `Unknown` variants, returns `None` since the tool name cannot be
    /// determined from the input structure alone.
    pub fn tool_name(&self) -> Option<&'static str> {
        match self {
            ToolInput::Bash(_) => Some("Bash"),
            ToolInput::Read(_) => Some("Read"),
            ToolInput::Write(_) => Some("Write"),
            ToolInput::Edit(_) => Some("Edit"),
            ToolInput::Glob(_) => Some("Glob"),
            ToolInput::Grep(_) => Some("Grep"),
            ToolInput::Task(_) => Some("Task"),
            ToolInput::WebFetch(_) => Some("WebFetch"),
            ToolInput::WebSearch(_) => Some("WebSearch"),
            ToolInput::TodoWrite(_) => Some("TodoWrite"),
            ToolInput::AskUserQuestion(_) => Some("AskUserQuestion"),
            ToolInput::NotebookEdit(_) => Some("NotebookEdit"),
            ToolInput::TaskOutput(_) => Some("TaskOutput"),
            ToolInput::KillShell(_) => Some("KillShell"),
            ToolInput::Skill(_) => Some("Skill"),
            ToolInput::EnterPlanMode(_) => Some("EnterPlanMode"),
            ToolInput::ExitPlanMode(_) => Some("ExitPlanMode"),
            ToolInput::MultiEdit(_) => Some("MultiEdit"),
            ToolInput::ScheduleWakeup(_) => Some("ScheduleWakeup"),
            ToolInput::NotebookRead(_) => Some("NotebookRead"),
            ToolInput::ToolSearch(_) => Some("ToolSearch"),
            ToolInput::LS(_) => Some("LS"),
            ToolInput::Unknown(_) => None,
        }
    }

    /// Try to get the input as a Bash input.
    pub fn as_bash(&self) -> Option<&BashInput> {
        match self {
            ToolInput::Bash(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Read input.
    pub fn as_read(&self) -> Option<&ReadInput> {
        match self {
            ToolInput::Read(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Write input.
    pub fn as_write(&self) -> Option<&WriteInput> {
        match self {
            ToolInput::Write(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as an Edit input.
    pub fn as_edit(&self) -> Option<&EditInput> {
        match self {
            ToolInput::Edit(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Glob input.
    pub fn as_glob(&self) -> Option<&GlobInput> {
        match self {
            ToolInput::Glob(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Grep input.
    pub fn as_grep(&self) -> Option<&GrepInput> {
        match self {
            ToolInput::Grep(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Task input.
    pub fn as_task(&self) -> Option<&TaskInput> {
        match self {
            ToolInput::Task(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a WebFetch input.
    pub fn as_web_fetch(&self) -> Option<&WebFetchInput> {
        match self {
            ToolInput::WebFetch(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a WebSearch input.
    pub fn as_web_search(&self) -> Option<&WebSearchInput> {
        match self {
            ToolInput::WebSearch(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a TodoWrite input.
    pub fn as_todo_write(&self) -> Option<&TodoWriteInput> {
        match self {
            ToolInput::TodoWrite(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as an AskUserQuestion input.
    pub fn as_ask_user_question(&self) -> Option<&AskUserQuestionInput> {
        match self {
            ToolInput::AskUserQuestion(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a NotebookEdit input.
    pub fn as_notebook_edit(&self) -> Option<&NotebookEditInput> {
        match self {
            ToolInput::NotebookEdit(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a TaskOutput input.
    pub fn as_task_output(&self) -> Option<&TaskOutputInput> {
        match self {
            ToolInput::TaskOutput(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a KillShell input.
    pub fn as_kill_shell(&self) -> Option<&KillShellInput> {
        match self {
            ToolInput::KillShell(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as a Skill input.
    pub fn as_skill(&self) -> Option<&SkillInput> {
        match self {
            ToolInput::Skill(input) => Some(input),
            _ => None,
        }
    }

    /// Try to get the input as an unknown Value.
    pub fn as_unknown(&self) -> Option<&Value> {
        match self {
            ToolInput::Unknown(value) => Some(value),
            _ => None,
        }
    }

    /// Check if this is an unknown tool input.
    pub fn is_unknown(&self) -> bool {
        matches!(self, ToolInput::Unknown(_))
    }
}

// ============================================================================
// Conversion implementations
// ============================================================================

impl From<BashInput> for ToolInput {
    fn from(input: BashInput) -> Self {
        ToolInput::Bash(input)
    }
}

impl From<ReadInput> for ToolInput {
    fn from(input: ReadInput) -> Self {
        ToolInput::Read(input)
    }
}

impl From<WriteInput> for ToolInput {
    fn from(input: WriteInput) -> Self {
        ToolInput::Write(input)
    }
}

impl From<EditInput> for ToolInput {
    fn from(input: EditInput) -> Self {
        ToolInput::Edit(input)
    }
}

impl From<GlobInput> for ToolInput {
    fn from(input: GlobInput) -> Self {
        ToolInput::Glob(input)
    }
}

impl From<GrepInput> for ToolInput {
    fn from(input: GrepInput) -> Self {
        ToolInput::Grep(input)
    }
}

impl From<TaskInput> for ToolInput {
    fn from(input: TaskInput) -> Self {
        ToolInput::Task(input)
    }
}

impl From<WebFetchInput> for ToolInput {
    fn from(input: WebFetchInput) -> Self {
        ToolInput::WebFetch(input)
    }
}

impl From<WebSearchInput> for ToolInput {
    fn from(input: WebSearchInput) -> Self {
        ToolInput::WebSearch(input)
    }
}

impl From<TodoWriteInput> for ToolInput {
    fn from(input: TodoWriteInput) -> Self {
        ToolInput::TodoWrite(input)
    }
}

impl From<AskUserQuestionInput> for ToolInput {
    fn from(input: AskUserQuestionInput) -> Self {
        ToolInput::AskUserQuestion(input)
    }
}

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

    #[test]
    fn test_bash_input_parsing() {
        let json = serde_json::json!({
            "command": "ls -la",
            "description": "List files",
            "timeout": 5000,
            "run_in_background": false
        });

        let input: BashInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.command, "ls -la");
        assert_eq!(input.description, Some("List files".to_string()));
        assert_eq!(input.timeout, Some(5000));
        assert_eq!(input.run_in_background, Some(false));
    }

    #[test]
    fn test_bash_input_minimal() {
        let json = serde_json::json!({
            "command": "echo hello"
        });

        let input: BashInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.command, "echo hello");
        assert_eq!(input.description, None);
        assert_eq!(input.timeout, None);
    }

    #[test]
    fn test_read_input_parsing() {
        let json = serde_json::json!({
            "file_path": "/home/user/test.rs",
            "offset": 10,
            "limit": 100
        });

        let input: ReadInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.file_path, "/home/user/test.rs");
        assert_eq!(input.offset, Some(10));
        assert_eq!(input.limit, Some(100));
    }

    #[test]
    fn test_write_input_parsing() {
        let json = serde_json::json!({
            "file_path": "/tmp/test.txt",
            "content": "Hello, world!"
        });

        let input: WriteInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.file_path, "/tmp/test.txt");
        assert_eq!(input.content, "Hello, world!");
    }

    #[test]
    fn test_edit_input_parsing() {
        let json = serde_json::json!({
            "file_path": "/home/user/code.rs",
            "old_string": "fn old()",
            "new_string": "fn new()",
            "replace_all": true
        });

        let input: EditInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.file_path, "/home/user/code.rs");
        assert_eq!(input.old_string, "fn old()");
        assert_eq!(input.new_string, "fn new()");
        assert_eq!(input.replace_all, Some(true));
    }

    #[test]
    fn test_glob_input_parsing() {
        let json = serde_json::json!({
            "pattern": "**/*.rs",
            "path": "/home/user/project"
        });

        let input: GlobInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.pattern, "**/*.rs");
        assert_eq!(input.path, Some("/home/user/project".to_string()));
    }

    #[test]
    fn test_grep_input_parsing() {
        let json = serde_json::json!({
            "pattern": "fn\\s+\\w+",
            "path": "/home/user/project",
            "type": "rust",
            "-i": true,
            "-C": 3
        });

        let input: GrepInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.pattern, "fn\\s+\\w+");
        assert_eq!(input.file_type, Some("rust".to_string()));
        assert_eq!(input.case_insensitive, Some(true));
        assert_eq!(input.context, Some(3));
    }

    #[test]
    fn test_task_input_parsing() {
        let json = serde_json::json!({
            "description": "Search codebase",
            "prompt": "Find all usages of foo()",
            "subagent_type": "Explore",
            "run_in_background": true
        });

        let input: TaskInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.description, "Search codebase");
        assert_eq!(input.prompt, "Find all usages of foo()");
        assert_eq!(input.subagent_type, SubagentType::Explore);
        assert_eq!(input.run_in_background, Some(true));
    }

    #[test]
    fn test_web_fetch_input_parsing() {
        let json = serde_json::json!({
            "url": "https://example.com",
            "prompt": "Extract the main content"
        });

        let input: WebFetchInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.url, "https://example.com");
        assert_eq!(input.prompt, "Extract the main content");
    }

    #[test]
    fn test_web_search_input_parsing() {
        let json = serde_json::json!({
            "query": "rust serde tutorial",
            "allowed_domains": ["docs.rs", "crates.io"]
        });

        let input: WebSearchInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.query, "rust serde tutorial");
        assert_eq!(
            input.allowed_domains,
            Some(vec!["docs.rs".to_string(), "crates.io".to_string()])
        );
    }

    #[test]
    fn test_todo_write_input_parsing() {
        let json = serde_json::json!({
            "todos": [
                {
                    "content": "Fix the bug",
                    "status": "in_progress",
                    "activeForm": "Fixing the bug"
                },
                {
                    "content": "Write tests",
                    "status": "pending",
                    "activeForm": "Writing tests"
                }
            ]
        });

        let input: TodoWriteInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.todos.len(), 2);
        assert_eq!(input.todos[0].content, "Fix the bug");
        assert_eq!(input.todos[0].status, TodoStatus::InProgress);
        assert_eq!(input.todos[1].status, TodoStatus::Pending);
    }

    #[test]
    fn test_ask_user_question_input_parsing() {
        let json = serde_json::json!({
            "questions": [
                {
                    "question": "Which framework?",
                    "header": "Framework",
                    "options": [
                        {"label": "React", "description": "Popular UI library"},
                        {"label": "Vue", "description": "Progressive framework"}
                    ],
                    "multiSelect": false
                }
            ]
        });

        let input: AskUserQuestionInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.questions.len(), 1);
        assert_eq!(input.questions[0].question, "Which framework?");
        assert_eq!(input.questions[0].options.len(), 2);
        assert_eq!(input.questions[0].options[0].label, "React");
    }

    #[test]
    fn test_tool_input_enum_bash() {
        let json = serde_json::json!({
            "command": "ls -la"
        });

        let input: ToolInput = serde_json::from_value(json).unwrap();
        assert!(matches!(input, ToolInput::Bash(_)));
        assert_eq!(input.tool_name(), Some("Bash"));
        assert!(input.as_bash().is_some());
    }

    #[test]
    fn test_tool_input_enum_edit() {
        let json = serde_json::json!({
            "file_path": "/test.rs",
            "old_string": "old",
            "new_string": "new"
        });

        let input: ToolInput = serde_json::from_value(json).unwrap();
        assert!(matches!(input, ToolInput::Edit(_)));
        assert_eq!(input.tool_name(), Some("Edit"));
    }

    #[test]
    fn test_tool_input_enum_unknown() {
        // Custom MCP tool with unknown structure
        let json = serde_json::json!({
            "custom_field": "custom_value",
            "another_field": 42
        });

        let input: ToolInput = serde_json::from_value(json).unwrap();
        assert!(matches!(input, ToolInput::Unknown(_)));
        assert_eq!(input.tool_name(), None);
        assert!(input.is_unknown());

        let unknown = input.as_unknown().unwrap();
        assert_eq!(unknown.get("custom_field").unwrap(), "custom_value");
    }

    #[test]
    fn test_tool_input_roundtrip() {
        let original = BashInput {
            command: "echo test".to_string(),
            description: Some("Test command".to_string()),
            timeout: Some(5000),
            run_in_background: None,
        };

        let tool_input: ToolInput = original.clone().into();
        let json = serde_json::to_value(&tool_input).unwrap();
        let parsed: ToolInput = serde_json::from_value(json).unwrap();

        if let ToolInput::Bash(bash) = parsed {
            assert_eq!(bash.command, original.command);
            assert_eq!(bash.description, original.description);
        } else {
            panic!("Expected Bash variant");
        }
    }

    #[test]
    fn test_notebook_edit_input_parsing() {
        let json = serde_json::json!({
            "notebook_path": "/home/user/notebook.ipynb",
            "new_source": "print('hello')",
            "cell_id": "abc123",
            "cell_type": "code",
            "edit_mode": "replace"
        });

        let input: NotebookEditInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.notebook_path, "/home/user/notebook.ipynb");
        assert_eq!(input.new_source, "print('hello')");
        assert_eq!(input.cell_id, Some("abc123".to_string()));
    }

    #[test]
    fn test_task_output_input_parsing() {
        let json = serde_json::json!({
            "task_id": "task-123",
            "block": false,
            "timeout": 60000
        });

        let input: TaskOutputInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.task_id, "task-123");
        assert!(!input.block);
        assert_eq!(input.timeout, 60000);
    }

    #[test]
    fn test_skill_input_parsing() {
        let json = serde_json::json!({
            "skill": "commit",
            "args": "-m 'Fix bug'"
        });

        let input: SkillInput = serde_json::from_value(json).unwrap();
        assert_eq!(input.skill, "commit");
        assert_eq!(input.args, Some("-m 'Fix bug'".to_string()));
    }

    #[test]
    fn test_multi_edit_input_parsing() {
        let json = serde_json::json!({
            "file_path": "/tmp/test.rs",
            "edits": [
                {"old_string": "foo", "new_string": "bar"},
                {"old_string": "baz", "new_string": "qux"}
            ]
        });

        let input: MultiEditInput = serde_json::from_value(json.clone()).unwrap();
        assert_eq!(input.file_path, "/tmp/test.rs");
        assert_eq!(input.edits.len(), 2);
        assert_eq!(input.edits[0].old_string, "foo");
        assert_eq!(input.edits[1].new_string, "qux");

        // Also test via ToolInput enum
        let tool_input: ToolInput = serde_json::from_value(json).unwrap();
        assert_eq!(tool_input.tool_name(), Some("MultiEdit"));
    }

    #[test]
    fn test_ls_input_parsing() {
        let json = serde_json::json!({"path": "/home/user/project"});

        let input: LsInput = serde_json::from_value(json.clone()).unwrap();
        assert_eq!(input.path, "/home/user/project");

        let tool_input: ToolInput = serde_json::from_value(json).unwrap();
        assert_eq!(tool_input.tool_name(), Some("LS"));
    }

    #[test]
    fn test_notebook_read_input_parsing() {
        let json = serde_json::json!({"notebook_path": "/tmp/analysis.ipynb"});

        let input: NotebookReadInput = serde_json::from_value(json.clone()).unwrap();
        assert_eq!(input.notebook_path, "/tmp/analysis.ipynb");

        let tool_input: ToolInput = serde_json::from_value(json).unwrap();
        assert_eq!(tool_input.tool_name(), Some("NotebookRead"));
    }

    #[test]
    fn test_schedule_wakeup_input_parsing() {
        let json = serde_json::json!({
            "delaySeconds": 270.0,
            "reason": "checking build status",
            "prompt": "check the build"
        });

        let input: ScheduleWakeupInput = serde_json::from_value(json.clone()).unwrap();
        assert_eq!(input.delay_seconds, 270.0);
        assert_eq!(input.reason, "checking build status");
        assert_eq!(input.prompt, "check the build");

        let tool_input: ToolInput = serde_json::from_value(json).unwrap();
        assert_eq!(tool_input.tool_name(), Some("ScheduleWakeup"));
    }

    #[test]
    fn test_tool_search_input_parsing() {
        let json = serde_json::json!({
            "query": "select:Read,Edit,Grep",
            "max_results": 5
        });

        let input: ToolSearchInput = serde_json::from_value(json.clone()).unwrap();
        assert_eq!(input.query, "select:Read,Edit,Grep");
        assert_eq!(input.max_results, Some(5));

        let tool_input: ToolInput = serde_json::from_value(json).unwrap();
        assert_eq!(tool_input.tool_name(), Some("ToolSearch"));
    }
}