feat: enhance command execution and status retrieval in virtual environments with transport abstractions

This commit is contained in:
Yeuoly
2025-12-30 19:37:16 +08:00
parent bac5245cd0
commit 39091fe4df
7 changed files with 334 additions and 30 deletions

View File

@ -43,7 +43,6 @@ class CommandStatus(BaseModel):
RUNNING = "running"
COMPLETED = "completed"
pid: int = Field(description="The process ID of the command.")
status: Status = Field(description="The status of the command execution.")
exit_code: int | None = Field(description="The return code of the command execution.")

View File

@ -4,6 +4,7 @@ from io import BytesIO
from typing import Any
from core.virtual_environment.__base.entities import CommandStatus, ConnectionHandle, FileState, Metadata
from core.virtual_environment.channel.transport import Transport
class VirtualEnvironment(ABC):
@ -116,7 +117,9 @@ class VirtualEnvironment(ABC):
"""
@abstractmethod
def execute_command(self, connection_handle: ConnectionHandle, command: list[str]) -> tuple[int, int, int, int]:
def execute_command(
self, connection_handle: ConnectionHandle, command: list[str]
) -> tuple[str, Transport, Transport, Transport]:
"""
Execute a command in the virtual environment.
@ -125,12 +128,13 @@ class VirtualEnvironment(ABC):
command (list[str]): The command to execute as a list of strings.
Returns:
tuple[int, int, int, int]: A tuple containing pid and 3 handle to os.pipe(): (stdin, stdout, stderr).
tuple[int, Transport, Transport, Transport]: A tuple containing pid and 3 handle
to os.pipe(): (stdin, stdout, stderr).
After exuection, the 3 handles will be closed by caller.
"""
@abstractmethod
def get_command_status(self, connection_handle: ConnectionHandle, pid: int) -> CommandStatus:
def get_command_status(self, connection_handle: ConnectionHandle, pid: str) -> CommandStatus:
"""
Get the status of a command executed in the virtual environment.