feat(gateway): Upgrade CLI Gateway to high-integrity framed protocol
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s
This commit is contained in:
@@ -82,7 +82,7 @@ The `main` function initializes the environment, loads skills, and starts the he
|
|||||||
|
|
||||||
(initialize-actuators)
|
(initialize-actuators)
|
||||||
(initialize-all-skills)
|
(initialize-all-skills)
|
||||||
(start-daemon)
|
|
||||||
(start-heartbeat)
|
(start-heartbeat)
|
||||||
|
|
||||||
;; Graceful shutdown handler for SBCL
|
;; Graceful shutdown handler for SBCL
|
||||||
|
|||||||
@@ -54,15 +54,14 @@ The CLI actuator writes the agent's response back to the client's network stream
|
|||||||
|
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defun execute-cli-action (action context)
|
(defun execute-cli-action (action context)
|
||||||
"Sends a message back to the connected CLI client via its network stream."
|
"Sends a framed message back to the connected CLI client."
|
||||||
(let* ((payload (getf action :payload))
|
(let* ((payload (getf action :payload))
|
||||||
(text (or (getf payload :text) (getf action :text)))
|
(text (or (getf payload :text) (getf action :text)))
|
||||||
(stream (getf context :reply-stream)))
|
(stream (getf context :reply-stream)))
|
||||||
(handler-case
|
(handler-case
|
||||||
(if (and stream (open-stream-p stream))
|
(if (and stream (open-stream-p stream))
|
||||||
(progn
|
(progn
|
||||||
(prin1 (list :type :chat :text text) stream)
|
(format stream "~a~%" (frame-message (format nil "~s" (list :type :chat :text text))))
|
||||||
(terpri stream)
|
|
||||||
(finish-output stream))
|
(finish-output stream))
|
||||||
(harness-log "CLI ERROR: No active or open reply stream for signal."))
|
(harness-log "CLI ERROR: No active or open reply stream for signal."))
|
||||||
(error (c) (harness-log "CLI ACTUATOR ERROR: ~a" c)))))
|
(error (c) (harness-log "CLI ACTUATOR ERROR: ~a" c)))))
|
||||||
@@ -76,8 +75,7 @@ Handles an individual TCP connection. It reads lines until the connection is clo
|
|||||||
"Handles TUI slash commands by returning structured Lisp s-expressions."
|
"Handles TUI slash commands by returning structured Lisp s-expressions."
|
||||||
(cond
|
(cond
|
||||||
((string= cmd "/status")
|
((string= cmd "/status")
|
||||||
(prin1 '(:type :status :scribe :idle :gardener :sleeping) stream)
|
(format stream "~a~%" (frame-message (format nil "~s" '(:type :status :scribe :idle :gardener :sleeping))))
|
||||||
(terpri stream)
|
|
||||||
(finish-output stream))
|
(finish-output stream))
|
||||||
((string= cmd "/exit")
|
((string= cmd "/exit")
|
||||||
(prin1 '(:type :info :text "Goodbye!") stream)
|
(prin1 '(:type :info :text "Goodbye!") stream)
|
||||||
@@ -88,22 +86,24 @@ Handles an individual TCP connection. It reads lines until the connection is clo
|
|||||||
(finish-output stream))))
|
(finish-output stream))))
|
||||||
|
|
||||||
(defun handle-cli-client (stream)
|
(defun handle-cli-client (stream)
|
||||||
"Reads lines from a CLI client and injects them as stimuli."
|
"Reads framed messages from a CLI client and injects them as stimuli."
|
||||||
(harness-log "CLI: Client connected.")
|
(harness-log "CLI: Client connected.")
|
||||||
(handler-case
|
(handler-case
|
||||||
(loop for line = (read-line stream nil nil)
|
(progn
|
||||||
while line do
|
;; 1. Send Handshake
|
||||||
(let ((trimmed (string-trim '(#\Space #\Tab #\Newline #\Return) line)))
|
(format stream "~a~%" (frame-message (format nil "~s" (make-hello-message "0.1.0"))))
|
||||||
(when (> (length trimmed) 0)
|
(finish-output stream)
|
||||||
(if (and (> (length trimmed) 0) (char= (char trimmed 0) #\/))
|
|
||||||
(handle-cli-slash-command trimmed stream)
|
;; 2. Communication Loop
|
||||||
(progn
|
(loop
|
||||||
(harness-log "CLI: Received input -> ~a" trimmed)
|
(let ((msg (read-framed-message stream)))
|
||||||
(inject-stimulus (list :type :EVENT
|
(cond ((eq msg :eof) (return))
|
||||||
:payload (list :sensor :chat-message
|
((eq msg :error) (return))
|
||||||
:channel :cli
|
(t (if (and (listp msg) (stringp (getf msg :text)) (char= (char (getf msg :text) 0) #\/))
|
||||||
:text trimmed))
|
(handle-cli-slash-command (getf msg :text) stream)
|
||||||
:stream stream))))))
|
(progn
|
||||||
|
(harness-log "CLI: Received input -> ~s" msg)
|
||||||
|
(inject-stimulus msg :stream stream))))))))
|
||||||
(error (c) (harness-log "CLI CLIENT DISCONNECT: ~a" c)))
|
(error (c) (harness-log "CLI CLIENT DISCONNECT: ~a" c)))
|
||||||
(harness-log "CLI: Client disconnected."))
|
(harness-log "CLI: Client disconnected."))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
(initialize-actuators)
|
(initialize-actuators)
|
||||||
(initialize-all-skills)
|
(initialize-all-skills)
|
||||||
(start-daemon)
|
|
||||||
(start-heartbeat)
|
(start-heartbeat)
|
||||||
|
|
||||||
;; Graceful shutdown handler for SBCL
|
;; Graceful shutdown handler for SBCL
|
||||||
|
|||||||
Reference in New Issue
Block a user