(dataDir *string)
| 8 | ) |
| 9 | |
| 10 | func apiCmd(dataDir *string) *cobra.Command { |
| 11 | var toolCallID string |
| 12 | fileReadPath := "" |
| 13 | fileRead := &cobra.Command{ |
| 14 | Use: "read-file <session_id>", |
| 15 | Short: "read a file from the sandbox workspace", |
| 16 | Args: cobra.ExactArgs(1), |
| 17 | RunE: func(cmd *cobra.Command, args []string) error { |
| 18 | paths, err := store.Init(*dataDir) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | db, err := store.Open(paths) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | defer db.Close() |
| 27 | body, decision, err := (computerapi.Service{DB: db, Paths: paths}).ReadFile(args[0], fileReadPath, toolCallID) |
| 28 | if err != nil { |
| 29 | return err |
| 30 | } |
| 31 | fmt.Fprintf(cmd.OutOrStdout(), "decision=%s reason=%s\n%s\n", decision.Decision, decision.Reason, body) |
| 32 | return nil |
| 33 | }, |
| 34 | } |
| 35 | fileRead.Flags().StringVar(&fileReadPath, "path", "", "workspace-relative path") |
| 36 | fileRead.Flags().StringVar(&toolCallID, "tool-call-id", "", "tool call id") |
| 37 | _ = fileRead.MarkFlagRequired("path") |
| 38 | |
| 39 | fileWritePath := "" |
| 40 | fileWriteContent := "" |
| 41 | fileWrite := &cobra.Command{ |
| 42 | Use: "write-file <session_id>", |
| 43 | Short: "write a file into the sandbox workspace", |
| 44 | Args: cobra.ExactArgs(1), |
| 45 | RunE: func(cmd *cobra.Command, args []string) error { |
| 46 | paths, err := store.Init(*dataDir) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | db, err := store.Open(paths) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | defer db.Close() |
| 55 | decision, err := (computerapi.Service{DB: db, Paths: paths}).WriteFile(args[0], fileWritePath, fileWriteContent, toolCallID) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | fmt.Fprintf(cmd.OutOrStdout(), "decision=%s reason=%s\n", decision.Decision, decision.Reason) |
| 60 | return nil |
| 61 | }, |
| 62 | } |
| 63 | fileWrite.Flags().StringVar(&fileWritePath, "path", "", "workspace-relative path") |
| 64 | fileWrite.Flags().StringVar(&fileWriteContent, "content", "", "file content") |
| 65 | fileWrite.Flags().StringVar(&toolCallID, "tool-call-id", "", "tool call id") |
| 66 | _ = fileWrite.MarkFlagRequired("path") |
| 67 | _ = fileWrite.MarkFlagRequired("content") |
no test coverage detected