From 8db786a33a41757f702fa880d44060faf3daf2db Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Sun, 19 Apr 2026 20:16:22 -0400 Subject: [PATCH] fix(protocol): Disable pretty-print during IO and handle NIL chat text --- literate/communication.org | 6 +++--- literate/tui-client.org | 2 +- src/communication.lisp | 6 +++--- src/tui-client.lisp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/literate/communication.org b/literate/communication.org index f36183e..b2f0db7 100644 --- a/literate/communication.org +++ b/literate/communication.org @@ -65,7 +65,7 @@ The ~frame-message~ function prepares an outgoing Lisp string for transmission. (defun frame-message (msg-string) "Prefixes MSG-STRING with a 6-character hex length. If security is enabled, prefixes a 64-char HMAC-SHA256 signature." - (let ((len (length msg-string)) + (let ((*print-pretty* nil) (len (length msg-string)) (enforce-hmac (uiop:getenv "PROTOCOL_ENFORCE_HMAC"))) (if (and enforce-hmac (string-equal enforce-hmac "true")) (let ((secret (uiop:getenv "PROTOCOL_HMAC_SECRET"))) @@ -114,7 +114,7 @@ Parsing is the high-security inverse of framing. This function acts as the final (error "communication protocol Integrity Failure: HMAC mismatch")))))) ;; SECURITY: Disable the reader's ability to execute code during parsing - (let ((*read-eval* nil)) + (let ((*read-eval* nil) (*print-pretty* nil)) (let ((msg (read-from-string actual-msg))) (validate-communication-protocol-schema msg) msg))))) @@ -156,7 +156,7 @@ A robust utility to read a framed message from a stream. It enforces the determi ;; 2. Read exactly LEN bytes (let ((msg-buffer (make-string len))) (read-sequence msg-buffer stream) - (let ((*read-eval* nil)) + (let ((*read-eval* nil) (*print-pretty* nil)) (let ((msg (read-from-string msg-buffer))) (validate-communication-protocol-schema msg) msg)))))) diff --git a/literate/tui-client.org b/literate/tui-client.org index 7763f29..98c89e9 100644 --- a/literate/tui-client.org +++ b/literate/tui-client.org @@ -66,7 +66,7 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro (or (getf msg :SCRIBE) (getf msg :scribe)) (or (getf msg :GARDENER) (getf msg :gardener))))) ((and (listp msg) (eq type :CHAT)) - (enqueue-msg (or (getf msg :TEXT) (getf msg :text)))) + (let ((text (or (getf msg :TEXT) (getf msg :text)))) (when text (enqueue-msg text)))) (t (harness-log "TUI: Ignored unknown type ~a" type))))) (when (eq raw-msg :eof) (setf *is-running* nil)) (when (eq raw-msg :error) (setf *status-text* "Protocol Error")))) diff --git a/src/communication.lisp b/src/communication.lisp index 49957e7..9366d13 100644 --- a/src/communication.lisp +++ b/src/communication.lisp @@ -10,7 +10,7 @@ (defun frame-message (msg-string) "Prefixes MSG-STRING with a 6-character hex length. If security is enabled, prefixes a 64-char HMAC-SHA256 signature." - (let ((len (length msg-string)) + (let ((*print-pretty* nil) (len (length msg-string)) (enforce-hmac (uiop:getenv "PROTOCOL_ENFORCE_HMAC"))) (if (and enforce-hmac (string-equal enforce-hmac "true")) (let ((secret (uiop:getenv "PROTOCOL_HMAC_SECRET"))) @@ -54,7 +54,7 @@ (error "communication protocol Integrity Failure: HMAC mismatch")))))) ;; SECURITY: Disable the reader's ability to execute code during parsing - (let ((*read-eval* nil)) + (let ((*read-eval* nil) (*print-pretty* nil)) (let ((msg (read-from-string actual-msg))) (validate-communication-protocol-schema msg) msg))))) @@ -85,7 +85,7 @@ ;; 2. Read exactly LEN bytes (let ((msg-buffer (make-string len))) (read-sequence msg-buffer stream) - (let ((*read-eval* nil)) + (let ((*read-eval* nil) (*print-pretty* nil)) (let ((msg (read-from-string msg-buffer))) (validate-communication-protocol-schema msg) msg)))))) diff --git a/src/tui-client.lisp b/src/tui-client.lisp index ccab0d9..c0af1f3 100644 --- a/src/tui-client.lisp +++ b/src/tui-client.lisp @@ -53,7 +53,7 @@ (or (getf msg :SCRIBE) (getf msg :scribe)) (or (getf msg :GARDENER) (getf msg :gardener))))) ((and (listp msg) (eq type :CHAT)) - (enqueue-msg (or (getf msg :TEXT) (getf msg :text)))) + (let ((text (or (getf msg :TEXT) (getf msg :text)))) (when text (enqueue-msg text)))) (t (harness-log "TUI: Ignored unknown type ~a" type))))) (when (eq raw-msg :eof) (setf *is-running* nil)) (when (eq raw-msg :error) (setf *status-text* "Protocol Error"))))