diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2026-01-19 15:15:18 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2026-01-20 21:12:57 +0000 |
| commit | 8088ac4199a6e947c38db669c11d4441a9d59581 (patch) | |
| tree | fe7d6a6f5c9a6de0be54a14b40cab448bb80aa59 /pkg/aflow/tool/codesearcher | |
| parent | fb714834adfb0e1e36c4cfc7ca288391cfc18986 (diff) | |
pkg/codesearch: add read-file command
Just provides full file contents as last resort.
Diffstat (limited to 'pkg/aflow/tool/codesearcher')
| -rw-r--r-- | pkg/aflow/tool/codesearcher/codesearcher.go | 23 |
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{ |
