@@ -118,6 +118,15 @@ var tools = map[string]types.Tool{
118
118
},
119
119
BuiltinFunc : SysRemove ,
120
120
},
121
+ "sys.file.stat" : {
122
+ Parameters : types.Parameters {
123
+ Description : "Gets size, modfied time, and mode of the specified file" ,
124
+ Arguments : types .ObjectSchema (
125
+ "filepath" , "The complete path and filename of the file" ,
126
+ ),
127
+ },
128
+ BuiltinFunc : SysFileStat ,
129
+ },
121
130
}
122
131
123
132
func SysProgram () * types.Program {
@@ -377,6 +386,22 @@ func SysRemove(ctx context.Context, env []string, input string) (string, error)
377
386
return fmt .Sprintf ("Removed file: %s" , params .Location ), os .Remove (params .Location )
378
387
}
379
388
389
+ func SysFileStat (ctx context.Context , env []string , input string ) (string , error ) {
390
+ var params struct {
391
+ Filepath string `json:"filepath,omitempty"`
392
+ }
393
+ if err := json .Unmarshal ([]byte (input ), & params ); err != nil {
394
+ return "" , err
395
+ }
396
+
397
+ stat , err := os .Stat (params .Filepath )
398
+ if err != nil {
399
+ return "" , err
400
+ }
401
+
402
+ return fmt .Sprintf ("File %s mode: %s, size: %d bytes, modtime: %s" , params .Filepath , stat .Mode ().String (), stat .Size (), stat .ModTime ().String ()), nil
403
+ }
404
+
380
405
func SysDownload (ctx context.Context , env []string , input string ) (_ string , err error ) {
381
406
var params struct {
382
407
URL string `json:"url,omitempty"`
0 commit comments