aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/aflow/tool/codesearcher
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/aflow/tool/codesearcher')
-rw-r--r--pkg/aflow/tool/codesearcher/codesearcher.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/aflow/tool/codesearcher/codesearcher.go b/pkg/aflow/tool/codesearcher/codesearcher.go
index c336a0ca4..34db81b80 100644
--- a/pkg/aflow/tool/codesearcher/codesearcher.go
+++ b/pkg/aflow/tool/codesearcher/codesearcher.go
@@ -17,6 +17,11 @@ var Tools = []aflow.Tool{
aflow.NewFuncTool("codesearch-dir-index", dirIndex, `
Tool provides list of source files and subdirectories in the given directory in the source tree.
`),
+ aflow.NewFuncTool("read-file", readFile, `
+Tool provides full contents of a single source file as is. Avoid using this tool if there are better
+and more specialized tools for the job, because source files may be large and contain lots
+of unrelated information.
+`),
aflow.NewFuncTool("codesearch-file-index", fileIndex, `
Tool provides list of entities defined in the given source file.
Entity can be function, struct, or global variable.
@@ -68,6 +73,15 @@ type dirIndexResult struct {
Files []string `jsonschema:"List of source files."`
}
+type readFileArgs struct {
+ File string `jsonschema:"Source file path."`
+}
+
+type readFileResult struct {
+ Missing bool `jsonschema:"Set to true if the requested file does not exist."`
+ Contents string `jsonschema:"File contents."`
+}
+
type fileIndexArgs struct {
SourceFile string `jsonschema:"Source file path."`
}
@@ -154,6 +168,15 @@ func dirIndex(ctx *aflow.Context, state prepareResult, args dirIndexArgs) (dirIn
return res, err
}
+func readFile(ctx *aflow.Context, state prepareResult, args readFileArgs) (readFileResult, error) {
+ ok, contents, err := state.Index.ReadFile(args.File)
+ res := readFileResult{
+ Missing: !ok,
+ Contents: contents,
+ }
+ return res, err
+}
+
func fileIndex(ctx *aflow.Context, state prepareResult, args fileIndexArgs) (fileIndexResult, error) {
ok, entities, err := state.Index.FileIndex(args.SourceFile)
res := fileIndexResult{