chore: workspace synchronization (sync inbox.org and staged deletions)

This commit is contained in:
2026-04-08 10:11:44 -04:00
parent e99e1744b9
commit d28eb0d765
393 changed files with 150 additions and 29218 deletions

View File

@@ -4,24 +4,35 @@
(eq sensor :chat-message)))
(defun verify-skill-chat (proposed-action context)
(if (and (eq (getf proposed-action :target) :emacs)
(eq (getf (getf proposed-action :payload) :action) :insert-at-end))
proposed-action
'(:target :emacs :action :message :text "Chat failed to format response.")))
(let* ((payload (getf proposed-action :payload))
(action (or (getf payload :action) (getf proposed-action :action)))
(target (getf proposed-action :target)))
(if (and (listp proposed-action)
(or (and (member (getf proposed-action :type) '(:request :REQUEST))
(or (and (member target '(:emacs :EMACS))
(member action '(:insert-at-end :INSERT-AT-END)))
(and (member target '(:shell :SHELL))
(or (getf payload :cmd) (getf proposed-action :cmd)))
(member target '(:tool :TOOL))))
(member (getf proposed-action :type) '(:response :RESPONSE :log :LOG))))
proposed-action
(let ((err-text (format nil "\n\n*System Error:* Chat agent returned invalid action: ~s" proposed-action)))
`(:type :request :target :emacs :payload (:action :insert-at-end :buffer "*org-agent-chat*" :text ,err-text))))))
(defun neuro-skill-chat (context)
"Generates a conversational response using the PSF Identity persona,
mandating an s-expression return format."
"Generates a conversational response, stripping system errors from context."
(let* ((payload (getf context :payload))
(text (getf payload :text))
(user (or (uiop:getenv "MEMEX_USER") "User"))
(assistant (or (uiop:getenv "MEMEX_ASSISTANT") "Passepartout")))
(ask-neuro text :system-prompt (format nil "You are ~a, the sovereign assistant to ~a.
Follow the PSF Org Mandate: speak in Org-mode subtrees.
Never use double asterisks for bold; use single asterisks.
(raw-text (getf payload :text))
;; Context Purge: Remove system errors and hallucinations from the history
(clean-text (cl-ppcre:regex-replace-all "(?i)Unknown request|System Error.*|Thinking\\.\\.\\." raw-text ""))
(trimmed-text (if (> (length clean-text) 1000)
(subseq clean-text (- (length clean-text) 1000))
clean-text)))
(ask-neuro trimmed-text :system-prompt "ACTUATOR IDENTITY: You are the pure Lisp actuator for the org-agent kernel.
MANDATE: Output EXACTLY ONE Common Lisp property list starting with (:type :REQUEST).
ZERO CONVERSATION: Do not explain. Do not use markdown.
STRICT RULE: Never output the strings 'Unknown request' or 'System Error'.
CRITICAL INSTRUCTION:
You are communicating directly with a Common Lisp microkernel. You MUST return your response as a single, valid Common Lisp property list (plist). Do NOT return any markdown formatting, backticks, or plain text outside the plist.
Your response MUST exactly match this structure:
(:target :emacs :payload (:action :insert-at-end :buffer \"*org-agent-chat*\" :text \"<your org-mode response here>\"))" assistant user))))
REQUIRED FORMATS:
- To reply: (:type :REQUEST :target :emacs :action :insert-at-end :buffer \"*org-agent-chat*\" :text \"* <Response>\")
- To use a tool: (:type :REQUEST :target :tool :action :call :tool \"<name>\" :args (...))")))

View File

@@ -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)))))))