aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2026-10-11 01:27:08 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2026-10-11 01:27:08 +0300
commit80acace256140862c4b5a4948b7389fb53eeeaad (patch)
tree868a2a77c4b697dff98f73dbec4d5542049c3b4c
parent3b9658bb9ae113732e250ad4e84866a349f88274 (diff)
downloadagent-80acace256140862c4b5a4948b7389fb53eeeaad.tar.gz
agent-80acace256140862c4b5a4948b7389fb53eeeaad.zip
feat: shell commands with permission request
-rw-r--r--actions.py13
-rwxr-xr-xllm.py2
2 files changed, 14 insertions, 1 deletions
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.