mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* simplified get * resolved merge conflicts * removed default param for get * add dood setup * add readme * better build process * multi-stage build * revert makefile * rm entrypoint.sh * adjust ssh box for docker * update readme * update readme * fix hostname * change workspace setting * add workspace_mount_base * fixes for workspace dir * clean up frontend * refactor dockerfile * try download.py * change docker order a bit * remove workspace_dir from frontend settings * fix merge issues * Update opendevin/config.py * remove relpath logic from server * rename workspace_mount_base to workspace_base * remove workspace dir plumbing for now * delint * delint * move workspace base dir * remove refs to workspace_dir * factor out constant * fix local directory usage * dont require dir * fix docs * fix arg parsing for task * implement WORKSPACE_MOUNT_PATH * fix workspace dir * fix ports * fix merge issues * add makefile * revert settingsService * fix string * Add address * Update Dockerfile * Update local_box.py * fix lint * move to port 3000 --------- Co-authored-by: மனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com> Co-authored-by: enyst <engel.nyst@gmail.com>
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
from typing import List
|
|
|
|
from opendevin import config
|
|
from opendevin.observation import CmdOutputObservation
|
|
from opendevin.sandbox import DockerExecBox, DockerSSHBox, Sandbox, LocalBox
|
|
from opendevin.schema import ConfigType
|
|
|
|
|
|
class CommandManager:
|
|
id: str
|
|
shell: Sandbox
|
|
|
|
def __init__(
|
|
self,
|
|
sid: str,
|
|
container_image: str | None = None,
|
|
):
|
|
sandbox_type = config.get(ConfigType.SANDBOX_TYPE).lower()
|
|
if sandbox_type == 'exec':
|
|
self.shell = DockerExecBox(
|
|
sid=(sid or 'default'), container_image=container_image
|
|
)
|
|
elif sandbox_type == 'local':
|
|
self.shell = LocalBox()
|
|
elif sandbox_type == 'ssh':
|
|
self.shell = DockerSSHBox(
|
|
sid=(sid or 'default'), container_image=container_image
|
|
)
|
|
else:
|
|
raise ValueError(f'Invalid sandbox type: {sandbox_type}')
|
|
|
|
def run_command(self, command: str, background=False) -> CmdOutputObservation:
|
|
if background:
|
|
return self._run_background(command)
|
|
else:
|
|
return self._run_immediately(command)
|
|
|
|
def _run_immediately(self, command: str) -> CmdOutputObservation:
|
|
exit_code, output = self.shell.execute(command)
|
|
return CmdOutputObservation(
|
|
command_id=-1, content=output, command=command, exit_code=exit_code
|
|
)
|
|
|
|
def _run_background(self, command: str) -> CmdOutputObservation:
|
|
bg_cmd = self.shell.execute_in_background(command)
|
|
content = f'Background command started. To stop it, send a `kill` action with id {bg_cmd.id}'
|
|
return CmdOutputObservation(
|
|
content=content,
|
|
command_id=bg_cmd.id,
|
|
command=command,
|
|
exit_code=0,
|
|
)
|
|
|
|
def kill_command(self, id: int) -> CmdOutputObservation:
|
|
cmd = self.shell.kill_background(id)
|
|
return CmdOutputObservation(
|
|
content=f'Background command with id {id} has been killed.',
|
|
command_id=id,
|
|
command=cmd.command,
|
|
exit_code=0,
|
|
)
|
|
|
|
def get_background_obs(self) -> List[CmdOutputObservation]:
|
|
obs = []
|
|
for _id, cmd in self.shell.background_commands.items():
|
|
output = cmd.read_logs()
|
|
if output is not None and output != '':
|
|
obs.append(
|
|
CmdOutputObservation(
|
|
content=output, command_id=_id, command=cmd.command
|
|
)
|
|
)
|
|
return obs
|