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
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
"""Terminal facet accessors that work on SessionCore and interactive Session.
|
|
|
|
Gateway and other headless surfaces use :class:`~core.agent_harness.session.SessionCore`,
|
|
which has no REPL terminal facet. Slash dispatch and delegated CLI commands still
|
|
need the small slice of terminal state those paths touch (dedup sets, outcome hints,
|
|
background-mode flags). These helpers read the shell terminal when present and fall
|
|
back to lightweight per-session state on headless sessions.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def session_terminal(session: Any) -> Any | None:
|
|
return getattr(session, "terminal", None)
|
|
|
|
|
|
def agent_turn_executed_slashes(session: Any) -> set[str]:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
executed_slashes: set[str] = terminal.agent_turn_executed_slashes
|
|
return executed_slashes
|
|
executed: set[str] | None = getattr(session, "_headless_agent_turn_executed_slashes", None)
|
|
if executed is None:
|
|
executed = set()
|
|
session._headless_agent_turn_executed_slashes = executed
|
|
return executed
|
|
|
|
|
|
def exclusive_stdin_active(session: Any) -> bool:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
return bool(terminal.exclusive_stdin_active)
|
|
return False
|
|
|
|
|
|
def background_mode_enabled(session: Any) -> bool:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
return bool(terminal.background_mode_enabled)
|
|
return False
|
|
|
|
|
|
def trust_mode_enabled(session: Any) -> bool:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
return bool(terminal.trust_mode)
|
|
return False
|
|
|
|
|
|
def pop_turn_outcome_hint(session: Any) -> str:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
pop_hint = getattr(terminal, "pop_turn_outcome_hint", None)
|
|
if callable(pop_hint):
|
|
hint = pop_hint()
|
|
return hint.strip() if isinstance(hint, str) else ""
|
|
hints = getattr(session, "_headless_turn_outcome_hints", None)
|
|
if isinstance(hints, list) and hints:
|
|
return str(hints.pop()).strip()
|
|
return ""
|
|
|
|
|
|
def set_turn_outcome_hint(session: Any, hint: str) -> None:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
terminal.set_turn_outcome_hint(hint)
|
|
return
|
|
hints = getattr(session, "_headless_turn_outcome_hints", None)
|
|
if hints is None:
|
|
hints = []
|
|
session._headless_turn_outcome_hints = hints
|
|
hints.append(hint)
|
|
|
|
|
|
def set_auto_command(session: Any, command: str) -> None:
|
|
terminal = session_terminal(session)
|
|
if terminal is not None:
|
|
terminal.set_auto_command(command)
|
|
return
|
|
set_turn_outcome_hint(
|
|
session,
|
|
f"Run `{command}` in the interactive shell (`uv run opensre`).",
|
|
)
|
|
|
|
|
|
__all__ = [
|
|
"agent_turn_executed_slashes",
|
|
"background_mode_enabled",
|
|
"exclusive_stdin_active",
|
|
"pop_turn_outcome_hint",
|
|
"session_terminal",
|
|
"set_auto_command",
|
|
"set_turn_outcome_hint",
|
|
"trust_mode_enabled",
|
|
]
|