diff --git a/$MEMEX_DIR/state/memory-image.lisp b/$MEMEX_DIR/state/memory-image.lisp new file mode 100644 index 0000000..e69de29 diff --git a/docs/README.org b/docs/README.org index 8bdf4b0..33f06d6 100644 --- a/docs/README.org +++ b/docs/README.org @@ -413,7 +413,17 @@ The physical implementation of the daemon, tangled from this Org document into = (defvar *auth-providers* (make-hash-table :test 'equal)) (defun register-auth-provider (name fn) (setf (gethash name *auth-providers*) fn)) -(defun get-provider-auth (provider) (let ((auth-fn (gethash provider *auth-providers*))) (if auth-fn (funcall auth-fn) nil))) +(defun get-provider-auth (provider) + "Retrieves authentication credentials for a provider. + Supports direct plists, functions, or environment variable fallbacks." + (let ((auth (gethash provider *auth-providers*))) + (cond + ((functionp auth) (funcall auth)) + ((listp auth) auth) + (t (case provider + (:gemini (list :api-key (uiop:getenv "GEMINI_API_KEY"))) + (:openrouter (list :api-key (uiop:getenv "OPENROUTER_API_KEY"))) + (t nil)))))) (defvar *neuro-backends* (make-hash-table :test 'equal)) (defvar *provider-cascade* '(:gemini)) diff --git a/org-agent-server b/org-agent-server index b2317d7..6f84800 100755 Binary files a/org-agent-server and b/org-agent-server differ diff --git a/src/neuro.lisp b/src/neuro.lisp index a904417..80e27c8 100644 --- a/src/neuro.lisp +++ b/src/neuro.lisp @@ -4,7 +4,17 @@ (defvar *auth-providers* (make-hash-table :test 'equal)) (defun register-auth-provider (name fn) (setf (gethash name *auth-providers*) fn)) -(defun get-provider-auth (provider) (let ((auth-fn (gethash provider *auth-providers*))) (if auth-fn (funcall auth-fn) nil))) +(defun get-provider-auth (provider) + "Retrieves authentication credentials for a provider. + Supports direct plists, functions, or environment variable fallbacks." + (let ((auth (gethash provider *auth-providers*))) + (cond + ((functionp auth) (funcall auth)) + ((listp auth) auth) + (t (case provider + (:gemini (list :api-key (uiop:getenv "GEMINI_API_KEY"))) + (:openrouter (list :api-key (uiop:getenv "OPENROUTER_API_KEY"))) + (t nil)))))) (defvar *neuro-backends* (make-hash-table :test 'equal)) (defvar *provider-cascade* '(:gemini)) @@ -114,14 +124,12 @@ ((and (let ((p (getf context :payload))) (eq (getf p :sensor) :chat-message)) (> (length cleaned-thought) 0)) (kernel-log "SYSTEM 1: SALVAGING plain-text response.~%") - ;; Heuristic: If it looks like meta-commentary with quoted text, extract the quote - (let* ((quote-match (cl-ppcre:scan-to-strings "\"((?:\\\\.|[^\"\\\\])*)\"" cleaned-thought)) - (payload-text (if (and quote-match (> (length quote-match) 0)) - (elt (nth-value 1 (cl-ppcre:scan-to-strings "\"((?:\\\\.|[^\"\\\\])*)\"" cleaned-thought)) 0) - cleaned-thought))) + ;; Remove common AI conversational filler at the start or end of the response + (let* ((no-prefix (cl-ppcre:regex-replace "(?i)^(okay,? |sure,? |i will |i've |i have |here is |got it\\.? |understood\\.? |done\\.? |yes,? )+" cleaned-thought "")) + (no-suffix (cl-ppcre:regex-replace "(?i)(\\s+okay,?|\\s+sure,?|\\s+got it\\.?|\\s+understood\\.?)$" no-prefix "")) + (payload-text (string-trim '(#\Space #\Newline #\Tab #\") no-suffix))) `(:type :request :target :emacs :payload (:action :insert-at-end :buffer "*org-agent-chat*" :text ,payload-text)))) - (t (kernel-log "SYSTEM 1 ERROR: Could not parse response as Lisp plist.~%") nil))) - '(:type :LOG :payload (:text "Skill triggered (Deterministic only)"))))) + (t (kernel-log "SYSTEM 1 ERROR: Could not parse response as Lisp plist.~%") nil))) '(:type :LOG :payload (:text "Skill triggered (Deterministic only)"))))) nil))) (defun distill-prompt (full-prompt successful-output) diff --git a/src/org-agent.el b/src/org-agent.el index 0fb371a..f98060e 100644 --- a/src/org-agent.el +++ b/src/org-agent.el @@ -142,6 +142,18 @@ will assume you have started it manually (e.g., via SBCL)." (org-agent--execute-request proc id payload)) ((member type '(:response :RESPONSE)) (message "org-agent: Received response for ID %s" id)) + ((member type '(:log :LOG)) + (let ((text (org-agent--plist-get payload :text))) + (save-excursion + (with-current-buffer (get-buffer-create "*org-agent-chat*") + (goto-char (point-max)) + ;; Clean up Thinking... if it exists + (save-excursion + (when (search-backward "** Thinking..." nil t) + (delete-region (point) (point-max)) + (when (eq (char-before) ?\n) (backward-delete-char 1)))) + (goto-char (point-max)) + (insert "\n*SYSTEM LOG*: " text "\n"))))) (t (message "org-agent: Received unknown message type %s" type))))) (defun org-agent--execute-request (proc id payload) @@ -173,7 +185,7 @@ will assume you have started it manually (e.g., via SBCL)." (when (eq (char-before) ?\n) (backward-delete-char 1))) (goto-char (point-max)) - (insert "\n" text "\n") + (insert text "\n") (org-agent-send `(:type :RESPONSE :id ,id :payload (:status :success))))))) ((member action '(:refactor-subtree :REFACTOR-SUBTREE)) (let ((target-id (org-agent--plist-get payload :target-id))