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

Function readDirCallback

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

Source from the content-addressed store, hash-verified

81}
82
83func readDirCallback(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
84 params, err := parseReadDirInput(input)
85 if err != nil {
86 return nil, err
87 }
88
89 expandedPath, err := wavebase.ExpandHomeDir(params.Path)
90 if err != nil {
91 return nil, fmt.Errorf("failed to expand path: %w", err)
92 }
93
94 if !filepath.IsAbs(expandedPath) {
95 return nil, fmt.Errorf("path must be absolute, got relative path: %s", params.Path)
96 }
97
98 result, err := fileutil.ReadDir(params.Path, *params.MaxEntries)
99 if err != nil {
100 return nil, err
101 }
102
103 resultMap := map[string]any{
104 "path": result.Path,
105 "absolute_path": result.AbsolutePath,
106 "entry_count": result.EntryCount,
107 "total_entries": result.TotalEntries,
108 "entries": result.Entries,
109 }
110
111 if result.Truncated {
112 resultMap["truncated"] = true
113 resultMap["truncated_message"] = fmt.Sprintf("Directory listing truncated to %d entries (out of %d total). Increase max_entries to see more.", result.EntryCount, result.TotalEntries)
114 }
115
116 if result.ParentDir != "" {
117 resultMap["parent_dir"] = result.ParentDir
118 }
119
120 return resultMap, nil
121}
122
123func GetReadDirToolDefinition() uctypes.ToolDefinition {
124 return uctypes.ToolDefinition{

Callers 4

TestReadDirCallbackFunction · 0.85
TestReadDirOnFileFunction · 0.85
TestReadDirMaxEntriesFunction · 0.85

Calls 3

ExpandHomeDirFunction · 0.92
ReadDirFunction · 0.92
parseReadDirInputFunction · 0.85

Tested by 4

TestReadDirCallbackFunction · 0.68
TestReadDirOnFileFunction · 0.68
TestReadDirMaxEntriesFunction · 0.68