(ctx context.Context, input map[string]any, tc *tools.ToolContext)
| 237 | } |
| 238 | |
| 239 | func (t *GlobTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) { |
| 240 | pattern, _ := input["pattern"].(string) |
| 241 | path := "." |
| 242 | if p, ok := input["path"].(string); ok { |
| 243 | path = p |
| 244 | } |
| 245 | |
| 246 | // 路径安全验证 |
| 247 | if t.middleware != nil { |
| 248 | validatedPath, err := t.middleware.validatePath(path) |
| 249 | if err != nil { |
| 250 | return map[string]any{ |
| 251 | "ok": false, |
| 252 | "error": fmt.Sprintf("path validation failed: %v", err), |
| 253 | }, nil |
| 254 | } |
| 255 | path = validatedPath |
| 256 | } |
| 257 | |
| 258 | results, err := t.backend.GlobInfo(ctx, pattern, path) |
| 259 | if err != nil { |
| 260 | return map[string]any{ |
| 261 | "ok": false, |
| 262 | "error": fmt.Sprintf("failed to glob: %v", err), |
| 263 | }, nil |
| 264 | } |
| 265 | |
| 266 | files := make([]string, 0, len(results)) |
| 267 | for _, info := range results { |
| 268 | files = append(files, info.Path) |
| 269 | } |
| 270 | |
| 271 | return map[string]any{ |
| 272 | "ok": true, |
| 273 | "pattern": pattern, |
| 274 | "files": files, |
| 275 | "count": len(files), |
| 276 | }, nil |
| 277 | } |
| 278 | |
| 279 | func (t *GlobTool) Prompt() string { |
| 280 | return `Use this tool to find files matching glob patterns. |
nothing calls this directly
no test coverage detected