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

Function verifyReadDirInput

pkg/aiusechat/tools_readdir.go:56–81  ·  view source on GitHub ↗
(input any, toolUseData *uctypes.UIMessageDataToolUse)

Source from the content-addressed store, hash-verified

54}
55
56func verifyReadDirInput(input any, toolUseData *uctypes.UIMessageDataToolUse) error {
57 params, err := parseReadDirInput(input)
58 if err != nil {
59 return err
60 }
61
62 expandedPath, err := wavebase.ExpandHomeDir(params.Path)
63 if err != nil {
64 return fmt.Errorf("failed to expand path: %w", err)
65 }
66
67 if !filepath.IsAbs(expandedPath) {
68 return fmt.Errorf("path must be absolute, got relative path: %s", params.Path)
69 }
70
71 fileInfo, err := os.Stat(expandedPath)
72 if err != nil {
73 return fmt.Errorf("failed to stat path: %w", err)
74 }
75
76 if !fileInfo.IsDir() {
77 return fmt.Errorf("path is not a directory, cannot be read with the read_dir tool. use the read_text_file tool if available to read files")
78 }
79
80 return nil
81}
82
83func readDirCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
84 params, err := parseReadDirInput(input)

Callers

nothing calls this directly

Calls 4

ExpandHomeDirFunction · 0.92
parseReadDirInputFunction · 0.85
StatMethod · 0.80
IsDirMethod · 0.45

Tested by

no test coverage detected