MCPcopy Create free account
hub / github.com/alibaba/open-code-review / execute

Method execute

internal/behaviortask/code.go:151–260  ·  view source on GitHub ↗
(ctx context.Context, name string, args map[string]any)

Source from the content-addressed store, hash-verified

149}
150
151func (code *codeTools) execute(ctx context.Context, name string, args map[string]any) (Observation, error) {
152 side, _ := args["side"].(string)
153 if side == "" {
154 side = "new"
155 }
156 observation := Observation{ToolName: name, Arguments: args, SourceKind: "code", Side: side, Revision: code.comparison.Head, Locations: []Location{}}
157 if side == "old" {
158 observation.Revision = code.comparison.Old
159 }
160 if name == "file_read_diff" {
161 observation.Side = ""
162 observation.Revision = ""
163 }
164 if name == "file_read" {
165 filePath, _ := args["file_path"].(string)
166 if !code.allowed[side][filePath] {
167 observation.ErrorClass = "unavailable"
168 return observation, fmt.Errorf("file is unavailable in the authorized %s scope", side)
169 }
170 }
171 if name == "file_find" {
172 if err := ctx.Err(); err != nil {
173 return observation, err
174 }
175 paths := slices.Sorted(maps.Keys(code.allowed[side]))
176 query, _ := args["query_name"].(string)
177 sensitive, _ := args["case_sensitive"].(bool)
178 matches, err := tool.MatchFileNames(ctx, paths, query, sensitive, 101, func(filePath string) bool { return code.allowed[side][filePath] })
179 if err != nil {
180 return observation, err
181 }
182 if len(matches) > 100 {
183 observation.Truncated = true
184 observation.Continuation = "Narrow query_name to see more authorized files."
185 matches = matches[:100]
186 }
187 observation.ReturnedContent = strings.Join(matches, "\n")
188 if len(matches) == 0 {
189 observation.ReturnedContent = "No authorized files returned."
190 }
191 return observation, nil
192 }
193 provider, ok := code.registry.Get(name)
194 if !ok {
195 return observation, fmt.Errorf("tool is unavailable")
196 }
197 var content string
198 var err error
199 if name == "code_search" {
200 content, err = code.search(ctx, provider, args, side)
201 } else {
202 content, err = provider.Execute(ctx, args)
203 }
204 if errors.Is(err, gitcmd.ErrAnalysisGitRead) {
205 return observation, gitcmd.ErrAnalysisGitRead
206 }
207 observation.ReturnedContent = content
208 if err != nil {

Calls 7

searchMethod · 0.95
MatchFileNamesFunction · 0.92
HunkRangesFunction · 0.92
stripSideFunction · 0.85
ExecuteMethod · 0.65
ErrMethod · 0.45
GetMethod · 0.45