diff options
| -rw-r--r-- | actions.py | 13 | ||||
| -rwxr-xr-x | llm.py | 2 |
2 files changed, 14 insertions, 1 deletions
@@ -61,3 +61,16 @@ def tldr(args, workdir=Path.cwd()): except Exception as e: return {"status": "error", "reason": f"An unexpected error occurred: {e}"} +def shell(args, workdir=Path.cwd()): + '{"action": "shell", "command": CMD} - Propose executing a shell command, but interrupts to ask for permission from the user.' + match args: + case {"action": "shell", "command": cmd}: + user_input = input(f"Run cmd `{cmd}`? [y/N]: ") + if user_input.lower() == 'y': + res = subprocess.run(cmd, shell=True, cwd=workdir, capture_output=True, text=True) + if res.returncode == 0: + return {"status": "success", "stdout": res.stdout} + else: + return {"status": "error", "reason": f"Shell command exited with code {res.returncode}", "stdout": res.stdout, "stderr": res.stderr} + else: + return {"status": "error", "reason": "Permission denied by user."} @@ -103,7 +103,7 @@ def main(): parser.add_argument("--workdir", type=Path, default=Path.cwd(), help="The directory the agent has access to (default: current directory)") args = parser.parse_args() - actions = [ls, read, write, tldr] + actions = [ls, read, write, tldr, shell] state = ({"role": "system", "content": f"""You are an autonomous coding agent that can help with programming tasks. You can explore repositories, read files, search for information, and make changes to code. |
