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 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actions.py') 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."} -- cgit v1.3.1