MCPcopy Create free account
hub / github.com/ByteYellow/AgentProvenance / apiCmd

Function apiCmd

internal/cli/api_cmd.go:10–168  ·  view source on GitHub ↗
(dataDir *string)

Source from the content-addressed store, hash-verified

8)
9
10func 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")

Callers 1

NewRootCommandFunction · 0.85

Calls 8

InitFunction · 0.92
OpenFunction · 0.92
ReadFileMethod · 0.80
WriteFileMethod · 0.80
SearchMethod · 0.80
ExportArtifactMethod · 0.80
CallMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected