package protocol import ( "encoding/json" "sort" "strings" "unicode" ) // OutputPreview quotes retained output, never infers accomplishments from a // successful process or invents a schema for technology-neutral workflows. func OutputPreview(output map[string]any) string { keys := []string{"summary", "result", "report", "message", "accomplished", "artifacts", "evidence", "reason", "error"} seen := map[string]bool{} remaining := make([]string, 0, len(output)) for key := range output { remaining = append(remaining, key) } sort.Strings(remaining) keys = append(keys, remaining...) for _, key := range keys { if seen[key] || key == "input" { continue } seen[key] = true value, exists := output[key] if !exists || value == nil { continue } text, ok := value.(string) if !ok { encoded, err := json.Marshal(value) if err != nil { continue } text = string(encoded) } text = strings.Map(func(r rune) rune { if unicode.IsControl(r) { return ' ' } return r }, text) text = strings.Join(strings.Fields(text), " ") if text == "" || text == "[]" || text == "{}" { continue } if key != "summary" && key != "result" && key != "report" && key != "message" { text = key + ": " + text } runes := []rune(text) if len(runes) > 280 { text = string(runes[:279]) + "…" } return text } return "" }