ConnectOnionConnectOnion

Shell

Shell command execution tool.

Installation

main.py
1from connectonion import Shell 2 3shell = Shell()

API

run(command)

Execute a shell command, returns output.

main.py
1result = shell.run("ls -la") 2# Returns: "total 12\ndrwxr-xr-x 8 user staff..." 3 4result = shell.run("git status") 5# Returns: "On branch main\nnothing to commit..." 6 7result = shell.run("python --version") 8# Returns: "Python 3.11.0"

run_in_dir(command, directory)

Execute command in a specific directory.

main.py
1result = shell.run_in_dir("npm install", "/path/to/project") 2# Returns: "added 100 packages..." 3 4result = shell.run_in_dir("pytest", "/path/to/tests") 5# Returns: "5 passed in 0.5s"

Use with Agent

main.py
1from connectonion import Agent, Shell 2 3shell = Shell() 4agent = Agent("coder", tools=[shell]) 5 6agent.input("list all python files in current directory") 7# Agent runs: shell.run("ls *.py") 8 9agent.input("run the tests") 10# Agent runs: shell.run("pytest") 11 12agent.input("install requests package") 13# Agent runs: shell.run("pip install requests")

Common Use Cases

main.py
1# Git operations 2shell.run("git status") 3shell.run("git add .") 4shell.run("git commit -m 'update'") 5 6# Package management 7shell.run("pip install requests") 8shell.run("npm install express") 9 10# Build and test 11shell.run("pytest") 12shell.run("npm run build") 13 14# System info 15shell.run("pwd") 16shell.run("whoami") 17shell.run("df -h")