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

59 lines
2.2 KiB
Python

"""Session lifecycle slash commands: /clear, /new, and /compact."""
from __future__ import annotations
from rich.console import Console
from core.agent_harness.session import SessionManager
from surfaces.interactive_shell.runtime import Session
from surfaces.interactive_shell.ui import DIM, HIGHLIGHT
def _cmd_clear(session: Session, console: Console, _args: list[str]) -> bool:
from surfaces.interactive_shell.ui import render_ready_box
console.clear()
render_ready_box(console, session=session)
return True
def _cmd_new(session: Session, console: Console, _args: list[str]) -> bool:
"""Start a new session while preserving the current LLM conversation context.
Unlike /clear (which only clears the screen), /new rotates the session ID
and resets all session state while keeping cli_agent_messages and
accumulated_context so a resumed or in-progress conversation continues
seamlessly in a fresh session file.
"""
saved_messages = list(session.agent.messages)
saved_context = dict(session.accumulated_context)
saved_resumed_name = session.resumed_from_name
SessionManager.for_session(session).rotate_in_place(session)
session.agent.messages = saved_messages
session.accumulated_context = saved_context
session.resumed_from_name = saved_resumed_name
console.print(
f"[{DIM}]new session started[/] [{HIGHLIGHT}]—[/] [{DIM}]conversation context carried forward.[/]"
)
if saved_messages:
console.print(f"[{DIM}] {len(saved_messages)} messages in context · type to continue[/]")
return True
def _cmd_compact(session: Session, console: Console, _args: list[str]) -> bool:
"""Compact the live session branch and persist a compaction entry."""
from core.agent_harness.turns.transcript_compaction import compact_session_branch
result = compact_session_branch(session)
if result is None:
console.print(f"[{DIM}]Nothing to compact yet.[/]")
return True
console.print(
f"[{HIGHLIGHT}]compacted session context[/] "
f"[{DIM}]({result.before_chars} chars -> {result.after_chars} chars)[/]"
)
session.record("slash", "/compact")
return True