diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-08 19:15:23 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-08 19:15:23 +0200 |
| commit | 94923948e1a1525988bf13025a10cc9226652684 (patch) | |
| tree | 91d6b5b78b6af47a7272e92b54386eee42f21e50 /internal/llm/tools/view.go | |
| parent | 5acf0cba6040aaf90acb5dcacd3e4127d6833ac5 (diff) | |
| download | opencode-94923948e1a1525988bf13025a10cc9226652684.tar.gz opencode-94923948e1a1525988bf13025a10cc9226652684.zip | |
structure tools the same
- add some tests
- fix some tests
- change how we handle permissions
Diffstat (limited to 'internal/llm/tools/view.go')
| -rw-r--r-- | internal/llm/tools/view.go | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/internal/llm/tools/view.go b/internal/llm/tools/view.go index 743cef6f4..a687be015 100644 --- a/internal/llm/tools/view.go +++ b/internal/llm/tools/view.go @@ -14,6 +14,12 @@ import ( "github.com/kujtimiihoxha/termai/internal/lsp" ) +type ViewParams struct { + FilePath string `json:"file_path"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} + type viewTool struct { lspClients map[string]*lsp.Client } @@ -23,18 +29,48 @@ const ( MaxReadSize = 250 * 1024 DefaultReadLimit = 2000 MaxLineLength = 2000 + viewDescription = `File viewing tool that reads and displays the contents of files with line numbers, allowing you to examine code, logs, or text data. + +WHEN TO USE THIS TOOL: +- Use when you need to read the contents of a specific file +- Helpful for examining source code, configuration files, or log files +- Perfect for looking at text-based file formats + +HOW TO USE: +- Provide the path to the file you want to view +- Optionally specify an offset to start reading from a specific line +- Optionally specify a limit to control how many lines are read + +FEATURES: +- Displays file contents with line numbers for easy reference +- Can read from any position in a file using the offset parameter +- Handles large files by limiting the number of lines read +- Automatically truncates very long lines for better display +- Suggests similar file names when the requested file isn't found + +LIMITATIONS: +- Maximum file size is 250KB +- Default reading limit is 2000 lines +- Lines longer than 2000 characters are truncated +- Cannot display binary files or images +- Images can be identified but not displayed + +TIPS: +- Use with Glob tool to first find files you want to view +- For code exploration, first use Grep to find relevant files, then View to examine them +- When viewing large files, use the offset parameter to read specific sections` ) -type ViewParams struct { - FilePath string `json:"file_path"` - Offset int `json:"offset"` - Limit int `json:"limit"` +func NewViewTool(lspClients map[string]*lsp.Client) BaseTool { + return &viewTool{ + lspClients, + } } func (v *viewTool) Info() ToolInfo { return ToolInfo{ Name: ViewToolName, - Description: viewDescription(), + Description: viewDescription, Parameters: map[string]any{ "file_path": map[string]any{ "type": "string", @@ -262,42 +298,3 @@ func (s *LineScanner) Text() string { func (s *LineScanner) Err() error { return s.scanner.Err() } - -func viewDescription() string { - return `File viewing tool that reads and displays the contents of files with line numbers, allowing you to examine code, logs, or text data. - -WHEN TO USE THIS TOOL: -- Use when you need to read the contents of a specific file -- Helpful for examining source code, configuration files, or log files -- Perfect for looking at text-based file formats - -HOW TO USE: -- Provide the path to the file you want to view -- Optionally specify an offset to start reading from a specific line -- Optionally specify a limit to control how many lines are read - -FEATURES: -- Displays file contents with line numbers for easy reference -- Can read from any position in a file using the offset parameter -- Handles large files by limiting the number of lines read -- Automatically truncates very long lines for better display -- Suggests similar file names when the requested file isn't found - -LIMITATIONS: -- Maximum file size is 250KB -- Default reading limit is 2000 lines -- Lines longer than 2000 characters are truncated -- Cannot display binary files or images -- Images can be identified but not displayed - -TIPS: -- Use with Glob tool to first find files you want to view -- For code exploration, first use Grep to find relevant files, then View to examine them -- When viewing large files, use the offset parameter to read specific sections` -} - -func NewViewTool(lspClients map[string]*lsp.Client) BaseTool { - return &viewTool{ - lspClients, - } -} |
