@@ -27,6 +27,8 @@ type Operation struct {
2727 Args []string `json:"args,omitempty"`
2828 WorkDir string `json:"work_dir,omitempty"`
2929 OutputFile string `json:"output_file,omitempty"`
30+ Content string `json:"content,omitempty"` // For write_file, append_to_file
31+ Sources []string `json:"sources,omitempty"` // For concatenate_files
3032}
3133
3234// WorkspaceInfo represents the result of workspace operations
@@ -108,15 +110,17 @@ func GetJsonSchema() string {
108110 "properties": {
109111 "type": {
110112 "type": "string",
111- "enum": ["copy_file", "mkdir", "copy_directory_contents", "run_command"]
113+ "enum": ["copy_file", "mkdir", "copy_directory_contents", "run_command", "read_file", "write_file", "append_to_file", "concatenate_files", "move_path" ]
112114 },
113115 "src_path": {"type": "string"},
114116 "dest_path": {"type": "string"},
115117 "path": {"type": "string"},
116118 "command": {"type": "string"},
117119 "args": {"type": "array", "items": {"type": "string"}},
118120 "work_dir": {"type": "string"},
119- "output_file": {"type": "string"}
121+ "output_file": {"type": "string"},
122+ "content": {"type": "string"},
123+ "sources": {"type": "array", "items": {"type": "string"}}
120124 }
121125 }
122126 }
@@ -180,6 +184,52 @@ func validateOperation(op Operation, index int) error {
180184 if op .Command == "" {
181185 return fmt .Errorf ("operation %d: run_command requires command" , index )
182186 }
187+ case "read_file" :
188+ if op .Path == "" {
189+ return fmt .Errorf ("operation %d: read_file requires path" , index )
190+ }
191+ if ! filepath .IsAbs (op .Path ) {
192+ return fmt .Errorf ("operation %d: path must be absolute: %s" , index , op .Path )
193+ }
194+ case "write_file" :
195+ if op .Path == "" {
196+ return fmt .Errorf ("operation %d: write_file requires path" , index )
197+ }
198+ if filepath .IsAbs (op .Path ) {
199+ return fmt .Errorf ("operation %d: path must be relative: %s" , index , op .Path )
200+ }
201+ case "append_to_file" :
202+ if op .Path == "" {
203+ return fmt .Errorf ("operation %d: append_to_file requires path" , index )
204+ }
205+ if filepath .IsAbs (op .Path ) {
206+ return fmt .Errorf ("operation %d: path must be relative: %s" , index , op .Path )
207+ }
208+ case "concatenate_files" :
209+ if len (op .Sources ) == 0 {
210+ return fmt .Errorf ("operation %d: concatenate_files requires sources" , index )
211+ }
212+ if op .DestPath == "" {
213+ return fmt .Errorf ("operation %d: concatenate_files requires dest_path" , index )
214+ }
215+ for i , source := range op .Sources {
216+ if ! filepath .IsAbs (source ) {
217+ return fmt .Errorf ("operation %d: source %d must be absolute: %s" , index , i , source )
218+ }
219+ }
220+ if filepath .IsAbs (op .DestPath ) {
221+ return fmt .Errorf ("operation %d: dest_path must be relative: %s" , index , op .DestPath )
222+ }
223+ case "move_path" :
224+ if op .SrcPath == "" || op .DestPath == "" {
225+ return fmt .Errorf ("operation %d: move_path requires src_path and dest_path" , index )
226+ }
227+ if ! filepath .IsAbs (op .SrcPath ) {
228+ return fmt .Errorf ("operation %d: src_path must be absolute: %s" , index , op .SrcPath )
229+ }
230+ if filepath .IsAbs (op .DestPath ) {
231+ return fmt .Errorf ("operation %d: dest_path must be relative: %s" , index , op .DestPath )
232+ }
183233 default :
184234 return fmt .Errorf ("operation %d: unknown operation type: %s" , index , op .Type )
185235 }
@@ -198,6 +248,16 @@ func executeJsonOperation(op Operation, workspaceDir string) ([]string, error) {
198248 return executeJsonCopyDirectoryContents (op , workspaceDir )
199249 case "run_command" :
200250 return executeJsonRunCommand (op , workspaceDir )
251+ case "read_file" :
252+ return executeJsonReadFile (op , workspaceDir )
253+ case "write_file" :
254+ return executeJsonWriteFile (op , workspaceDir )
255+ case "append_to_file" :
256+ return executeJsonAppendToFile (op , workspaceDir )
257+ case "concatenate_files" :
258+ return executeJsonConcatenateFiles (op , workspaceDir )
259+ case "move_path" :
260+ return executeJsonMovePath (op , workspaceDir )
201261 default :
202262 return nil , fmt .Errorf ("unsupported operation type: %s" , op .Type )
203263 }
@@ -295,3 +355,68 @@ func executeJsonRunCommand(op Operation, workspaceDir string) ([]string, error)
295355
296356 return []string {}, nil
297357}
358+
359+ // executeJsonReadFile executes read_file operation
360+ func executeJsonReadFile (op Operation , workspaceDir string ) ([]string , error ) {
361+ // Read file uses absolute path (from validation)
362+ content , err := ReadFile (op .Path )
363+ if err != nil {
364+ return nil , err
365+ }
366+
367+ // If output_file is specified, write content there
368+ if op .OutputFile != "" {
369+ outputPath := filepath .Join (workspaceDir , op .OutputFile )
370+ if err := WriteFile (outputPath , content ); err != nil {
371+ return nil , fmt .Errorf ("failed to write output: %w" , err )
372+ }
373+ return []string {outputPath }, nil
374+ }
375+
376+ // Otherwise just return the source path as processed
377+ return []string {op .Path }, nil
378+ }
379+
380+ // executeJsonWriteFile executes write_file operation
381+ func executeJsonWriteFile (op Operation , workspaceDir string ) ([]string , error ) {
382+ path := filepath .Join (workspaceDir , op .Path )
383+
384+ if err := WriteFile (path , op .Content ); err != nil {
385+ return nil , err
386+ }
387+
388+ return []string {path }, nil
389+ }
390+
391+ // executeJsonAppendToFile executes append_to_file operation
392+ func executeJsonAppendToFile (op Operation , workspaceDir string ) ([]string , error ) {
393+ path := filepath .Join (workspaceDir , op .Path )
394+
395+ if err := AppendToFile (path , op .Content ); err != nil {
396+ return nil , err
397+ }
398+
399+ return []string {path }, nil
400+ }
401+
402+ // executeJsonConcatenateFiles executes concatenate_files operation
403+ func executeJsonConcatenateFiles (op Operation , workspaceDir string ) ([]string , error ) {
404+ dest := filepath .Join (workspaceDir , op .DestPath )
405+
406+ if err := ConcatenateFiles (op .Sources , dest ); err != nil {
407+ return nil , err
408+ }
409+
410+ return []string {dest }, nil
411+ }
412+
413+ // executeJsonMovePath executes move_path operation
414+ func executeJsonMovePath (op Operation , workspaceDir string ) ([]string , error ) {
415+ dest := filepath .Join (workspaceDir , op .DestPath )
416+
417+ if err := MovePath (op .SrcPath , dest ); err != nil {
418+ return nil , err
419+ }
420+
421+ return []string {dest }, nil
422+ }
0 commit comments