refactor: Switch TUI/daemon communication from JSON to Lisp S-Expressions
This commit is contained in:
@@ -53,15 +53,20 @@ The OpenCortex TUI Client is a standalone Common Lisp executable providing a ric
|
|||||||
(let ((line (read-line *stream* nil :eof)))
|
(let ((line (read-line *stream* nil :eof)))
|
||||||
(if (eq line :eof)
|
(if (eq line :eof)
|
||||||
(setf *is-running* nil)
|
(setf *is-running* nil)
|
||||||
(let ((json (ignore-errors (cl-json:decode-json-from-string line))))
|
(let* ((*read-eval* nil)
|
||||||
(if json
|
(sexp (ignore-errors (read-from-string line))))
|
||||||
|
(if (and sexp (listp sexp))
|
||||||
(cond
|
(cond
|
||||||
((string= (cdr (assoc :type json)) "status")
|
((eq (getf sexp :type) :status)
|
||||||
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
|
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
|
||||||
(cdr (assoc :scribe json))
|
(getf sexp :scribe)
|
||||||
(cdr (assoc :gardener json)))))
|
(getf sexp :gardener))))
|
||||||
((string= (cdr (assoc :type json)) "chat")
|
((eq (getf sexp :type) :chat)
|
||||||
(enqueue-msg (cdr (assoc :text json))))
|
(enqueue-msg (getf sexp :text)))
|
||||||
|
((eq (getf sexp :type) :info)
|
||||||
|
(enqueue-msg (format nil "*System*: ~a" (getf sexp :text))))
|
||||||
|
((eq (getf sexp :type) :error)
|
||||||
|
(enqueue-msg (format nil "*Error*: ~a" (getf sexp :text))))
|
||||||
(t (enqueue-msg line)))
|
(t (enqueue-msg line)))
|
||||||
(enqueue-msg line))))))
|
(enqueue-msg line))))))
|
||||||
(error () (setf *is-running* nil)))
|
(error () (setf *is-running* nil)))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
(uiop:symbol-call :fiveam :run! (uiop:find-symbol* :immune-suite :opencortex-immune-system-tests))))
|
(uiop:symbol-call :fiveam :run! (uiop:find-symbol* :immune-suite :opencortex-immune-system-tests))))
|
||||||
|
|
||||||
(defsystem :opencortex/tui
|
(defsystem :opencortex/tui
|
||||||
:depends-on (:opencortex :croatoan :usocket :bordeaux-threads :cl-json)
|
:depends-on (:opencortex :croatoan :usocket :bordeaux-threads)
|
||||||
:components ((:file "src/tui-client"))
|
:components ((:file "src/tui-client"))
|
||||||
:build-operation "program-op"
|
:build-operation "program-op"
|
||||||
:build-pathname "opencortex-tui"
|
:build-pathname "opencortex-tui"
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ The CLI actuator writes the agent's response back to the client's network stream
|
|||||||
(handler-case
|
(handler-case
|
||||||
(if (and stream (open-stream-p stream))
|
(if (and stream (open-stream-p stream))
|
||||||
(progn
|
(progn
|
||||||
(format stream "{\"type\": \"chat\", \"text\": \"~a\"}" text)
|
(prin1 (list :type :chat :text text) stream)
|
||||||
(terpri stream)
|
(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."))
|
||||||
@@ -73,17 +73,17 @@ Handles an individual TCP connection. It reads lines until the connection is clo
|
|||||||
|
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
(defun handle-cli-slash-command (cmd stream)
|
(defun handle-cli-slash-command (cmd stream)
|
||||||
"Handles TUI slash commands by returning structured JSON."
|
"Handles TUI slash commands by returning structured Lisp s-expressions."
|
||||||
(cond
|
(cond
|
||||||
((string= cmd "/status")
|
((string= cmd "/status")
|
||||||
(format stream "{\"type\": \"status\", \"scribe\": \"idle\", \"gardener\": \"sleeping\"}")
|
(prin1 '(:type :status :scribe :idle :gardener :sleeping) stream)
|
||||||
(terpri stream)
|
(terpri stream)
|
||||||
(finish-output stream))
|
(finish-output stream))
|
||||||
((string= cmd "/exit")
|
((string= cmd "/exit")
|
||||||
(format stream "{\"type\": \"info\", \"text\": \"Goodbye!\"}")
|
(prin1 '(:type :info :text "Goodbye!") stream)
|
||||||
(terpri stream)
|
(terpri stream)
|
||||||
(finish-output stream))
|
(finish-output stream))
|
||||||
(t (format stream "{\"type\": \"error\", \"text\": \"Unknown command: ~a\"}" cmd)
|
(t (prin1 (list :type :error :text (format nil "Unknown command: ~a" cmd)) stream)
|
||||||
(terpri stream)
|
(terpri stream)
|
||||||
(finish-output stream))))
|
(finish-output stream))))
|
||||||
|
|
||||||
|
|||||||
@@ -32,15 +32,20 @@
|
|||||||
(let ((line (read-line *stream* nil :eof)))
|
(let ((line (read-line *stream* nil :eof)))
|
||||||
(if (eq line :eof)
|
(if (eq line :eof)
|
||||||
(setf *is-running* nil)
|
(setf *is-running* nil)
|
||||||
(let ((json (ignore-errors (cl-json:decode-json-from-string line))))
|
(let* ((*read-eval* nil)
|
||||||
(if json
|
(sexp (ignore-errors (read-from-string line))))
|
||||||
|
(if (and sexp (listp sexp))
|
||||||
(cond
|
(cond
|
||||||
((string= (cdr (assoc :type json)) "status")
|
((eq (getf sexp :type) :status)
|
||||||
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
|
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
|
||||||
(cdr (assoc :scribe json))
|
(getf sexp :scribe)
|
||||||
(cdr (assoc :gardener json)))))
|
(getf sexp :gardener))))
|
||||||
((string= (cdr (assoc :type json)) "chat")
|
((eq (getf sexp :type) :chat)
|
||||||
(enqueue-msg (cdr (assoc :text json))))
|
(enqueue-msg (getf sexp :text)))
|
||||||
|
((eq (getf sexp :type) :info)
|
||||||
|
(enqueue-msg (format nil "*System*: ~a" (getf sexp :text))))
|
||||||
|
((eq (getf sexp :type) :error)
|
||||||
|
(enqueue-msg (format nil "*Error*: ~a" (getf sexp :text))))
|
||||||
(t (enqueue-msg line)))
|
(t (enqueue-msg line)))
|
||||||
(enqueue-msg line))))))
|
(enqueue-msg line))))))
|
||||||
(error () (setf *is-running* nil)))
|
(error () (setf *is-running* nil)))
|
||||||
|
|||||||
Reference in New Issue
Block a user