Some checks failed
Deploy (Gitea) / deploy (push) Failing after 3s
REPL tool: - ~/.opencode/bin/repl — connects to running daemon, evaluates Lisp forms, returns results. Usage: repl '(+ 1 2)' or via stdin. - Server-side handler in programming-repl skill registers for :repl-eval sensor, bypasses LLM pipeline, writes result back through reply-stream. - Core provides pre-reason-handler registry (register-pre-reason-handler) for skills to register custom sensors without modifying core code. HITL gateway integration: - hitl-handle-message: TUI, Telegram, and Signal gateways intercept approval/deny commands before they reach the LLM. - hitl-create/hitl-approve/hitl-deny: in-memory HITL store with correlation tokens for gateway-agnostic approval. - loop-gate-perceive detects HITL commands and blocks LLM processing. Naming drift fixes (the complete batch): - register-actuator vs actuator-register — fixed to register-actuator - process-signal vs loop-process — alias added - perceive-gate/reason-gate/act-gate vs loop-gate-* — aliases added - initialize-actuators vs actuator-initialize — fixed to actuator-initialize - initialize-all-skills vs skill-initialize-all — fixed to skill-initialize-all - inject-stimulus alias added for backward compatibility - All original gateway-manager inject-stimulus → stimulus-inject + HITL check
123 lines
5.2 KiB
Common Lisp
123 lines
5.2 KiB
Common Lisp
(in-package :passepartout)
|
|
|
|
(defvar *actuator-registry* (make-hash-table :test 'equalp)
|
|
"Global registry mapping target keywords to their physical actuator functions.")
|
|
|
|
(defun register-actuator (name fn)
|
|
"Registers an actuator function. Actuators receive: (ACTION CONTEXT)."
|
|
(let ((key (if (keywordp name) name (intern (string-upcase (string name)) :keyword))))
|
|
(setf (gethash key *actuator-registry*) fn)))
|
|
|
|
(defun protocol-message-sanitize (msg)
|
|
"Recursively strips non-serializable objects from a protocol plist."
|
|
(if (and msg (listp msg))
|
|
(let ((clean nil))
|
|
(loop for (k v) on msg by #'cddr
|
|
do (unless (member k '(:reply-stream :socket :stream))
|
|
(push k clean)
|
|
(push (if (listp v) (protocol-message-sanitize v) v) clean)))
|
|
(nreverse clean))
|
|
msg))
|
|
|
|
(defun frame-message (msg)
|
|
"Serializes a message plist and prefixes it with a 6-character hex length."
|
|
(let* ((sanitized (protocol-message-sanitize msg))
|
|
(payload (let ((*print-pretty* nil) (*read-eval* nil)) (format nil "~s" sanitized)))
|
|
(len (length payload)))
|
|
(format nil "~6,'0x~a" len payload)))
|
|
|
|
(defun read-framed-message (stream)
|
|
"Reads a hex-length prefixed S-expression from the stream securely."
|
|
(let ((length-buffer (make-string 6)))
|
|
(handler-case
|
|
(progn
|
|
(loop for char = (peek-char nil stream nil :eof)
|
|
while (and (not (eq char :eof)) (member char '(#\Space #\Newline #\Tab #\Return)))
|
|
do (read-char stream))
|
|
(let ((count (read-sequence length-buffer stream)))
|
|
(if (< count 6)
|
|
:eof
|
|
(let ((len (ignore-errors (parse-integer length-buffer :radix 16))))
|
|
(if (not len)
|
|
:error
|
|
(let ((msg-buffer (make-string len)))
|
|
(read-sequence msg-buffer stream)
|
|
(let ((*read-eval* nil))
|
|
(handler-case (read-from-string msg-buffer)
|
|
(error () :error)))))))))
|
|
(error () :error))))
|
|
|
|
(defvar *daemon-socket* nil)
|
|
|
|
(defun client-handle-connection (socket)
|
|
"Handles a single TUI/CLI client connection in a dedicated thread."
|
|
(let ((stream (usocket:socket-stream socket)))
|
|
(handler-case
|
|
(progn
|
|
(format stream "~a" (frame-message (make-hello-message "0.2.0")))
|
|
(finish-output stream)
|
|
(loop
|
|
(let ((msg (read-framed-message stream)))
|
|
(cond
|
|
((eq msg :eof) (return))
|
|
((eq msg :error) (return))
|
|
((eq (getf msg :type) :health-check)
|
|
(let ((health-msg (list :type :health-response
|
|
:status (or (and (boundp 'passepartout::*system-health*)
|
|
(symbol-value 'passepartout::*system-health*))
|
|
:unknown)
|
|
:checked-p (or (and (boundp 'passepartout::*health-check-ran*)
|
|
(symbol-value 'passepartout::*health-check-ran*))
|
|
nil))))
|
|
(format stream "~a" (frame-message health-msg))
|
|
(finish-output stream)))
|
|
(t (inject-stimulus msg :stream stream))))))
|
|
(error (c) (log-message "CLIENT ERROR: ~a" c)))
|
|
(ignore-errors (usocket:socket-close socket))))
|
|
|
|
(defun start-daemon (&key (port 9105))
|
|
"Starts the network listener for TUI/CLI clients."
|
|
(setf *daemon-socket* (usocket:socket-listen "127.0.0.1" port :reuse-address t))
|
|
(log-message "DAEMON: Listening on localhost:~a" port)
|
|
(bt:make-thread
|
|
(lambda ()
|
|
(loop
|
|
(let ((client-socket (usocket:socket-accept *daemon-socket*)))
|
|
(when client-socket
|
|
(bt:make-thread (lambda () (client-handle-connection client-socket))
|
|
:name "passepartout-client-handler")))))
|
|
:name "passepartout-server-listener"))
|
|
|
|
(defun make-hello-message (version)
|
|
"Constructs the standard HELLO handshake message."
|
|
(list :TYPE :EVENT
|
|
:PAYLOAD (list :ACTION :handshake
|
|
:VERSION version
|
|
:CAPABILITIES '(:AUTH :ORG-AST))))
|
|
|
|
(in-package :passepartout)
|
|
|
|
(defun protocol-schema-validate (msg)
|
|
"Strict structural validation for incoming protocol messages."
|
|
(unless (listp msg) (error "Message must be a plist"))
|
|
(let ((type (proto-get msg :type)))
|
|
(unless (member type '(:REQUEST :EVENT :RESPONSE :LOG :STATUS))
|
|
(error "Invalid message type '~a'" type))
|
|
t))
|
|
|
|
(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
(ql:quickload :fiveam :silent t))
|
|
|
|
(defpackage :passepartout-communication-tests
|
|
(:use :cl :fiveam :passepartout)
|
|
(:export #:communication-protocol-suite))
|
|
(in-package :passepartout-communication-tests)
|
|
|
|
(def-suite communication-protocol-suite :description "Communication Protocol Suite")
|
|
(in-suite communication-protocol-suite)
|
|
|
|
(test test-framing
|
|
(let* ((msg '(:type :EVENT :payload (:action :handshake)))
|
|
(framed (frame-message msg)))
|
|
(is (string= "00002C" (string-upcase (subseq framed 0 6))))))
|