From 80acace256140862c4b5a4948b7389fb53eeeaad Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 11 Oct 2026 01:27:08 +0300 Subject: feat: shell commands with permission request --- actions.py | 13 +++++++++++++ llm.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/actions.py b/actions.py index 765fe3d..ffd33f7 100644 --- a/actions.py +++ b/actions.py @@ -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."} diff --git a/llm.py b/llm.py index 51234bd..4ef94d9 100755 --- a/llm.py +++ b/llm.py @@ -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. -- cgit v1.3.1