(messages []map[string]any)
| 350 | "- Important implementation decisions already made\n", |
| 351 | "- Files, commands, and tool results that matter\n", |
| 352 | "- Known failures or blockers\n", |
| 353 | "- Concrete next step\n\n", |
| 354 | "Conversation excerpts:\n\n", |
| 355 | } |
| 356 | for _, msg := range messages { |
| 357 | role := GetString(msg, "role", "system") |
| 358 | content := msg["content"] |
| 359 | switch c := content.(type) { |
| 360 | case []map[string]any: |
| 361 | var texts []string |
| 362 | var tools []string |
| 363 | for _, block := range c { |
| 364 | blockType := GetString(block, "type", "") |
| 365 | if blockType == "text" { |
| 366 | text := GetString(block, "text", "").(string) |
| 367 | if len(text) > 0 { |
| 368 | texts = append(texts, text) |
| 369 | } |
| 370 | } |
| 371 | if blockType == "tool_use" { |
| 372 | name := GetString(block, "name", "").(string) |
| 373 | if name != "" { |
| 374 | tools = append(tools, name) |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | for _, text := range texts { |
| 379 | parts = append(parts, fmt.Sprintf("[%s]: %s\n", role, TruncateRunes(text, 500))) |
| 380 | } |
| 381 | if len(tools) > 0 { |
| 382 | parts = append(parts, fmt.Sprintf("[%s called tools: %s]\n", role, strings.Join(tools, ", "))) |
| 383 | } |
| 384 | case []any: |
| 385 | var texts []string |
| 386 | var tools []string |
| 387 | for _, rawBlock := range c { |
| 388 | block, ok := rawBlock.(map[string]any) |
| 389 | if !ok { |
| 390 | continue |
| 391 | } |
| 392 | blockType := GetString(block, "type", "") |
| 393 | if blockType == "text" { |
| 394 | text := GetString(block, "text", "").(string) |
| 395 | if len(text) > 0 { |
| 396 | texts = append(texts, text) |
| 397 | } |
| 398 | } |
| 399 | if blockType == "tool_use" { |
| 400 | name := GetString(block, "name", "").(string) |
| 401 | if name != "" { |
| 402 | tools = append(tools, name) |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | for _, text := range texts { |
| 407 | parts = append(parts, fmt.Sprintf("[%s]: %s\n", role, TruncateRunes(text, 500))) |
| 408 | } |
| 409 | if len(tools) > 0 { |
no test coverage detected