refactor: Switch TUI/daemon communication from JSON to Lisp S-Expressions

This commit is contained in:
2026-04-17 13:36:54 -04:00
parent 47a2cf6478
commit 0debfe5a95
4 changed files with 30 additions and 20 deletions

View File

@@ -53,15 +53,20 @@ The OpenCortex TUI Client is a standalone Common Lisp executable providing a ric
(let ((line (read-line *stream* nil :eof)))
(if (eq line :eof)
(setf *is-running* nil)
(let ((json (ignore-errors (cl-json:decode-json-from-string line))))
(if json
(let* ((*read-eval* nil)
(sexp (ignore-errors (read-from-string line))))
(if (and sexp (listp sexp))
(cond
((string= (cdr (assoc :type json)) "status")
((eq (getf sexp :type) :status)
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
(cdr (assoc :scribe json))
(cdr (assoc :gardener json)))))
((string= (cdr (assoc :type json)) "chat")
(enqueue-msg (cdr (assoc :text json))))
(getf sexp :scribe)
(getf sexp :gardener))))
((eq (getf sexp :type) :chat)
(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)))
(enqueue-msg line))))))
(error () (setf *is-running* nil)))

View File

@@ -39,7 +39,7 @@
(uiop:symbol-call :fiveam :run! (uiop:find-symbol* :immune-suite :opencortex-immune-system-tests))))
(defsystem :opencortex/tui
:depends-on (:opencortex :croatoan :usocket :bordeaux-threads :cl-json)
:depends-on (:opencortex :croatoan :usocket :bordeaux-threads)
:components ((:file "src/tui-client"))
:build-operation "program-op"
:build-pathname "opencortex-tui"

View File

@@ -61,7 +61,7 @@ The CLI actuator writes the agent's response back to the client's network stream
(handler-case
(if (and stream (open-stream-p stream))
(progn
(format stream "{\"type\": \"chat\", \"text\": \"~a\"}" text)
(prin1 (list :type :chat :text text) stream)
(terpri stream)
(finish-output stream))
(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
(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
((string= cmd "/status")
(format stream "{\"type\": \"status\", \"scribe\": \"idle\", \"gardener\": \"sleeping\"}")
(prin1 '(:type :status :scribe :idle :gardener :sleeping) stream)
(terpri stream)
(finish-output stream))
((string= cmd "/exit")
(format stream "{\"type\": \"info\", \"text\": \"Goodbye!\"}")
(prin1 '(:type :info :text "Goodbye!") stream)
(terpri 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)
(finish-output stream))))

View File

@@ -32,15 +32,20 @@
(let ((line (read-line *stream* nil :eof)))
(if (eq line :eof)
(setf *is-running* nil)
(let ((json (ignore-errors (cl-json:decode-json-from-string line))))
(if json
(let* ((*read-eval* nil)
(sexp (ignore-errors (read-from-string line))))
(if (and sexp (listp sexp))
(cond
((string= (cdr (assoc :type json)) "status")
((eq (getf sexp :type) :status)
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
(cdr (assoc :scribe json))
(cdr (assoc :gardener json)))))
((string= (cdr (assoc :type json)) "chat")
(enqueue-msg (cdr (assoc :text json))))
(getf sexp :scribe)
(getf sexp :gardener))))
((eq (getf sexp :type) :chat)
(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)))
(enqueue-msg line))))))
(error () (setf *is-running* nil)))