From cce760932ecea722357d5ffef7ce0c5fdb1b078a Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Sun, 19 Apr 2026 17:11:53 -0400 Subject: [PATCH] fix(kernel): Enable Universal Reasoning Fallback (resolves Bouncer-hijacking bug) --- literate/reason.org | 30 ++++++++++++++---------------- literate/skills.org | 5 +++-- src/reason.lisp | 30 ++++++++++++++---------------- src/skills.lisp | 5 +++-- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/literate/reason.org b/literate/reason.org index cf31d16..5b8e9cd 100644 --- a/literate/reason.org +++ b/literate/reason.org @@ -61,22 +61,20 @@ The `think` function represents the "intuitive" side of the agent. It identifies (global-context (context-assemble-global-awareness)) (system-logs (context-get-system-logs)) (assistant-name (or (uiop:getenv "MEMEX_ASSISTANT") "Agent"))) - (if active-skill - (let* ((prompt-generator (skill-probabilistic-prompt active-skill)) - (raw-prompt (when prompt-generator (funcall prompt-generator context))) - (system-prompt (format nil "IDENTITY: Actuator for ~a. MANDATE: ONE Lisp plist. ~a ~a RECENT_LOGS: ~a" - assistant-name global-context tool-belt system-logs))) - (if (and raw-prompt (> (length raw-prompt) 1)) - (let* ((thought (probabilistic-call raw-prompt :system-prompt system-prompt :context context)) - ;; Ensure we are working with a string for read-from-string - (cleaned (if (stringp thought) (string-trim '(#\Space #\Newline #\Tab) thought) thought))) - (if (stringp cleaned) - (let ((*read-eval* nil)) - (handler-case (read-from-string cleaned) - (error (c) (list :type :EVENT :payload (list :sensor :syntax-error :code cleaned :error (format nil "~a" c)))))) - cleaned)) - (list :type :LOG :payload (list :text (format nil "Skill '~a' triggered (Deterministic only)" (skill-name active-skill)))))) - nil))) + (let* ((prompt-generator (when active-skill (skill-probabilistic-prompt active-skill))) + (raw-prompt (if prompt-generator + (funcall prompt-generator context) + (let ((p (proto-get (proto-get context :payload) :text))) + (if (and p (stringp p)) p "Maintain metabolic stasis.")))) + (system-prompt (format nil "IDENTITY: ~a. MANDATE: Respond with ONE Lisp plist. ~a ~a RECENT_LOGS: ~a" + assistant-name global-context tool-belt system-logs))) + (let* ((thought (probabilistic-call raw-prompt :system-prompt system-prompt :context context)) + (cleaned (if (stringp thought) (string-trim '(#\Space #\Newline #\Tab) thought) thought))) + (if (stringp cleaned) + (let ((*read-eval* nil)) + (handler-case (read-from-string cleaned) + (error (c) (list :type :EVENT :payload (list :sensor :syntax-error :code cleaned :error (format nil "~a" c)))))) + cleaned))))) #+end_src ** Deterministic Verification diff --git a/literate/skills.org b/literate/skills.org index 050aae3..e0c4be7 100644 --- a/literate/skills.org +++ b/literate/skills.org @@ -30,11 +30,12 @@ A static, hardcoded architecture is inherently fragile. The ~opencortex~ Skill E (load-time 0)) (defun find-triggered-skill (context) - "Returns the highest priority skill whose trigger condition matches the context." + "Returns the highest priority skill whose trigger matches context AND has a probabilistic prompt." (let ((triggered nil)) (maphash (lambda (name skill) (declare (ignore name)) - (when (ignore-errors (funcall (skill-trigger-fn skill) context)) + (when (and (skill-probabilistic-prompt skill) + (ignore-errors (funcall (skill-trigger-fn skill) context))) (push skill triggered))) *skills-registry*) (first (sort triggered #'> :key #'skill-priority)))) diff --git a/src/reason.lisp b/src/reason.lisp index 78bdaf7..40ce913 100644 --- a/src/reason.lisp +++ b/src/reason.lisp @@ -36,22 +36,20 @@ (global-context (context-assemble-global-awareness)) (system-logs (context-get-system-logs)) (assistant-name (or (uiop:getenv "MEMEX_ASSISTANT") "Agent"))) - (if active-skill - (let* ((prompt-generator (skill-probabilistic-prompt active-skill)) - (raw-prompt (when prompt-generator (funcall prompt-generator context))) - (system-prompt (format nil "IDENTITY: Actuator for ~a. MANDATE: ONE Lisp plist. ~a ~a RECENT_LOGS: ~a" - assistant-name global-context tool-belt system-logs))) - (if (and raw-prompt (> (length raw-prompt) 1)) - (let* ((thought (probabilistic-call raw-prompt :system-prompt system-prompt :context context)) - ;; Ensure we are working with a string for read-from-string - (cleaned (if (stringp thought) (string-trim '(#\Space #\Newline #\Tab) thought) thought))) - (if (stringp cleaned) - (let ((*read-eval* nil)) - (handler-case (read-from-string cleaned) - (error (c) (list :type :EVENT :payload (list :sensor :syntax-error :code cleaned :error (format nil "~a" c)))))) - cleaned)) - (list :type :LOG :payload (list :text (format nil "Skill '~a' triggered (Deterministic only)" (skill-name active-skill)))))) - nil))) + (let* ((prompt-generator (when active-skill (skill-probabilistic-prompt active-skill))) + (raw-prompt (if prompt-generator + (funcall prompt-generator context) + (let ((p (proto-get (proto-get context :payload) :text))) + (if (and p (stringp p)) p "Maintain metabolic stasis.")))) + (system-prompt (format nil "IDENTITY: ~a. MANDATE: Respond with ONE Lisp plist. ~a ~a RECENT_LOGS: ~a" + assistant-name global-context tool-belt system-logs))) + (let* ((thought (probabilistic-call raw-prompt :system-prompt system-prompt :context context)) + (cleaned (if (stringp thought) (string-trim '(#\Space #\Newline #\Tab) thought) thought))) + (if (stringp cleaned) + (let ((*read-eval* nil)) + (handler-case (read-from-string cleaned) + (error (c) (list :type :EVENT :payload (list :sensor :syntax-error :code cleaned :error (format nil "~a" c)))))) + cleaned))))) (defun deterministic-verify (proposed-action context) "Iterates through all skill deterministic-gates sorted by priority." diff --git a/src/skills.lisp b/src/skills.lisp index 0bab583..334ccc6 100644 --- a/src/skills.lisp +++ b/src/skills.lisp @@ -17,11 +17,12 @@ (load-time 0)) (defun find-triggered-skill (context) - "Returns the highest priority skill whose trigger condition matches the context." + "Returns the highest priority skill whose trigger matches context AND has a probabilistic prompt." (let ((triggered nil)) (maphash (lambda (name skill) (declare (ignore name)) - (when (ignore-errors (funcall (skill-trigger-fn skill) context)) + (when (and (skill-probabilistic-prompt skill) + (ignore-errors (funcall (skill-trigger-fn skill) context))) (push skill triggered))) *skills-registry*) (first (sort triggered #'> :key #'skill-priority))))