diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 01:27:08 +0300 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-11 01:27:08 +0300 |
| commit | 80acace256140862c4b5a4948b7389fb53eeeaad (patch) | |
| tree | 868a2a77c4b697dff98f73dbec4d5542049c3b4c | |
| parent | 3b9658bb9ae113732e250ad4e84866a349f88274 (diff) | |
| download | agent-80acace256140862c4b5a4948b7389fb53eeeaad.tar.gz agent-80acace256140862c4b5a4948b7389fb53eeeaad.zip | |
feat: shell commands with permission request
| -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. |
