Print a one-line summary of an assistant message to stderr. Tool calls show name + key arg; text shows a truncated preview.
(msg: dict, prefix: str)
| 111 | |
| 112 | |
| 113 | def _progress_line(msg: dict, prefix: str) -> None: |
| 114 | """Print a one-line summary of an assistant message to stderr. |
| 115 | Tool calls show name + key arg; text shows a truncated preview.""" |
| 116 | if msg.get("type") != "assistant": |
| 117 | return |
| 118 | for b in msg.get("message", {}).get("content", []): |
| 119 | if not isinstance(b, dict): |
| 120 | continue |
| 121 | if b.get("type") == "tool_use": |
| 122 | inp = b.get("input") or {} |
| 123 | arg = (inp.get("command") or inp.get("file_path") or inp.get("path") |
| 124 | or inp.get("pattern") or "") |
| 125 | arg = str(arg).replace("\n", " ")[:120] |
| 126 | line = color(f"{prefix} → {b.get('name')}: {arg}", "dim", sys.stderr) |
| 127 | print(line, file=sys.stderr, flush=True) |
| 128 | elif b.get("type") == "text": |
| 129 | t = (b.get("text") or "").strip().replace("\n", " ") |
| 130 | if t: |
| 131 | line = color(f"{prefix} · {t[:140]}", "dim", sys.stderr) |
| 132 | print(line, file=sys.stderr, flush=True) |
| 133 | |
| 134 | |
| 135 | # ────────────────────────────────────────────────────────────────────────────── |