Bash Automator

UFO allows the HostAgent to execute bash commands on the host machine. The bash commands can be used to open applications or execute system commands. The Bash Automator is implemented in the ufo/automator/app_apis/shell module.

Note

Only HostAgent is currently supported by the Bash Automator.

Receiver

The Web Automator receiver is the ShellReceiver class defined in the ufo/automator/app_apis/shell/shell_client.py file.

Bases: ReceiverBasic

The base class for Web COM client using crawl4ai.

Initialize the shell client.

Source code in automator/app_apis/shell/shell_client.py
19
20
21
22
def __init__(self) -> None:
    """
    Initialize the shell client.
    """

run_shell(params)

Run the command.

Parameters:
  • params (Dict[str, Any]) –

    The parameters of the command.

Returns:
  • Any

    The result content.

Source code in automator/app_apis/shell/shell_client.py
24
25
26
27
28
29
30
31
32
33
34
def run_shell(self, params: Dict[str, Any]) -> Any:
    """
    Run the command.
    :param params: The parameters of the command.
    :return: The result content.
    """
    bash_command = params.get("command")
    result = subprocess.run(
        bash_command, shell=True, capture_output=True, text=True
    )
    return result.stdout


Command

We now only support one command in the Bash Automator to execute a bash command on the host machine.

@ShellReceiver.register
class RunShellCommand(ShellCommand):
    """
    The command to run the crawler with various options.
    """

    def execute(self):
        """
        Execute the command to run the crawler.
        :return: The result content.
        """
        return self.receiver.run_shell(params=self.params)

    @classmethod
    def name(cls) -> str:
        """
        The name of the command.
        """
        return "run_shell"

Below is the list of available commands in the Web Automator that are currently supported by UFO:

Command Name Function Name Description
RunShellCommand run_shell Get the content of a web page into a markdown format.