| 81 | } |
| 82 | |
| 83 | func 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 | |
| 123 | func GetReadDirToolDefinition() uctypes.ToolDefinition { |
| 124 | return uctypes.ToolDefinition{ |