39 lines
1.1 KiB
Org Mode
39 lines
1.1 KiB
Org Mode
#+TITLE: SKILL: Shell Actuator (org-skill-shell-actuator.org)
|
|
#+AUTHOR: Agent
|
|
#+FILETAGS: :skill:actuator:shell:
|
|
#+PROPERTY: header-args:lisp :tangle org-skill-shell-actuator.lisp
|
|
|
|
* Overview
|
|
The *Shell Actuator* provides the agent with the capability to execute bash commands.
|
|
|
|
* Implementation
|
|
|
|
** Package Context
|
|
#+begin_src lisp
|
|
(in-package :opencortex)
|
|
#+end_src
|
|
|
|
** Shell Execution (shell-execute)
|
|
#+begin_src lisp
|
|
(defun shell-execute (action context)
|
|
"Executes a bash command and returns the output."
|
|
(declare (ignore context))
|
|
(let* ((payload (getf action :payload))
|
|
(cmd (getf payload :cmd)))
|
|
(harness-log "ACT [Shell]: ~a" cmd)
|
|
(multiple-value-bind (out err code)
|
|
(uiop:run-program (list "bash" "-c" cmd) :output :string :error-output :string :ignore-error-status t)
|
|
(if (= code 0)
|
|
out
|
|
(format nil "ERROR [~a]: ~a" code err)))))
|
|
#+end_src
|
|
|
|
** Skill Registration
|
|
#+begin_src lisp
|
|
(register-actuator :shell #'shell-execute)
|
|
|
|
(defskill :skill-shell-actuator
|
|
:priority 50
|
|
:trigger (lambda (ctx) (declare (ignore ctx)) nil))
|
|
#+end_src
|