From 8088ac4199a6e947c38db669c11d4441a9d59581 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 19 Jan 2026 15:15:18 +0100 Subject: pkg/codesearch: add read-file command Just provides full file contents as last resort. --- pkg/aflow/tool/codesearcher/codesearcher.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'pkg/aflow') 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 @@ -16,6 +16,11 @@ import ( 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. @@ -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{ -- cgit mrf-deployment