chore: workspace synchronization (sync inbox.org and staged deletions)
This commit is contained in:
@@ -4,16 +4,35 @@
|
||||
|
||||
(defun stream-to-emacs (stream action-plist)
|
||||
"Streams a chunk of data to a specific Emacs client over OACP using framing."
|
||||
(let* ((msg (prin1-to-string action-plist))
|
||||
(let* ((type (or (getf action-plist :type) :request))
|
||||
(payload (getf action-plist :payload))
|
||||
;; Ensure Emacs always receives a :payload drawer
|
||||
(envelope (if (and (getf action-plist :type) payload)
|
||||
action-plist
|
||||
(let ((clean-payload (copy-list action-plist)))
|
||||
(remf clean-payload :type)
|
||||
(remf clean-payload :id)
|
||||
(list :type type
|
||||
:id (or (getf action-plist :id) (get-universal-time))
|
||||
:payload clean-payload))))
|
||||
(msg (prin1-to-string envelope))
|
||||
(len (length msg))
|
||||
(framed (format nil "~6,'0x~a" len msg)))
|
||||
(write-string framed stream)
|
||||
(finish-output stream)))
|
||||
(handler-case
|
||||
(progn
|
||||
(write-string framed stream)
|
||||
(finish-output stream))
|
||||
(error (c)
|
||||
(kernel-log "BRIDGE - Lost client: ~a" stream)
|
||||
(org-agent:unregister-emacs-client stream)))))
|
||||
|
||||
(defun broadcast-to-emacs (action-plist context)
|
||||
"Sends a framed message back to the client that sent the stimulus."
|
||||
"Sends a framed message back to the client that sent the stimulus, or all clients if async."
|
||||
(let ((stream (getf context :reply-stream)))
|
||||
(if stream
|
||||
(handler-case (stream-to-emacs stream action-plist)
|
||||
(error (c) (kernel-log "BRIDGE ERROR: Failed to write to Emacs: ~a" c)))
|
||||
(kernel-log "BRIDGE ERROR: No reply-stream in context."))))
|
||||
(stream-to-emacs stream action-plist)
|
||||
(progn
|
||||
(kernel-log "BRIDGE - Async broadcast to all clients...")
|
||||
(bt:with-lock-held (org-agent:*clients-lock*)
|
||||
(dolist (s org-agent:*emacs-clients*)
|
||||
(stream-to-emacs s action-plist)))))))
|
||||
|
||||
Reference in New Issue
Block a user