@@ -18,31 +18,45 @@ func (FileEditTool) Description() string {
1818 return "Edit a file by replacing an exact string match with new content."
1919}
2020
21- func (FileEditTool ) Parameters () map [string ]interface {} {
22- return map [string ]interface {}{
23- "type" : "object" ,
24- "properties" : map [string ]interface {}{
25- "path" : map [string ]interface {}{"type" : "string" , "description" : "File path to edit" },
26- "file_path" : map [string ]interface {}{"type" : "string" , "description" : "Archive-compatible alias for path" },
27- "old_str" : map [string ]interface {}{"type" : "string" , "description" : "Exact string to find and replace" },
28- "old_string" : map [string ]interface {}{"type" : "string" , "description" : "Archive-compatible alias for old_str" },
29- "new_str" : map [string ]interface {}{"type" : "string" , "description" : "Replacement string" },
30- "new_string" : map [string ]interface {}{"type" : "string" , "description" : "Archive-compatible alias for new_str" },
21+ // FileEditInput is the typed input for FileEditTool. NewStr/NewString are
22+ // pointers so an explicit empty replacement is distinguishable from absent.
23+ type FileEditInput struct {
24+ Path string `json:"path"`
25+ FilePath string `json:"file_path"`
26+ OldStr string `json:"old_str"`
27+ OldString string `json:"old_string"`
28+ NewStr * string `json:"new_str"`
29+ NewString * string `json:"new_string"`
30+ }
31+
32+ // Schema returns the typed input schema. Parameters() delegates to it so the
33+ // two cannot diverge. Alias descriptions are preserved verbatim: the input
34+ // validator discovers aliases from them.
35+ func (FileEditTool ) Schema () ToolSchema {
36+ return ToolSchema {
37+ Type : "object" ,
38+ Properties : map [string ]SchemaProperty {
39+ "path" : {Type : "string" , Description : "File path to edit" },
40+ "file_path" : {Type : "string" , Description : "Archive-compatible alias for path" },
41+ "old_str" : {Type : "string" , Description : "Exact string to find and replace" },
42+ "old_string" : {Type : "string" , Description : "Archive-compatible alias for old_str" },
43+ "new_str" : {Type : "string" , Description : "Replacement string" },
44+ "new_string" : {Type : "string" , Description : "Archive-compatible alias for new_str" },
3145 },
32- "required" : []string {"path" , "old_str" },
46+ Required : []string {"path" , "old_str" },
3347 }
3448}
3549
50+ func (FileEditTool ) Parameters () map [string ]interface {} {
51+ return fileEditSchema .ToJSONSchema ()
52+ }
53+
54+ // fileEditSchema is the single source of truth for FileEdit's input schema.
55+ var fileEditSchema = FileEditTool {}.Schema ()
56+
3657func (FileEditTool ) Execute (ctx context.Context , input json.RawMessage ) (string , error ) {
37- var p struct {
38- Path string `json:"path"`
39- FilePath string `json:"file_path"`
40- OldStr string `json:"old_str"`
41- OldString string `json:"old_string"`
42- NewStr * string `json:"new_str"`
43- NewString * string `json:"new_string"`
44- }
45- if err := json .Unmarshal (input , & p ); err != nil {
58+ p , err := DecodeInput [FileEditInput ]("FileEdit" , input )
59+ if err != nil {
4660 return "" , err
4761 }
4862 path := p .Path
0 commit comments