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

103 lines
3.1 KiB
Python

"""Headless subprocess presenter for gateway and other non-TTY agent surfaces."""
from __future__ import annotations
import logging
import subprocess
import tempfile
import threading
from typing import Any
from tools.interactive_shell.shared import ExecutionPolicyResult
from tools.interactive_shell.subprocess import subprocess_env_with_width
log = logging.getLogger(__name__)
class HeadlessSubprocessPresenter:
"""Minimal :class:`~tools.interactive_shell.subprocess.SubprocessPresenter` for gateway turns."""
def __init__(self, session: Any, console: Any | None = None) -> None:
self._session = session
self._console = console
@property
def session(self) -> Any:
return self._session
def execution_allowed(
self,
policy: ExecutionPolicyResult,
*,
action_summary: str,
) -> bool:
_ = (policy, action_summary)
return True
def print(self, message: str = "") -> None:
if message:
log.debug("subprocess: %s", message)
def print_error(self, message: str) -> None:
log.warning("subprocess error: %s", message)
def print_highlight(self, message: str) -> None:
log.info("subprocess: %s", message)
def print_bold_command(self, display_command: str) -> None:
log.info("$ %s", display_command)
def print_command_output(self, text: str, *, style: str | None = None) -> None:
_ = style
if text.strip():
log.debug("subprocess output: %s", text.strip())
def print_plain(self, text: str) -> None:
log.debug("subprocess: %s", text)
def report_exception(self, exc: BaseException, *, context: str) -> None:
log.exception("subprocess exception (%s)", context, exc_info=exc)
def subprocess_env(self) -> dict[str, str]:
return subprocess_env_with_width(columns=120)
def start_task_output_streams(
self,
*,
task: Any,
proc: subprocess.Popen[Any],
stdout_capture: tempfile.SpooledTemporaryFile[bytes] | None = None, # type: ignore[type-arg]
stderr_capture: tempfile.SpooledTemporaryFile[bytes] | None = None, # type: ignore[type-arg]
) -> list[threading.Thread]:
_ = (task, proc, stdout_capture, stderr_capture)
return []
def join_task_output_streams(self, threads: list[threading.Thread]) -> None:
_ = threads
def start_background_cli_task(
self,
*,
display_command: str,
argv_list: list[str],
timeout_seconds: int,
kind: Any,
use_pty: bool = False,
) -> Any:
_ = (display_command, argv_list, timeout_seconds, kind, use_pty)
raise RuntimeError("background CLI tasks are not supported in headless gateway mode")
def headless_subprocess_presenter_factory(
session: Any,
console: Any,
confirm_fn: Any,
is_tty: bool | None,
action_already_listed: bool,
) -> HeadlessSubprocessPresenter:
_ = (confirm_fn, is_tty, action_already_listed)
return HeadlessSubprocessPresenter(session, console)
__all__ = ["HeadlessSubprocessPresenter", "headless_subprocess_presenter_factory"]