MCPcopy
hub / github.com/wavetermdev/waveterm / verifyReadTextFileInput

Function verifyReadTextFileInput

pkg/aiusechat/tools_readfile.go:200–229  ·  view source on GitHub ↗
(input any, toolUseData *uctypes.UIMessageDataToolUse)

Source from the content-addressed store, hash-verified

198}
199
200func verifyReadTextFileInput(input any, toolUseData *uctypes.UIMessageDataToolUse) error {
201 params, err := parseReadTextFileInput(input)
202 if err != nil {
203 return err
204 }
205
206 expandedPath, err := wavebase.ExpandHomeDir(params.Filename)
207 if err != nil {
208 return fmt.Errorf("failed to expand path: %w", err)
209 }
210
211 if !filepath.IsAbs(expandedPath) {
212 return fmt.Errorf("path must be absolute, got relative path: %s", params.Filename)
213 }
214
215 if blocked, reason := isBlockedFile(expandedPath); blocked {
216 return fmt.Errorf("access denied: potentially sensitive file: %s", reason)
217 }
218
219 fileInfo, err := os.Stat(expandedPath)
220 if err != nil {
221 return fmt.Errorf("failed to stat file: %w", err)
222 }
223
224 if fileInfo.IsDir() {
225 return fmt.Errorf("path is a directory, cannot be read with the read_text_file tool. use the read_dir tool if available to read directories")
226 }
227
228 return nil
229}
230
231func readTextFileCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
232 const ReadLimit = 1024 * 1024 * 1024

Callers

nothing calls this directly

Calls 5

ExpandHomeDirFunction · 0.92
parseReadTextFileInputFunction · 0.85
isBlockedFileFunction · 0.85
StatMethod · 0.80
IsDirMethod · 0.45

Tested by

no test coverage detected