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

133 lines
4.8 KiB
Python

"""Execute planned opensre CLI actions.
Pure subprocess execution, planning, and orchestration for shell / synthetic /
Claude Code / opensre CLI action tools live under ``tools.interactive_shell``
(``subprocess/``, ``shell/``, ``synthetic/``, ``implementation/``, ``cli/``).
This package keeps Rich relay helpers in ``task_streaming``, the REPL presenter
in ``repl_presenter``, and backward-compatible surface adapters such as
``opensre_cli_runner`` for slash parity and legacy test monkeypatch paths.
Shell command execution lives in ``tools.interactive_shell.shell`` (parsing,
policy, ``execute_shell_command``, and the ``run_shell_command`` / ``run_cd`` /
``run_pwd`` runner); it is intentionally not re-exported here. Synthetic test
execution lives in ``tools.interactive_shell.synthetic`` (the
``run_synthetic_test`` / ``watch_synthetic_subprocess`` runner), Claude Code
implementation execution lives in ``tools.interactive_shell.implementation.claude_code_executor``
(``run_claude_code_implementation``), and sample-alert / free-text investigation
execution lives in ``tools.interactive_shell.actions.sample_alert`` /
``tools.interactive_shell.actions.investigation`` (``run_sample_alert`` /
``run_text_investigation``); none are re-exported here. Shared stdlib subprocess
primitives live in ``tools.interactive_shell.subprocess``; Rich stream relay
remains in ``task_streaming``.
Public API is stable: all names exported below are importable directly from
``subprocess_runner`` and will remain so regardless of internal submodule changes.
Stdlib modules ``os``, ``subprocess``, and ``threading`` are re-imported here so
that tests can patch them via the full ``subprocess_runner.<module>.<attr>`` path
(e.g. ``subprocess_runner.subprocess.Popen``). Since these are module singletons in
``sys.modules``, patching via this attribute also affects the actual call sites
inside the submodules.
"""
from __future__ import annotations
# Stdlib singletons — imported so that monkeypatch paths resolve correctly in tests:
# ``"…subprocess_runner.os.chdir"``, ``"…subprocess_runner.subprocess.Popen"``,
# ``"…subprocess_runner.threading.Thread"``, ``"…subprocess_runner.time.sleep"``,
# ``"…subprocess_runner.Path.cwd"``.
import os
import subprocess
import threading
import time
from pathlib import Path
from .background_task_executor import start_background_cli_task
from .opensre_cli_runner import (
_INTERACTIVE_OPENSRE_COMMAND_PATHS,
_OPENSRE_BLOCKED_SUBCOMMANDS,
OpensreCommandClass,
OpensreExecutionMode,
OpensreExecutionPlan,
OpensreRunOutcome,
OpensreRunResult,
_build_opensre_execution_plan,
_classify_opensre_command,
_is_interactive_wizard,
_opensre_confirmation_reason,
_run_opensre_foreground,
_run_opensre_foreground_streaming,
build_opensre_cli_argv,
print_interactive_wizard_handoff,
run_opensre_cli_command,
run_opensre_cli_command_result,
)
from .task_streaming import (
_MAX_COMMAND_OUTPUT_CHARS,
_MIN_SUBPROCESS_TERMINAL_WIDTH,
_SYNTHETIC_DIAG_CHARS,
_SYNTHETIC_POLL_SECONDS,
_TASK_OUTPUT_JOIN_TIMEOUT_SECONDS,
_TASK_OUTPUT_PREFIX_WIDTH,
CLAUDE_CODE_IMPLEMENTATION_TIMEOUT_SECONDS,
SHELL_COMMAND_TIMEOUT_SECONDS,
SYNTHETIC_TEST_TIMEOUT_SECONDS,
_console_file_is_tty,
_join_task_output_streams,
_print_task_output_line,
_pump_task_pty,
_pump_task_stream,
_should_use_pty,
_start_task_output_streams,
_subprocess_env_with_aligned_width,
read_diag,
read_task_output,
terminate_child_process,
)
__all__ = [
"CLAUDE_CODE_IMPLEMENTATION_TIMEOUT_SECONDS",
"SHELL_COMMAND_TIMEOUT_SECONDS",
"SYNTHETIC_TEST_TIMEOUT_SECONDS",
"OpensreCommandClass",
"OpensreExecutionMode",
"OpensreExecutionPlan",
"OpensreRunOutcome",
"OpensreRunResult",
"Path",
"_INTERACTIVE_OPENSRE_COMMAND_PATHS",
"_MAX_COMMAND_OUTPUT_CHARS",
"_MIN_SUBPROCESS_TERMINAL_WIDTH",
"_OPENSRE_BLOCKED_SUBCOMMANDS",
"_SYNTHETIC_DIAG_CHARS",
"_SYNTHETIC_POLL_SECONDS",
"_TASK_OUTPUT_JOIN_TIMEOUT_SECONDS",
"_TASK_OUTPUT_PREFIX_WIDTH",
"_classify_opensre_command",
"_build_opensre_execution_plan",
"_console_file_is_tty",
"_is_interactive_wizard",
"_join_task_output_streams",
"_opensre_confirmation_reason",
"_print_task_output_line",
"_pump_task_pty",
"_pump_task_stream",
"_run_opensre_foreground",
"_run_opensre_foreground_streaming",
"_should_use_pty",
"_start_task_output_streams",
"_subprocess_env_with_aligned_width",
"build_opensre_cli_argv",
"os",
"print_interactive_wizard_handoff",
"read_diag",
"read_task_output",
"run_opensre_cli_command",
"run_opensre_cli_command_result",
"start_background_cli_task",
"subprocess",
"terminate_child_process",
"threading",
"time",
]