cli/history: never collapse a turn's ends

The mixed policy previewed the user row, so a long prompt came back truncated
even though it is half of what the turn is about. Both ends - the human's
message and the model's answer - now print in full at every verbosity level;
--preview remains the explicit one-line skimmer that collapses them too.

Tests cover the ends staying full in the default and -v views (and the rounds
between them staying one-liners) plus a long-prompt regression.
This commit is contained in:
2026-09-22 21:15:07 +08:00
parent 72d323d680
commit 836ac8d6f8
3 changed files with 37 additions and 11 deletions
+3 -2
View File
@@ -1440,8 +1440,9 @@ def history_cmd(
``/history N`` — turn N (numbered from the first turn of this session)
``/history last [N]`` — the last N turns (default 1)
``/history --message N`` — one message (display number, not a DB row)
``-v`` adds every intermediate row (tool calls/results, notices); ``-vv``
prints full bodies for all of them; ``--preview`` collapses to one line each.
The turn's ends are printed in full; ``-v`` adds every intermediate row (tool
calls/results, notices) as a one-liner, ``-vv`` prints those in full too, and
``--preview`` collapses every row (ends included) to one line.
"""
from plyngent.cli import transcript as transcript_mod
+11 -3
View File
@@ -39,8 +39,9 @@ PREVIEW_CHARS = 200
# ``-v`` expands a turn's rows; ``-vv`` also prints their full bodies.
MAX_VERBOSE = 2
# Detail policy: ``mixed`` = a turn's final assistant answer in full, everything
# else on one line; ``full``/``preview`` force the extremes.
# Detail policy: ``mixed`` = a turn's two ends (the user message and the final
# answer) in full, the rounds between them on one line; ``full``/``preview``
# force the extremes (``--preview`` also collapses the ends).
type Detail = Literal["mixed", "full", "preview"]
# ``/history N`` addresses a turn by number; ``last`` counts from the end.
type TurnTarget = int | Literal["last"]
@@ -281,9 +282,16 @@ def echo_turn(turn: Turn, *, verbose: bool, detail: Detail) -> None:
def _row_detail(row: Row, *, turn: Turn, detail: Detail) -> Detail:
"""Effective detail for *row*: mixed prints the turn's answer in full."""
"""Effective detail for *row*.
Under ``mixed`` the two ends of a turn — the human's message and the model's
answer — are the rows a reader actually wants, so they are never collapsed;
the rounds between them stay one-liners.
"""
if detail != "mixed":
return detail
if row is turn.user:
return "full"
return "full" if row is turn.last and isinstance(row.message, AssistantChatMessage) else "preview"