ALIGN: Rename Protocol to Communication and unify terminology
This commit is contained in:
@@ -88,8 +88,8 @@
|
||||
:trigger (lambda (ctx)
|
||||
(or (eq (getf (getf ctx :payload) :sensor) :approval-required)
|
||||
(eq (getf (getf ctx :payload) :sensor) :heartbeat)))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action context)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action context)
|
||||
(declare (ignore action))
|
||||
(let* ((payload (getf context :payload))
|
||||
(sensor (getf payload :sensor)))
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
(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)
|
||||
(defun probabilistic-skill-chat (context)
|
||||
"Generates a conversational response, stripping system errors from context."
|
||||
(let* ((payload (getf context :payload))
|
||||
(raw-text (getf payload :text))
|
||||
@@ -66,7 +66,7 @@
|
||||
(:signal (format nil "- To reply via Signal: (:type :REQUEST :target :signal :chat-id \"~a\" :text \"<Response>\")" chat-id))
|
||||
(:matrix (format nil "- To reply via Matrix: (:type :REQUEST :target :matrix :room-id \"~a\" :text \"<Response>\")" chat-id))
|
||||
(t "- To reply via Emacs: (:type :REQUEST :target :emacs :action :insert-at-end :buffer \"*org-agent-chat*\" :text \"* <Response>\")"))))
|
||||
(ask-neuro trimmed-text :system-prompt (concatenate 'string
|
||||
(ask-probabilistic trimmed-text :system-prompt (concatenate 'string
|
||||
"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.
|
||||
@@ -79,5 +79,5 @@ REQUIRED FORMATS:
|
||||
(defskill :skill-chat
|
||||
:priority 100
|
||||
:trigger #'trigger-skill-chat
|
||||
:neuro #'neuro-skill-chat
|
||||
:symbolic #'verify-skill-chat)
|
||||
:probabilistic #'probabilistic-skill-chat
|
||||
:deterministic #'verify-skill-chat)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
(use-hmac (and enforce-hmac (string-equal enforce-hmac "true")))
|
||||
(prefix-len (if use-hmac 70 6)))
|
||||
(when (< (length framed-string) prefix-len)
|
||||
(error "Framed string too short for Harness Protocol prefix"))
|
||||
(error "Framed string too short for Harness Communication prefix"))
|
||||
|
||||
(let* ((len-str (subseq framed-string 0 6))
|
||||
(signature (when use-hmac (subseq framed-string 6 70)))
|
||||
@@ -51,7 +51,7 @@
|
||||
(ironclad:update-mac hmac payload-bytes)
|
||||
(let ((expected-signature (ironclad:byte-array-to-hex-string (ironclad:produce-mac hmac))))
|
||||
(unless (string-equal signature expected-signature)
|
||||
(error "Harness Protocol Integrity Failure: HMAC mismatch"))))))
|
||||
(error "Harness Communication Integrity Failure: HMAC mismatch"))))))
|
||||
|
||||
;; SECURITY: Disable the reader's ability to execute code during parsing
|
||||
(let ((*read-eval* nil))
|
||||
@@ -64,9 +64,9 @@
|
||||
:priority 90
|
||||
:dependencies ("org-skill-embedding")
|
||||
:trigger (lambda (ctx) (member (getf (getf ctx :payload) :sensor) '(:perceive :context-refresh)))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(declare (ignore action ctx))
|
||||
;; This skill primarily provides the context-assemble-global-awareness function
|
||||
;; used by the neuro-gate, rather than handling specific actions.
|
||||
;; used by the probabilistic-gate, rather than handling specific actions.
|
||||
nil))
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
(defskill :skill-credentials-vault
|
||||
:priority 200 ; High priority, foundational
|
||||
:trigger (lambda (ctx) (eq (getf (getf ctx :payload) :sensor) :onboarding-request))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(vault-onboard-gemini-web)
|
||||
action)))
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
(in-package :org-agent)
|
||||
|
||||
(defun decide (proposed-action context)
|
||||
"The Deterministic Safety Gate: iterates through all skill symbolic-gates sorted by priority."
|
||||
"The Deterministic Safety Gate: iterates through all skill deterministic-gates sorted by priority."
|
||||
(let ((current-action proposed-action)
|
||||
(skills nil))
|
||||
;; 1. Collect all skills with symbolic gates
|
||||
;; 1. Collect all skills with deterministic gates
|
||||
(maphash (lambda (name skill)
|
||||
(declare (ignore name))
|
||||
(when (skill-symbolic-fn skill)
|
||||
(when (skill-deterministic-fn skill)
|
||||
(push skill skills)))
|
||||
*skills-registry*)
|
||||
|
||||
;; 2. Sort skills by priority (highest first)
|
||||
(setf skills (sort skills #'> :key #'skill-priority))
|
||||
|
||||
;; 3. Execute symbolic gates sequentially
|
||||
;; 3. Execute deterministic gates sequentially
|
||||
(dolist (skill skills)
|
||||
(let ((gate (skill-symbolic-fn skill)))
|
||||
(let ((gate (skill-deterministic-fn skill)))
|
||||
(setf current-action (funcall gate current-action context))
|
||||
;; If any gate returns a LOG or EVENT (blocking/intercepting), stop and return it.
|
||||
(when (and (listp current-action)
|
||||
@@ -51,8 +51,8 @@
|
||||
(defskill :skill-embedding
|
||||
:priority 50
|
||||
:trigger (lambda (ctx) (eq (getf (getf ctx :payload) :sensor) :embedding-request))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(declare (ignore ctx))
|
||||
(case (getf action :action)
|
||||
(:get-embedding (get-embedding (getf action :text)))
|
||||
|
||||
@@ -26,5 +26,5 @@
|
||||
(org-agent:defskill :skill-engineering-standards
|
||||
:priority 900 ; High priority, runs before most skills
|
||||
:trigger (lambda (ctx) t) ; Always active
|
||||
:neuro nil
|
||||
:symbolic #'engineering-standards-gate)
|
||||
:probabilistic nil
|
||||
:deterministic #'engineering-standards-gate)
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
(defskill :skill-event-orchestrator
|
||||
:priority 400 ; Foundational control layer
|
||||
:trigger (lambda (ctx) (eq (getf (getf ctx :payload) :sensor) :heartbeat))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(orchestrator-process-cron)
|
||||
action)))
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
(defskill :skill-gateway-matrix
|
||||
:priority 150
|
||||
:trigger (lambda (ctx) (declare (ignore ctx)) nil)
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
|
||||
(start-matrix-gateway)
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
(defskill :skill-gateway-signal
|
||||
:priority 150
|
||||
:trigger (lambda (ctx) (declare (ignore ctx)) nil) ;; Passive
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
|
||||
(start-signal-gateway)
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
(defskill :skill-gateway-telegram
|
||||
:priority 150
|
||||
:trigger (lambda (ctx) (declare (ignore ctx)) nil) ;; Passive, handles its own loop
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
|
||||
(start-telegram-gateway)
|
||||
|
||||
@@ -32,5 +32,5 @@
|
||||
(defskill :skill-harness-monitor
|
||||
:priority 100
|
||||
:trigger (lambda (context) t)
|
||||
:neuro (lambda (context) \"You are the Harness Monitor. Use your tools to provide system visibility.\")
|
||||
:symbolic (lambda (action context) action))
|
||||
:probabilistic (lambda (context) \"You are the Harness Monitor. Use your tools to provide system visibility.\")
|
||||
:deterministic (lambda (action context) action))
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
(defskill :skill-homoiconic-memory
|
||||
:priority 300 ; Core foundational skill
|
||||
:trigger (lambda (ctx) (member (getf (getf ctx :payload) :sensor) '(:buffer-save :ingest)))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(let ((ast (getf (getf ctx :payload) :ast)))
|
||||
(when ast (memory-normalize-ast ast))
|
||||
action))))
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
(setf *last-reflection-time* now)
|
||||
t)
|
||||
nil)))
|
||||
:neuro (lambda (ctx)
|
||||
:probabilistic (lambda (ctx)
|
||||
(declare (ignore ctx))
|
||||
(let* ((memories (sample-random-memories 3))
|
||||
(context-string "LATENT REFLECTION CANDIDATES:\n"))
|
||||
@@ -58,7 +58,7 @@ Find hidden connections, suggest new tags, or propose a new insight that bridges
|
||||
MANDATE: Output EXACTLY ONE Common Lisp property list starting with (:type :REQUEST).
|
||||
Use the :emacs target and :insert-at-end action to write your reflection into the \"*org-agent-chat*\" buffer."
|
||||
context-string)))
|
||||
:symbolic (lambda (action ctx)
|
||||
:deterministic (lambda (action ctx)
|
||||
(declare (ignore ctx))
|
||||
;; Approve any safe request
|
||||
action))
|
||||
|
||||
@@ -24,14 +24,14 @@ CODE: ~a
|
||||
MANDATE: Output EXACTLY ONE valid Common Lisp list. Do not explain. Do not use markdown blocks."
|
||||
error-message code))
|
||||
(system-prompt "You are a Lisp Syntax Repair Actuator. Return only valid, balanced Lisp code."))
|
||||
(let ((repaired (ask-neuro prompt :system-prompt system-prompt)))
|
||||
(let ((repaired (ask-probabilistic prompt :system-prompt system-prompt)))
|
||||
(string-trim '(#\Space #\Newline #\Tab) repaired))))
|
||||
|
||||
(defskill :skill-lisp-repair
|
||||
:priority 90
|
||||
:trigger (lambda (ctx) (eq (getf (getf ctx :payload) :sensor) :syntax-error))
|
||||
:neuro nil ;; Handled deterministically in symbolic or manually via ask-neuro
|
||||
:symbolic (lambda (action context)
|
||||
:probabilistic nil ;; Handled deterministically in deterministic or manually via ask-probabilistic
|
||||
:deterministic (lambda (action context)
|
||||
(declare (ignore action))
|
||||
(let* ((payload (getf context :payload))
|
||||
(code (getf payload :code))
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
(when candidate
|
||||
(let ((payload (getf candidate :payload)))
|
||||
(member (getf payload :action) '(:eval :shell))))))
|
||||
:neuro nil ; Purely deterministic/safety skill
|
||||
:symbolic (lambda (action context)
|
||||
:probabilistic nil ; Purely deterministic/safety skill
|
||||
:deterministic (lambda (action context)
|
||||
(harness-log "DETERMINISTIC ENGINE [Lisp-Validator]: Intercepted critical action for structural validation.")
|
||||
action))
|
||||
|
||||
@@ -82,11 +82,11 @@
|
||||
:model (getf args :model))))
|
||||
|
||||
(dolist (p '(:anthropic :gemini-api :gemini-web :groq :ollama :openai :openrouter))
|
||||
(org-agent:register-neuro-backend p (lambda (prompt system-prompt &key model)
|
||||
(org-agent:register-probabilistic-backend p (lambda (prompt system-prompt &key model)
|
||||
(execute-llm-request prompt system-prompt :provider p :model model))))
|
||||
|
||||
(defskill :skill-llm-gateway
|
||||
:priority 150 ; Higher than individual old skills
|
||||
:trigger (lambda (context) (declare (ignore context)) nil)
|
||||
:neuro (lambda (context) (declare (ignore context)) nil)
|
||||
:symbolic (lambda (action context) (declare (ignore context)) action))
|
||||
:probabilistic (lambda (context) (declare (ignore context)) nil)
|
||||
:deterministic (lambda (action context) (declare (ignore context)) action))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;;; org-agent.el --- Neurosymbolic Lisp Machine Kernel for Org-mode -*- lexical-binding: t; -*-
|
||||
;;; org-agent.el --- Probabilistic-Deterministic Lisp Machine Kernel for Org-mode -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2026 Amr
|
||||
;;
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; org-agent provides a Neurosymbolic Lisp Machine interface for Emacs.
|
||||
;; org-agent provides a Probabilistic-Deterministic Lisp Machine interface for Emacs.
|
||||
;; It acts as the sensor/actuator array, communicating with a persistent
|
||||
;; Common Lisp daemon over a high-speed Harness Protocol socket.
|
||||
;; Common Lisp daemon over a high-speed Harness Communication socket.
|
||||
|
||||
;;; Code:
|
||||
|
||||
@@ -100,7 +100,7 @@ will assume you have started it manually (e.g., via SBCL)."
|
||||
(message "org-agent: Killed daemon process.")))
|
||||
|
||||
(defun org-agent--filter (proc string)
|
||||
"Handle incoming Harness Protocol messages from the daemon via PROC with STRING."
|
||||
"Handle incoming Harness Communication messages from the daemon via PROC with STRING."
|
||||
(let ((buf (process-buffer proc)))
|
||||
(when (buffer-live-p buf)
|
||||
(with-current-buffer buf
|
||||
@@ -109,7 +109,7 @@ will assume you have started it manually (e.g., via SBCL)."
|
||||
(org-agent--process-buffer buf proc)))))
|
||||
|
||||
(defun org-agent--process-buffer (buffer &optional proc)
|
||||
"Process the Harness Protocol message BUFFER, optionally using PROC."
|
||||
"Process the Harness Communication message BUFFER, optionally using PROC."
|
||||
(with-current-buffer buffer
|
||||
(goto-char (point-min))
|
||||
(while (>= (buffer-size) 6)
|
||||
@@ -127,13 +127,13 @@ will assume you have started it manually (e.g., via SBCL)."
|
||||
(setq msg-len 1000000)))))) ; Break loop
|
||||
|
||||
(defun org-agent--plist-get (plist prop)
|
||||
"Case-insensitive keyword lookup for Harness Protocol compatibility."
|
||||
"Case-insensitive keyword lookup for Harness Communication compatibility."
|
||||
(or (plist-get plist prop)
|
||||
(plist-get plist (intern (upcase (symbol-name prop))))
|
||||
(plist-get plist (intern (downcase (symbol-name prop))))))
|
||||
|
||||
(defun org-agent--handle-message (proc plist)
|
||||
"Route and execute incoming Harness Protocol messages from PROC using PLIST."
|
||||
"Route and execute incoming Harness Communication messages from PROC using PLIST."
|
||||
(let ((type (org-agent--plist-get plist :type))
|
||||
(id (org-agent--plist-get plist :id))
|
||||
(payload (or (org-agent--plist-get plist :payload) plist)))
|
||||
@@ -190,7 +190,7 @@ will assume you have started it manually (e.g., via SBCL)."
|
||||
(message "org-agent: Connection lost.")))
|
||||
|
||||
(defun org-agent-send (plist)
|
||||
"Send a Lisp PLIST to the daemon using Harness Protocol framing."
|
||||
"Send a Lisp PLIST to the daemon using Harness Communication framing."
|
||||
(let* ((msg (prin1-to-string plist))
|
||||
(len (length msg))
|
||||
(framed (format "%06x%s" len msg)))
|
||||
@@ -401,7 +401,7 @@ Opens a history buffer and a dedicated input area."
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode org-agent-mode
|
||||
"Global minor mode for the org-agent Neurosymbolic kernel.
|
||||
"Global minor mode for the org-agent Probabilistic-Deterministic kernel.
|
||||
When enabled, this mode starts the Lisp daemon (if configured)
|
||||
and establishes the network connection to enable proactive
|
||||
Org-mode sensing."
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(defpackage :org-agent
|
||||
(:use :cl)
|
||||
(:export
|
||||
;; --- Harness Protocol ---
|
||||
;; --- Harness Communication ---
|
||||
#:frame-message
|
||||
#:parse-message
|
||||
#:make-hello-message
|
||||
@@ -47,7 +47,7 @@
|
||||
;; --- Reactive Signal Pipeline ---
|
||||
#:process-signal
|
||||
#:perceive-gate
|
||||
#:neuro-gate
|
||||
#:probabilistic-gate
|
||||
#:consensus-gate
|
||||
#:decide-gate
|
||||
#:dispatch-gate
|
||||
@@ -69,8 +69,8 @@
|
||||
#:skill-priority
|
||||
#:skill-dependencies
|
||||
#:skill-trigger-fn
|
||||
#:skill-neuro-prompt
|
||||
#:skill-symbolic-fn
|
||||
#:skill-probabilistic-prompt
|
||||
#:skill-deterministic-fn
|
||||
|
||||
;; --- Tool Registry ---
|
||||
#:def-cognitive-tool
|
||||
@@ -89,12 +89,12 @@
|
||||
#:unregister-emacs-client
|
||||
|
||||
;; --- Probabilistic Engine ---
|
||||
#:ask-neuro
|
||||
#:register-neuro-backend
|
||||
#:ask-probabilistic
|
||||
#:register-probabilistic-backend
|
||||
#:distill-prompt
|
||||
#:*provider-cascade*
|
||||
|
||||
;; --- Symbolic Logic ---
|
||||
;; --- Deterministic Logic ---
|
||||
#:list-objects-with-attribute
|
||||
#:decide
|
||||
|
||||
|
||||
@@ -34,5 +34,5 @@
|
||||
(defskill :skill-playwright
|
||||
:priority 150
|
||||
:trigger (lambda (ctx) (declare (ignore ctx)) nil) ; Passive tool provider
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx) (declare (ignore ctx)) action))
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
(defskill :skill-policy-enforcer
|
||||
:priority 1000 ; Absolute highest priority
|
||||
:trigger (lambda (context) t) ; Always active as a fallback
|
||||
:neuro (lambda (context)
|
||||
:probabilistic (lambda (context)
|
||||
\"You are the Org-Agent Policy Enforcer. Your goal is to ensure all actions empower the user through the Lisp Machine and adhere to the System Policy.\")
|
||||
:symbolic (lambda (action context)
|
||||
:deterministic (lambda (action context)
|
||||
;; Basic invariant check: Block actions that appear to violate sovereignty
|
||||
(let ((payload (getf action :payload)))
|
||||
(if (and payload (search \"proprietary\" (format nil \"~s\" payload)))
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
(in-package :org-agent)
|
||||
|
||||
(defvar *neuro-backends* (make-hash-table :test 'equal))
|
||||
(defvar *probabilistic-backends* (make-hash-table :test 'equal))
|
||||
|
||||
(defvar *provider-cascade* nil)
|
||||
|
||||
(defun register-neuro-backend (name fn) (setf (gethash name *neuro-backends*) fn))
|
||||
(defun register-probabilistic-backend (name fn) (setf (gethash name *probabilistic-backends*) fn))
|
||||
|
||||
(defvar *model-selector-fn* nil "A function called with (provider context) to return a model ID.")
|
||||
|
||||
(defvar *consensus-enabled-p* nil "If T, ask-neuro queries all backends in parallel.")
|
||||
(defvar *consensus-enabled-p* nil "If T, ask-probabilistic queries all backends in parallel.")
|
||||
|
||||
(defun ask-neuro (prompt &key (system-prompt "You are the Probabilistic engine of a Neurosymbolic Lisp Machine.") (cascade nil) (context nil))
|
||||
(defun ask-probabilistic (prompt &key (system-prompt "You are the Probabilistic engine of a Probabilistic-Deterministic Lisp Machine.") (cascade nil) (context nil))
|
||||
"Dispatches a neural request through the provider cascade or parallel consensus."
|
||||
(let ((backends (cond
|
||||
((and cascade (listp cascade)) cascade)
|
||||
@@ -22,7 +22,7 @@
|
||||
(threads nil)
|
||||
(lock (bt:make-lock)))
|
||||
(dolist (backend backends)
|
||||
(let ((backend-fn (gethash backend *neuro-backends*)))
|
||||
(let ((backend-fn (gethash backend *probabilistic-backends*)))
|
||||
(when backend-fn
|
||||
(push (bt:make-thread
|
||||
(lambda ()
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
;; SEQUENTIAL CASCADE MODE
|
||||
(or (dolist (backend backends)
|
||||
(let ((backend-fn (gethash backend *neuro-backends*)))
|
||||
(let ((backend-fn (gethash backend *probabilistic-backends*)))
|
||||
(when backend-fn
|
||||
(harness-log "PROBABILISTIC: Attempting backend ~a..." backend)
|
||||
(let* ((model (when *model-selector-fn* (funcall *model-selector-fn* backend context)))
|
||||
@@ -68,7 +68,7 @@
|
||||
(if active-skill
|
||||
(progn
|
||||
(harness-log "PROBABILISTIC: Engaging skill '~a'~%" (skill-name active-skill))
|
||||
(let* ((prompt-generator (skill-neuro-prompt active-skill))
|
||||
(let* ((prompt-generator (skill-probabilistic-prompt active-skill))
|
||||
(raw-prompt (when prompt-generator (funcall prompt-generator context)))
|
||||
(full-system-prompt (concatenate 'string
|
||||
"ACTUATOR IDENTITY: You are the pure Lisp actuator for the org-agent kernel.
|
||||
@@ -91,7 +91,7 @@ To call a tool, you MUST use:
|
||||
|
||||
")))
|
||||
(if (and raw-prompt (> (length raw-prompt) 1))
|
||||
(let* ((thought (ask-neuro raw-prompt :system-prompt full-system-prompt :context context))
|
||||
(let* ((thought (ask-probabilistic raw-prompt :system-prompt full-system-prompt :context context))
|
||||
(raw-thoughts (cl-ppcre:split (cl-ppcre:quote-meta-chars "|CONSENSUS-SEP|") thought))
|
||||
(suggestions nil))
|
||||
(dolist (raw-thought raw-thoughts)
|
||||
@@ -120,4 +120,4 @@ To call a tool, you MUST use:
|
||||
|
||||
(defun distill-prompt (full-prompt successful-output)
|
||||
(let ((system-instr "You are a Meta-Cognitive Prompt Architect. DISTILL into template."))
|
||||
(ask-neuro (format nil "PROMPT: ~a~%RESULT: ~a" full-prompt successful-output) :system-prompt system-instr)))
|
||||
(ask-probabilistic (format nil "PROMPT: ~a~%RESULT: ~a" full-prompt successful-output) :system-prompt system-instr)))
|
||||
@@ -6,12 +6,12 @@
|
||||
(member "!archive" tags :test #'string-equal))
|
||||
|
||||
(in-package :org-agent)
|
||||
(defun neuro-skill-inbox-processor (context)
|
||||
(defun probabilistic-skill-inbox-processor (context)
|
||||
(let* ((payload (getf context :payload))
|
||||
(content (getf payload :content))
|
||||
(tags (getf payload :tags))
|
||||
(is-archive (inbox-is-archive-p tags)))
|
||||
(ask-neuro content :system-prompt
|
||||
(ask-probabilistic content :system-prompt
|
||||
(format nil "You are the PSF Librarian. Your goal is to ENRICH this Org-mode capture.
|
||||
RULES:
|
||||
1. Create a '** Summary' sub-heading with a 1-sentence summary.
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
(in-package :org-agent)
|
||||
|
||||
(defun validate-harness-protocol-schema (msg)
|
||||
"Strict structural validation for incoming Harness Protocol messages."
|
||||
"Strict structural validation for incoming Harness Communication messages."
|
||||
(unless (listp msg)
|
||||
(error "Harness Protocol Schema Error: Message must be a property list (got ~s)" (type-of msg)))
|
||||
(error "Harness Communication Schema Error: Message must be a property list (got ~s)" (type-of msg)))
|
||||
|
||||
(let ((type (getf msg :type)))
|
||||
(unless (member type '(:REQUEST :EVENT :RESPONSE :LOG))
|
||||
(error "Harness Protocol Schema Error: Invalid message type '~a'" type))
|
||||
(error "Harness Communication Schema Error: Invalid message type '~a'" type))
|
||||
|
||||
(case type
|
||||
(:REQUEST
|
||||
(unless (getf msg :target)
|
||||
(error "Harness Protocol Schema Error: REQUEST missing mandatory :target"))
|
||||
(error "Harness Communication Schema Error: REQUEST missing mandatory :target"))
|
||||
(unless (getf msg :payload)
|
||||
(error "Harness Protocol Schema Error: REQUEST missing mandatory :payload")))
|
||||
(error "Harness Communication Schema Error: REQUEST missing mandatory :payload")))
|
||||
|
||||
(:EVENT
|
||||
(let ((payload (getf msg :payload)))
|
||||
(unless (and payload (listp payload))
|
||||
(error "Harness Protocol Schema Error: EVENT missing or invalid :payload"))
|
||||
(error "Harness Communication Schema Error: EVENT missing or invalid :payload"))
|
||||
(unless (or (getf payload :action) (getf payload :sensor))
|
||||
(error "Harness Protocol Schema Error: EVENT payload must contain :action or :sensor"))))
|
||||
(error "Harness Communication Schema Error: EVENT payload must contain :action or :sensor"))))
|
||||
|
||||
(:RESPONSE
|
||||
(unless (getf msg :payload)
|
||||
(error "Harness Protocol Schema Error: RESPONSE missing mandatory :payload"))))
|
||||
(error "Harness Communication Schema Error: RESPONSE missing mandatory :payload"))))
|
||||
|
||||
t))
|
||||
|
||||
(defskill :skill-harness-protocol-validator
|
||||
:priority 95
|
||||
:trigger (lambda (ctx) (member (getf (getf ctx :payload) :sensor) '(:protocol-received)))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(declare (ignore ctx))
|
||||
(validate-harness-protocol-schema action)
|
||||
action))
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
(tool-belt (generate-tool-belt-prompt))
|
||||
(global-context (context-assemble-global-awareness)))
|
||||
(if active-skill
|
||||
(let* ((prompt-generator (skill-neuro-prompt active-skill))
|
||||
(let* ((prompt-generator (skill-probabilistic-prompt active-skill))
|
||||
(raw-prompt (when prompt-generator (funcall prompt-generator context)))
|
||||
(system-prompt (concatenate 'string "IDENTITY: Actuator for org-agent. MANDATE: ONE Lisp plist. " global-context " " tool-belt)))
|
||||
(if (and raw-prompt (> (length raw-prompt) 1))
|
||||
@@ -45,13 +45,13 @@
|
||||
;; --- 2. Deterministic Mechanisms ---
|
||||
|
||||
(defun deterministic-verify (proposed-action context)
|
||||
"Iterates through all skill symbolic-gates sorted by priority."
|
||||
"Iterates through all skill deterministic-gates sorted by priority."
|
||||
(let ((current-action proposed-action)
|
||||
(skills nil))
|
||||
(maphash (lambda (name skill) (declare (ignore name)) (when (skill-symbolic-fn skill) (push skill skills))) *skills-registry*)
|
||||
(maphash (lambda (name skill) (declare (ignore name)) (when (skill-deterministic-fn skill) (push skill skills))) *skills-registry*)
|
||||
(setf skills (sort skills #'> :key #'skill-priority))
|
||||
(dolist (skill skills)
|
||||
(let ((gate (skill-symbolic-fn skill)))
|
||||
(let ((gate (skill-deterministic-fn skill)))
|
||||
(setf current-action (funcall gate current-action context))
|
||||
(when (and (listp current-action) (member (getf current-action :type) '(:LOG :EVENT)))
|
||||
(harness-log "DETERMINISTIC: Intercepted by skill '~a'" (skill-name skill))
|
||||
|
||||
@@ -83,5 +83,5 @@
|
||||
(defskill :skill-shell-actuator
|
||||
:priority 80
|
||||
:trigger #'trigger-skill-shell-actuator
|
||||
:neuro #'neuro-skill-shell-actuator
|
||||
:symbolic (lambda (action context) (declare (ignore context)) action))
|
||||
:probabilistic #'probabilistic-skill-shell-actuator
|
||||
:deterministic (lambda (action context) (declare (ignore context)) action))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(in-package :org-agent)
|
||||
|
||||
(defstruct skill name priority dependencies trigger-fn neuro-prompt symbolic-fn)
|
||||
(defstruct skill name priority dependencies trigger-fn probabilistic-prompt deterministic-fn)
|
||||
|
||||
(defvar *skill-catalog* (make-hash-table :test 'equal)
|
||||
"A stateful tracking table for all skill files discovered in the environment.")
|
||||
@@ -21,15 +21,15 @@
|
||||
*skills-registry*)
|
||||
(first (sort triggered #'> :key #'skill-priority))))
|
||||
|
||||
(defmacro defskill (name &key priority dependencies trigger neuro symbolic)
|
||||
(defmacro defskill (name &key priority dependencies trigger probabilistic deterministic)
|
||||
"Registers a new skill into the global registry."
|
||||
`(setf (gethash (string-downcase (string ,name)) *skills-registry*)
|
||||
(make-skill :name (string-downcase (string ,name))
|
||||
:priority (or ,priority 10)
|
||||
:dependencies ',dependencies
|
||||
:trigger-fn ,trigger
|
||||
:neuro-prompt ,neuro
|
||||
:symbolic-fn ,symbolic)))
|
||||
:probabilistic-prompt ,probabilistic
|
||||
:deterministic-fn ,deterministic)))
|
||||
|
||||
(defun resolve-skill-dependencies (skill-name)
|
||||
"Recursively resolves dependencies for a given skill name."
|
||||
@@ -46,27 +46,26 @@
|
||||
(nreverse resolved))))
|
||||
|
||||
(defun parse-skill-metadata (filepath)
|
||||
"Extracts ID and DEPENDS_ON tags using robust line-scanning."
|
||||
"Extracts ID and DEPENDS_ON tags using robust regex scanning."
|
||||
(let ((dependencies nil)
|
||||
(id nil))
|
||||
(with-open-file (stream filepath)
|
||||
(loop for line = (read-line stream nil :eof)
|
||||
until (eq line :eof)
|
||||
do (let ((clean (string-trim '(#\Space #\Tab #\Return #\Newline) line)))
|
||||
(cond
|
||||
((uiop:string-prefix-p "#+DEPENDS_ON:" (string-upcase clean))
|
||||
(let* ((deps-part (string-trim " " (subseq clean 13))))
|
||||
(setf dependencies (append dependencies
|
||||
(mapcar (lambda (s) (string-trim "[] " s))
|
||||
(uiop:split-string deps-part :separator '(#\Space #\Tab)))))))
|
||||
((uiop:string-prefix-p ":ID:" (string-upcase clean))
|
||||
(setf id (string-trim '(#\Space #\Tab) (subseq clean 4))))))))
|
||||
(id nil)
|
||||
(content (uiop:read-file-string filepath)))
|
||||
;; Extract ID
|
||||
(multiple-value-bind (match regs)
|
||||
(ppcre:scan-to-strings "(?im:^:ID:\\s*([^\\s\\r\\n]+))" content)
|
||||
(when match (setf id (aref regs 0))))
|
||||
;; Extract all DEPENDS_ON lines
|
||||
(ppcre:do-register-groups (deps-string)
|
||||
("(?im:^#\\+DEPENDS_ON:\\s*(.*))" content)
|
||||
(let ((deps (ppcre:split "\\s+" (string-trim " " deps-string))))
|
||||
(setf dependencies (append dependencies (mapcar (lambda (s) (string-trim "[] " s)) deps)))))
|
||||
(values id (remove-if (lambda (s) (= 0 (length s))) dependencies))))
|
||||
|
||||
(defun topological-sort-skills (skills-dir)
|
||||
"Returns a list of skill filepaths sorted by dependency (dependencies first)."
|
||||
(let ((files (uiop:directory-files skills-dir "org-skill-*.org"))
|
||||
(adj (make-hash-table :test 'equal))
|
||||
(name-to-file (make-hash-table :test 'equal))
|
||||
(id-to-file (make-hash-table :test 'equal))
|
||||
(result nil)
|
||||
(visited (make-hash-table :test 'equal))
|
||||
@@ -74,7 +73,7 @@
|
||||
(dolist (file files)
|
||||
(let ((filename (pathname-name file)))
|
||||
(multiple-value-bind (id deps) (parse-skill-metadata file)
|
||||
(setf (gethash (string-downcase filename) id-to-file) file)
|
||||
(setf (gethash (string-downcase filename) name-to-file) file)
|
||||
(when id (setf (gethash (string-downcase id) id-to-file) file))
|
||||
(setf (gethash (string-downcase filename) adj) deps))))
|
||||
(labels ((visit (file)
|
||||
@@ -83,10 +82,12 @@
|
||||
(unless (gethash node-key visited)
|
||||
(setf (gethash node-key stack) t)
|
||||
(dolist (dep (gethash node-key adj))
|
||||
(let* ((dep-id (if (and (> (length dep) 3) (uiop:string-prefix-p "id:" (string-downcase dep)))
|
||||
(subseq dep 3)
|
||||
dep))
|
||||
(dep-file (gethash (string-downcase dep-id) id-to-file)))
|
||||
(let* ((is-id-p (uiop:string-prefix-p "id:" (string-downcase dep)))
|
||||
(dep-key (string-downcase (if is-id-p (subseq dep 3) dep)))
|
||||
(dep-file (if is-id-p
|
||||
(gethash dep-key id-to-file)
|
||||
(or (gethash dep-key id-to-file)
|
||||
(gethash dep-key name-to-file)))))
|
||||
(when dep-file
|
||||
(let ((dep-filename (pathname-name dep-file)))
|
||||
(if (gethash (string-downcase dep-filename) stack)
|
||||
@@ -97,9 +98,9 @@
|
||||
(push file result)))))
|
||||
(let ((filenames (sort (mapcar #'pathname-name files) #'string<)))
|
||||
(dolist (name filenames)
|
||||
(let ((file (gethash (string-downcase name) id-to-file)))
|
||||
(let ((file (gethash (string-downcase name) name-to-file)))
|
||||
(when file (visit file)))))
|
||||
result)))
|
||||
(nreverse result))))
|
||||
|
||||
(defun validate-lisp-syntax (code-string)
|
||||
"Checks if a string contains valid, readable Common Lisp forms."
|
||||
@@ -197,8 +198,8 @@
|
||||
|
||||
(let ((sorted-files (topological-sort-skills skills-dir)))
|
||||
;; MANDATE: The System Policy must be present for a safe boot
|
||||
(unless (member "org-skill-system-invariants" sorted-files :key #'pathname-name :test #'string-equal)
|
||||
(error "BOOT FAILURE: org-skill-system-invariants.org not found in skills directory."))
|
||||
(unless (member "org-skill-policy" sorted-files :key #'pathname-name :test #'string-equal)
|
||||
(error "BOOT FAILURE: org-skill-policy.org not found in skills directory."))
|
||||
|
||||
(harness-log "==================================================")
|
||||
(harness-log " LOADER: Initializing ~a skills..." (length sorted-files))
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
:trigger (lambda (ctx)
|
||||
(let ((sensor (getf (getf ctx :payload) :sensor)))
|
||||
(member sensor '(:heartbeat :manual-persist))))
|
||||
:neuro nil
|
||||
:symbolic (lambda (action ctx)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action ctx)
|
||||
(persistence-dump-local)
|
||||
action))
|
||||
|
||||
13
src/system-invariants.lisp
Normal file
13
src/system-invariants.lisp
Normal file
@@ -0,0 +1,13 @@
|
||||
(in-package :org-agent)
|
||||
|
||||
(defun policy-check-sovereignty (action context)
|
||||
"Ensures the action does not violate the Sovereignty invariant."
|
||||
(declare (ignore context))
|
||||
;; Implementation placeholder
|
||||
action)
|
||||
|
||||
(defskill :skill-policy
|
||||
:priority 100
|
||||
:trigger (lambda (ctx) t)
|
||||
:probabilistic nil
|
||||
:deterministic #'policy-check-sovereignty)
|
||||
@@ -43,7 +43,7 @@
|
||||
t)))
|
||||
|
||||
(defun verify-action-formally (action context)
|
||||
"Symbolically proves that ACTION satisfies all applicable security invariants."
|
||||
"Deterministically proves that ACTION satisfies all applicable security invariants."
|
||||
(let ((action-target (getf action :target))
|
||||
(action-type (getf action :type))
|
||||
(all-passed t))
|
||||
@@ -64,8 +64,8 @@
|
||||
(defskill :skill-formal-verification
|
||||
:priority 95 ; Just below Bouncer
|
||||
:trigger (lambda (context) (declare (ignore context)) nil) ; Middleware only
|
||||
:neuro nil
|
||||
:symbolic (lambda (action context)
|
||||
:probabilistic nil
|
||||
:deterministic (lambda (action context)
|
||||
(if (verify-action-formally action context)
|
||||
action
|
||||
(let ((err (format nil "Formal verification failed for action: ~s" action)))
|
||||
|
||||
Reference in New Issue
Block a user