formatToolInput returns a compact one-line summary of a tool call's input.
(name string, raw json.RawMessage)
| 263 | |
| 264 | // formatToolInput returns a compact one-line summary of a tool call's input. |
| 265 | func formatToolInput(name string, raw json.RawMessage) string { |
| 266 | var m map[string]interface{} |
| 267 | if err := json.Unmarshal(raw, &m); err != nil { |
| 268 | return string(raw) |
| 269 | } |
| 270 | |
| 271 | switch name { |
| 272 | case "Bash": |
| 273 | if cmd, ok := m["command"].(string); ok { |
| 274 | return "$ " + cmd |
| 275 | } |
| 276 | case "Read": |
| 277 | if fp, ok := m["file_path"].(string); ok { |
| 278 | parts := []string{fp} |
| 279 | if off, ok := m["offset"].(float64); ok { |
| 280 | parts = append(parts, fmt.Sprintf("offset=%d", int(off))) |
| 281 | } |
| 282 | if lim, ok := m["limit"].(float64); ok { |
| 283 | parts = append(parts, fmt.Sprintf("limit=%d", int(lim))) |
| 284 | } |
| 285 | return strings.Join(parts, " ") |
| 286 | } |
| 287 | case "Write": |
| 288 | if fp, ok := m["file_path"].(string); ok { |
| 289 | return fp |
| 290 | } |
| 291 | case "Edit": |
| 292 | if fp, ok := m["file_path"].(string); ok { |
| 293 | return fp |
| 294 | } |
| 295 | case "Glob": |
| 296 | if p, ok := m["pattern"].(string); ok { |
| 297 | return p |
| 298 | } |
| 299 | case "Grep": |
| 300 | if p, ok := m["pattern"].(string); ok { |
| 301 | parts := []string{p} |
| 302 | if path, ok := m["path"].(string); ok { |
| 303 | parts = append(parts, "in "+path) |
| 304 | } |
| 305 | return strings.Join(parts, " ") |
| 306 | } |
| 307 | case "Agent": |
| 308 | if desc, ok := m["description"].(string); ok { |
| 309 | return desc |
| 310 | } |
| 311 | if prompt, ok := m["prompt"].(string); ok { |
| 312 | return truncate(prompt, 120) |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // Fallback: compact JSON of the input. |
| 317 | compact, err := json.Marshal(m) |
| 318 | if err != nil { |
| 319 | return string(raw) |
| 320 | } |
| 321 | return truncate(string(compact), 200) |
| 322 | } |
no test coverage detected