Files
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

91 lines
3.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Presentation for /resume: render a resumed session's prior activity.
Pure rendering — takes a console plus already-loaded session data and prints it
in REPL turn order. Holds no lookup or orchestration logic so the resume command
module stays focused on the resume flow.
"""
from __future__ import annotations
from collections import deque
from rich.console import Console
from rich.markup import escape
from surfaces.interactive_shell.ui import DIM, HIGHLIGHT
_HISTORY_DISPLAY_CHAT_KINDS: frozenset[str] = frozenset(
{"chat", "cli_agent", "follow_up", "alert", "incoming_alert"}
)
def _response_for_prompt(turn_details: list[dict], prompt: str) -> str:
for detail in turn_details:
if detail.get("prompt") == prompt:
return str(detail.get("response") or "")
return ""
def render_resumed_session_history(
console: Console,
*,
history: list[dict],
turn_details: list[dict],
messages: list[tuple[str, str]],
) -> None:
"""Render prior session activity in REPL turn order, including slash commands."""
from rich.markdown import Markdown
from platform.terminal.theme import MARKDOWN_THEME
from surfaces.interactive_shell.ui.streaming import render_response_header
if not history and not messages:
return
console.print(f"[{DIM}]─── conversation history ─────────────────────────────────[/]")
if history:
assistant_by_user: dict[str, deque[str]] = {}
pending_user: str | None = None
for role, text in messages:
if role == "user":
pending_user = text
elif role == "assistant" and pending_user is not None:
assistant_by_user.setdefault(pending_user, deque()).append(text)
pending_user = None
for rec in history:
kind = rec.get("kind", "")
text = rec.get("text") or ""
if kind == "slash":
console.print(f"[bold]$ {escape(text)}[/bold]")
continue
if kind not in _HISTORY_DISPLAY_CHAT_KINDS or not text:
continue
console.print(f"[bold {HIGHLIGHT}][/] {escape(text)}")
response = _response_for_prompt(turn_details, text)
if not response:
queued = assistant_by_user.get(text)
response = queued.popleft() if queued else ""
if response:
render_response_header(console, "assistant")
with console.use_theme(MARKDOWN_THEME):
console.print(Markdown(response, code_theme="ansi_dark"))
console.print(f"[{DIM}]─────────────────────────────────────────────────────────[/]")
return
has_pending_user = False
for role, text in messages:
if role == "user":
console.print(f"[bold {HIGHLIGHT}][/] {escape(text)}")
has_pending_user = True
elif role == "assistant" and has_pending_user:
render_response_header(console, "assistant")
with console.use_theme(MARKDOWN_THEME):
console.print(Markdown(text, code_theme="ansi_dark"))
has_pending_user = False
console.print(f"[{DIM}]─────────────────────────────────────────────────────────[/]")
__all__ = ["render_resumed_session_history"]