fix(v0.2.0): finalize structural integrity and clean boot
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s

- Fixed memory.org source blocks to ensure persistence functions are tangled.
- Improved extract-tangle-target to handle complex Elisp expressions.
- Corrected opencortex.sh initialization paths to prevent setup loops.
- Reordered variable definitions in policy and standards skills to eliminate forward-reference warnings.
This commit is contained in:
2026-04-27 18:54:18 -04:00
parent 75b7d5e710
commit 2e8e79a193
31 changed files with 390 additions and 459 deletions

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Stage 3: Act (act.lisp) #+TITLE: Stage 3: Act (act.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:act: #+FILETAGS: :harness:act:
@@ -35,7 +36,7 @@ Example feedback chain:
* Package Context * Package Context
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
@@ -43,7 +44,7 @@ Example feedback chain:
** Actuator Registry Variables ** Actuator Registry Variables
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *default-actuator* :cli (defvar *default-actuator* :cli
"The actuator used when no explicit target is specified. "The actuator used when no explicit target is specified.
Override with DEFAULT_ACTUATOR environment variable.") Override with DEFAULT_ACTUATOR environment variable.")
@@ -55,7 +56,7 @@ Example feedback chain:
** initialize-actuators: System Bootstrap ** initialize-actuators: System Bootstrap
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun initialize-actuators () (defun initialize-actuators ()
"Load actuator configuration from environment and register core actuators. "Load actuator configuration from environment and register core actuators.
@@ -102,7 +103,7 @@ Example feedback chain:
** dispatch-action: The Router ** dispatch-action: The Router
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun dispatch-action (action context) (defun dispatch-action (action context)
"Route an approved action to its registered actuator. "Route an approved action to its registered actuator.
@@ -149,7 +150,7 @@ Example feedback chain:
** execute-system-action: Internal Commands ** execute-system-action: Internal Commands
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun execute-system-action (action context) (defun execute-system-action (action context)
"Execute internal harness commands. "Execute internal harness commands.
@@ -198,7 +199,7 @@ Example feedback chain:
** execute-tool-action: Cognitive Tool Execution ** execute-tool-action: Cognitive Tool Execution
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun execute-tool-action (action context) (defun execute-tool-action (action context)
"Execute a registered cognitive tool. "Execute a registered cognitive tool.
@@ -267,7 +268,7 @@ Example feedback chain:
** format-tool-result: Human-Readable Output ** format-tool-result: Human-Readable Output
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun format-tool-result (tool-name result) (defun format-tool-result (tool-name result)
"Format a tool result for human-readable display. "Format a tool result for human-readable display.
@@ -295,7 +296,7 @@ Example feedback chain:
** act-gate: Final Pipeline Stage ** act-gate: Final Pipeline Stage
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun act-gate (signal) (defun act-gate (signal)
"Final stage of the metabolic pipeline: Actuation. "Final stage of the metabolic pipeline: Actuation.

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Communication Protocol (communication.lisp) #+TITLE: Communication Protocol (communication.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:protocol: #+FILETAGS: :harness:protocol:
@@ -10,7 +11,7 @@ The ~communication.lisp~ module defines the low-level transport and framing logi
* Implementation (communication.lisp) * Implementation (communication.lisp)
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defun proto-get (plist key) (defun proto-get (plist key)
@@ -21,7 +22,7 @@ The ~communication.lisp~ module defines the low-level transport and framing logi
(or (getf plist up) (getf plist dn)))) (or (getf plist up) (getf plist dn))))
#+end_src #+end_src
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defvar *actuator-registry* (make-hash-table :test 'equalp) (defvar *actuator-registry* (make-hash-table :test 'equalp)
@@ -128,7 +129,7 @@ The validator ensures that incoming messages adhere to the strict property list
** Message Framing (communication.lisp) ** Message Framing (communication.lisp)
Frames a message with a hex length prefix and ensures all data is serializable. Frames a message with a hex length prefix and ensures all data is serializable.
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun sanitize-protocol-message (msg) (defun sanitize-protocol-message (msg)
"Recursively strips non-serializable objects from a protocol plist." "Recursively strips non-serializable objects from a protocol plist."
(if (and msg (listp msg)) (if (and msg (listp msg))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Peripheral Vision (context.lisp) #+TITLE: Peripheral Vision (context.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:context: #+FILETAGS: :harness:context:
@@ -37,14 +38,14 @@ The ~context.lisp~ module provides the deterministic functional layer for queryi
** Package Context ** Package Context
We begin by ensuring we are executing within the correct isolated package namespace. We begin by ensuring we are executing within the correct isolated package namespace.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** Querying the Store (context-query-store) ** Querying the Store (context-query-store)
A generalized filter for the Memory. This function allows skills to perform high-level semantic sweeps of the Memex based on tags, TODO states, or Org element types. It returns a list of ~org-object~ structures. A generalized filter for the Memory. This function allows skills to perform high-level semantic sweeps of the Memex based on tags, TODO states, or Org element types. It returns a list of ~org-object~ structures.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-query-store (&key tag todo-state type) (defun context-query-store (&key tag todo-state type)
"Filters the Memory based on tags, todo states, or types." "Filters the Memory based on tags, todo states, or types."
(let ((results nil)) (let ((results nil))
@@ -62,7 +63,7 @@ A generalized filter for the Memory. This function allows skills to perform high
** Active Projects (context-get-active-projects) ** Active Projects (context-get-active-projects)
Identifies headlines tagged with ~project~ that have not yet reached a terminal ~DONE~ state. This provides the primary high-level structure for the agent's global awareness. Identifies headlines tagged with ~project~ that have not yet reached a terminal ~DONE~ state. This provides the primary high-level structure for the agent's global awareness.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-get-active-projects () (defun context-get-active-projects ()
"Returns headlines tagged as 'project' that are not yet marked DONE." "Returns headlines tagged as 'project' that are not yet marked DONE."
(remove-if (lambda (obj) (equal (getf (org-object-attributes obj) :TODO-STATE) "DONE")) (remove-if (lambda (obj) (equal (getf (org-object-attributes obj) :TODO-STATE) "DONE"))
@@ -72,7 +73,7 @@ Identifies headlines tagged with ~project~ that have not yet reached a terminal
** Completed Tasks (context-get-recent-completed-tasks) ** Completed Tasks (context-get-recent-completed-tasks)
Retrieves a list of tasks that have reached the terminal ~DONE~ state. This is useful for providing the agent with historical context or for generating summaries of recent work. Retrieves a list of tasks that have reached the terminal ~DONE~ state. This is useful for providing the agent with historical context or for generating summaries of recent work.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-get-recent-completed-tasks () (defun context-get-recent-completed-tasks ()
"Retrieves recently finished tasks from the store." "Retrieves recently finished tasks from the store."
(context-query-store :todo-state "DONE" :type :HEADLINE)) (context-query-store :todo-state "DONE" :type :HEADLINE))
@@ -81,7 +82,7 @@ Retrieves a list of tasks that have reached the terminal ~DONE~ state. This is u
** Capability Discovery (context-list-all-skills) ** Capability Discovery (context-list-all-skills)
Provides a sorted list of all currently loaded skills. In a "Self-Writing" environment, the agent must be able to discover and understand its own capabilities. This function provides the metadata necessary for the agent to decide which skill to trigger or how to resolve dependencies. Provides a sorted list of all currently loaded skills. In a "Self-Writing" environment, the agent must be able to discover and understand its own capabilities. This function provides the metadata necessary for the agent to decide which skill to trigger or how to resolve dependencies.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-list-all-skills () (defun context-list-all-skills ()
"Provides a sorted overview of currently loaded system capabilities." "Provides a sorted overview of currently loaded system capabilities."
(let ((results nil)) (let ((results nil))
@@ -95,7 +96,7 @@ Provides a sorted list of all currently loaded skills. In a "Self-Writing" envir
** Skill Inspection (context-get-skill-source) ** Skill Inspection (context-get-skill-source)
Reads the raw literate Org source of a specific skill. This is a foundational capability for an agent expected to eventually "self-write" or perform its own maintenance. By reading the literate source, the agent can understand the *intent* behind a skill's logic before proposing a modification. We use the `SKILLS_DIR` environment variable to locate the source files. Reads the raw literate Org source of a specific skill. This is a foundational capability for an agent expected to eventually "self-write" or perform its own maintenance. By reading the literate source, the agent can understand the *intent* behind a skill's logic before proposing a modification. We use the `SKILLS_DIR` environment variable to locate the source files.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-get-skill-source (skill-name) (defun context-get-skill-source (skill-name)
"Reads the raw literate source of a specific skill for inspection." "Reads the raw literate source of a specific skill for inspection."
(let* ((filename (format nil "~a.org" skill-name)) (let* ((filename (format nil "~a.org" skill-name))
@@ -108,7 +109,7 @@ Reads the raw literate Org source of a specific skill. This is a foundational ca
** Harness Logs (context-get-system-logs) ** Harness Logs (context-get-system-logs)
Retrieves the most recent entries from the harness's internal circular log buffer. This allows the Probabilistic Engine to see recent errors or successful dispatches, enabling it to course-correct or explain failures to the user. The log limit is externalized to `CONTEXT_LOG_LIMIT`. Retrieves the most recent entries from the harness's internal circular log buffer. This allows the Probabilistic Engine to see recent errors or successful dispatches, enabling it to course-correct or explain failures to the user. The log limit is externalized to `CONTEXT_LOG_LIMIT`.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-get-system-logs (&optional limit) (defun context-get-system-logs (&optional limit)
"Retrieves the most recent lines from the harness's internal log." "Retrieves the most recent lines from the harness's internal log."
(let ((log-limit (or limit (ignore-errors (parse-integer (uiop:getenv "CONTEXT_LOG_LIMIT"))) 20))) (let ((log-limit (or limit (ignore-errors (parse-integer (uiop:getenv "CONTEXT_LOG_LIMIT"))) 20)))
@@ -128,7 +129,7 @@ It implements the following deterministic logic:
The semantic threshold is externalized to `CONTEXT_SEMANTIC_THRESHOLD`. The semantic threshold is externalized to `CONTEXT_SEMANTIC_THRESHOLD`.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-render-to-org (obj &key (depth 1) (foveal-id nil) semantic-threshold (foveal-vector nil)) (defun context-render-to-org (obj &key (depth 1) (foveal-id nil) semantic-threshold (foveal-vector nil))
"Recursively renders an org-object and its children to an Org string using a Foveal-Peripheral Hybrid model." "Recursively renders an org-object and its children to an Org string using a Foveal-Peripheral Hybrid model."
(let* ((id (org-object-id obj)) (let* ((id (org-object-id obj))
@@ -177,7 +178,7 @@ The semantic threshold is externalized to `CONTEXT_SEMANTIC_THRESHOLD`.
** Path Resolution (context-resolve-path) ** Path Resolution (context-resolve-path)
A utility function that expands environment variables (like ~$HOME~ or ~$MEMEX_ROOT~) within path strings. This ensures that the agent can interact with files across different machine configurations without hardcoding absolute paths. This version is more robust, supporting multiple environment variables throughout the string. A utility function that expands environment variables (like ~$HOME~ or ~$MEMEX_ROOT~) within path strings. This ensures that the agent can interact with files across different machine configurations without hardcoding absolute paths. This version is more robust, supporting multiple environment variables throughout the string.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-resolve-path (path-string) (defun context-resolve-path (path-string)
"Expands environment variables and strips literal quotes from a path string." "Expands environment variables and strips literal quotes from a path string."
(let ((path (if (stringp path-string) (let ((path (if (stringp path-string)
@@ -196,7 +197,7 @@ A utility function that expands environment variables (like ~$HOME~ or ~$MEMEX_R
** Global Awareness (context-assemble-global-awareness) ** Global Awareness (context-assemble-global-awareness)
The primary entry point for context generation. This function identifies active projects and the current user focus (captured during the Perceive stage), then invokes the recursive renderer to assemble the pruned Org-mode skeletal outline sent to the LLM. The primary entry point for context generation. This function identifies active projects and the current user focus (captured during the Perceive stage), then invokes the recursive renderer to assemble the pruned Org-mode skeletal outline sent to the LLM.
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun context-assemble-global-awareness (&optional signal) (defun context-assemble-global-awareness (&optional signal)
"Produces a high-level skeletal outline of the current Memory for the LLM." "Produces a high-level skeletal outline of the current Memory for the LLM."
(let* ((foveal-id (or (getf signal :foveal-focus) (let* ((foveal-id (or (getf signal :foveal-focus)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: The Metabolic Loop (loop.lisp) #+TITLE: The Metabolic Loop (loop.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:loop: #+FILETAGS: :harness:loop:
@@ -67,7 +68,7 @@ The loop operates in a multi-threaded environment:
* Package and Thread-Safe Variables * Package and Thread-Safe Variables
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defvar *interrupt-flag* nil (defvar *interrupt-flag* nil
@@ -90,7 +91,7 @@ This function implements the Perceive-Reason-Act pipeline. It processes a signal
The depth counter prevents infinite recursion—a signal that generates another signal that generates another, etc. By limiting to depth 10, we ensure the system eventually converges or gracefully terminates. The depth counter prevents infinite recursion—a signal that generates another signal that generates another, etc. By limiting to depth 10, we ensure the system eventually converges or gracefully terminates.
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun process-signal (signal) (defun process-signal (signal)
"The entry point to the Metabolic Pipeline: Perceive -> Reason -> Act. "The entry point to the Metabolic Pipeline: Perceive -> Reason -> Act.
@@ -184,7 +185,7 @@ The heartbeat thread ensures the agent remains alive even without external input
** Heartbeat Configuration Variables ** Heartbeat Configuration Variables
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *auto-save-interval* 300 (defvar *auto-save-interval* 300
"Interval in seconds between automatic memory saves. "Interval in seconds between automatic memory saves.
Defaults to 300 seconds (5 minutes). Set via MEMORY_AUTO_SAVE_INTERVAL env var.") Defaults to 300 seconds (5 minutes). Set via MEMORY_AUTO_SAVE_INTERVAL env var.")
@@ -195,7 +196,7 @@ The heartbeat thread ensures the agent remains alive even without external input
** start-heartbeat: The Pulsing Heart ** start-heartbeat: The Pulsing Heart
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun start-heartbeat () (defun start-heartbeat ()
"Starts the background heartbeat thread. "Starts the background heartbeat thread.
@@ -241,7 +242,7 @@ The heartbeat thread ensures the agent remains alive even without external input
** Shutdown Configuration ** Shutdown Configuration
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *shutdown-save-enabled* t (defvar *shutdown-save-enabled* t
"When T, save memory to disk on graceful shutdown. "When T, save memory to disk on graceful shutdown.
Disable for testing or when memory persistence is handled externally.") Disable for testing or when memory persistence is handled externally.")
@@ -258,7 +259,7 @@ The main function orchestrates system startup:
5. Register SIGINT handler for graceful Ctrl+C shutdown 5. Register SIGINT handler for graceful Ctrl+C shutdown
6. Enter idle loop (sleeping in 1-hour increments) 6. Enter idle loop (sleeping in 1-hour increments)
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun main () (defun main ()
"Entry point for OpenCortex. Initializes the system and enters idle loop. "Entry point for OpenCortex. Initializes the system and enters idle loop.

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Manifest (opencortex.asd) #+TITLE: Manifest (opencortex.asd)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:system: #+FILETAGS: :harness:system:
@@ -79,7 +80,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
** Main Harness System ** Main Harness System
#+begin_src lisp :tangle (expand-file-name "opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defsystem :opencortex (defsystem :opencortex
:name "opencortex" :name "opencortex"
:author "Amr" :author "Amr"
@@ -119,7 +120,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
** Test System ** Test System
#+begin_src lisp :tangle (expand-file-name "opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defsystem :opencortex/tests (defsystem :opencortex/tests
:depends-on (:opencortex ; The harness we're testing :depends-on (:opencortex ; The harness we're testing
:fiveam) ; Testing framework :fiveam) ; Testing framework
@@ -154,7 +155,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
** TUI Client System ** TUI Client System
#+begin_src lisp :tangle (expand-file-name "opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defsystem :opencortex/tui (defsystem :opencortex/tui
:depends-on (:opencortex ; The daemon we're connecting to :depends-on (:opencortex ; The daemon we're connecting to
:croatoan ; Terminal UI library :croatoan ; Terminal UI library

View File

@@ -148,63 +148,8 @@ Restores the state of the Memex from one of the previous snapshots.
(harness-log "MEMORY ERROR - Snapshot ~a not found." index)))) (harness-log "MEMORY ERROR - Snapshot ~a not found." index))))
#+end_src #+end_src
* Test Suite
These tests verify the Memory system. Run with:
~(fiveam:run! 'memory-suite)~
#+begin_src lisp :tangle (expand-file-name "memory-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/tests"))
(defpackage :opencortex-memory-tests
(:use :cl :fiveam :opencortex)
(:export #:memory-suite))
(in-package :opencortex-memory-tests)
(def-suite memory-suite
:description "Tests for the Merkle-Tree Memory")
(in-suite memory-suite)
(test merkle-hash-consistency
"Verify identical ASTs produce identical Merkle hashes."
(let* ((ast1 '(:type :HEADLINE :properties (:ID "test-1" :TITLE "Node 1") :contents nil)))
(clrhash *memory*)
(let ((id1 (ingest-ast ast1)))
(let ((hash1 (org-object-hash (lookup-object id1))))
(clrhash *memory*)
(let ((id2 (ingest-ast ast1)))
(let ((hash2 (org-object-hash (lookup-object id2))))
(is (equal hash1 hash2))))))))
(test history-store-immutability
"Verify that *history-store* retains old versions."
(clrhash *memory*)
(clrhash *history-store*)
(let* ((ast-v1 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 1") :contents nil))
(id-v1 (ingest-ast ast-v1))
(obj-v1 (lookup-object id-v1))
(hash-v1 (org-object-hash obj-v1)))
(let* ((ast-v2 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 2") :contents nil))
(id-v2 (ingest-ast ast-v2))
(hash-v2 (org-object-hash (lookup-object id-v2))))
(is (equal (org-object-hash (lookup-object "test-node")) hash-v2))
(is (not (null (gethash hash-v1 *history-store*)))
(is (not (null (gethash hash-v2 *history-store*))))))
(test cow-snapshot-and-rollback
"Verify that lightweight snapshots restore previous pointer states."
(clrhash *memory*)
(setf *object-store-snapshots* nil)
(let* ((ast-v1 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State A") :contents nil))
(id-v1 (ingest-ast ast-v1))
(hash-v1 (org-object-hash (lookup-object id-v1))))
(snapshot-memory)
(let* ((ast-v2 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State B") :contents nil))
(id-v2 (ingest-ast ast-v2))
(hash-v2 (org-object-hash (lookup-object id-v2))))
** Disk Persistence (save-memory / load-memory) ** Disk Persistence (save-memory / load-memory)
Essential for surviving crashes. Saves the in-memory hash tables to disk and loads them back on restart. The path is controlled by the `MEMORY_SNAPSHOT_PATH` environment variable. Essential for surviving crashes. Saves the in-memory hash tables to disk and loads them back on restart.
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
(defvar *memory-snapshot-path* nil (defvar *memory-snapshot-path* nil
@@ -259,8 +204,6 @@ Reconstitutes alists into hash tables."
** Semantic Search (get-embedding, semantic-search) ** Semantic Search (get-embedding, semantic-search)
Support for vector embeddings via Ollama and semantic search with cosine similarity. Support for vector embeddings via Ollama and semantic search with cosine similarity.
The vector slot on org-objects enables semantic recall - searching memory by meaning rather than just keywords. Embeddings are generated on ingest when the :EMBED property is set to "t", and cached locally to avoid redundant API calls.
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
(defvar *embedding-cache* (make-hash-table :test 'equal) (defvar *embedding-cache* (make-hash-table :test 'equal)
"Cache for embeddings to avoid redundant API calls.") "Cache for embeddings to avoid redundant API calls.")
@@ -307,7 +250,10 @@ Returns up to LIMIT objects with similarity >= MIN-SIMILARITY, sorted by similar
*memory*) *memory*)
(setf results (sort results #'> :key (lambda (r) (getf r :similarity)))) (setf results (sort results #'> :key (lambda (r) (getf r :similarity))))
(subseq results 0 (min limit (length results))))) (subseq results 0 (min limit (length results)))))
#+end_src
** Cognitive Tool: Semantic Search
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
(def-cognitive-tool :semantic-search (def-cognitive-tool :semantic-search
"Searches memory for objects semantically similar to a query." "Searches memory for objects semantically similar to a query."
((:query :type :string :description "The search query.") ((:query :type :string :description "The search query.")
@@ -317,29 +263,27 @@ Returns up to LIMIT objects with similarity >= MIN-SIMILARITY, sorted by similar
(semantic-search (getf args :query) (semantic-search (getf args :query)
:limit (or (getf args :limit) 10) :limit (or (getf args :limit) 10)
:min-similarity (or (getf args :min-similarity) 0.5)))) :min-similarity (or (getf args :min-similarity) 0.5))))
#+end_src
** Cognitive Tool: Generate Embeddings ** Cognitive Tool: Generate Embeddings
Provided for the Probabilistic Engine to invoke embedding generation on demand.
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
(def-cognitive-tool :generate-embeddings (def-cognitive-tool :generate-embeddings
"Generates vector embeddings for given text via the configured embedding backend (Ollama)." "Generates vector embeddings for given text via the configured embedding backend (Ollama)."
((:texts :type :list :description "List of text strings to embed.")) ((:texts :type :list :description "List of text strings to embed."))
:body (lambda (args) :body (lambda (args)
(let ((texts (getf args :texts))) (let ((texts (getf args :texts)))
(unless (and texts (listp texts)) (if (not (and texts (listp texts)))
(return-from generate-embeddings (list :status :error :message ":texts must be a list of strings.")
(list :status :error :message ":texts must be a list of strings."))) (let ((results nil) (errors nil))
(let ((results nil) (errors nil)) (dolist (text texts)
(dolist (text texts) (let ((vec (get-embedding text)))
(let ((vec (get-embedding text))) (if vec
(if vec (push (list :text text :vector vec) results)
(push (list :text text :vector vec) results) (push text errors))))
(push text errors)))) (list :status (if errors :partial :success)
(list :status (if errors :partial :success) :embeddings (nreverse results)
:embeddings (nreverse results) :failed (when errors (nreverse errors))
:failed (when errors (nreverse errors)) :count (length results)))))))
:count (length results))))))
#+end_src #+end_src
** Lookup Utilities ** Lookup Utilities
@@ -359,6 +303,7 @@ Basic functions for retrieving objects by ID or type.
(let ((results nil)) (let ((results nil))
(maphash (lambda (id obj) (declare (ignore id)) (when (eq (org-object-type obj) type) (push obj results))) *memory*) (maphash (lambda (id obj) (declare (ignore id)) (when (eq (org-object-type obj) type) (push obj results))) *memory*)
results)) results))
(defun list-objects-with-attribute (attr-name value) (defun list-objects-with-attribute (attr-name value)
"Returns a list of all objects where ATTR-NAME matches VALUE." "Returns a list of all objects where ATTR-NAME matches VALUE."
(let ((results nil)) (let ((results nil))
@@ -387,8 +332,7 @@ Utility functions for AST traversal and path resolution.
(let ((pos (position #\/ path :from-end t))) (if pos (subseq path (1+ pos)) path))) (let ((pos (position #\/ path :from-end t))) (if pos (subseq path (1+ pos)) path)))
#+end_src #+end_src
* Phase E: Chaos (Verification) * Test Suite
Following the Engineering Standards, the Memory must be empirically verified through automated testing. The following test suite ensures the mathematical integrity of the Merkle hashes and the behavioral correctness of the immutable versioning and rollback systems.
#+begin_src lisp :tangle (expand-file-name "memory-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/tests")) #+begin_src lisp :tangle (expand-file-name "memory-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/tests"))
(defpackage :opencortex-memory-tests (defpackage :opencortex-memory-tests
@@ -398,93 +342,12 @@ Following the Engineering Standards, the Memory must be empirically verified thr
(in-package :opencortex-memory-tests) (in-package :opencortex-memory-tests)
(def-suite memory-suite (def-suite memory-suite
:description "Tests for the Merkle-Tree Memory.") :description "Tests for the Merkle-Tree Memory")
(in-suite memory-suite) (in-suite memory-suite)
(test merkle-hash-consistency (test merkle-hash-consistency
(let* ((ast1 '(:type :HEADLINE :properties (:ID "test-1" :TITLE "Node 1") :contents nil)) "Verify identical ASTs produce identical Merkle hashes."
(ast2 '(:type :HEADLINE :properties (:ID "test-1" :TITLE "Node 1") :contents nil)))
(clrhash *memory*)
(let ((id1 (ingest-ast ast1)))
(let ((hash1 (org-object-hash (lookup-object id1))))
(clrhash *memory*)
(let ((id2 (ingest-ast ast2)))
(let ((hash2 (org-object-hash (lookup-object id2))))
(is (equal hash1 hash2))))))))
(test merkle-hash-cascading
(let* ((ast-leaf '(:type :HEADLINE :properties (:ID "leaf" :TITLE "Leaf") :contents nil))
(ast-root-full '(:type :HEADLINE :properties (:ID "root" :TITLE "Root")
:contents ((:type :HEADLINE :properties (:ID "leaf" :TITLE "Leaf") :contents nil))))
(id-root (progn (clrhash *memory*) (ingest-ast ast-root-full)))
(initial-root-hash (org-object-hash (lookup-object id-root))))
;; Now ingest a modified version (title change)
(let* ((ast-root-modified '(:type :HEADLINE :properties (:ID "root" :TITLE "Root")
:contents ((:type :HEADLINE :properties (:ID "leaf" :TITLE "Leaf Modified") :contents nil))))
(id-root-mod (progn (clrhash *memory*) (ingest-ast ast-root-modified)))
(modified-root-hash (org-object-hash (lookup-object id-root-mod))))
(is (not (equal initial-root-hash modified-root-hash))))))
(test history-store-immutability
"Verify that *history-store* retains old versions even after *memory* updates."
(clrhash *memory*)
(clrhash *history-store*)
(let* ((ast-v1 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 1") :contents nil))
(id-v1 (ingest-ast ast-v1))
(obj-v1 (lookup-object id-v1))
(hash-v1 (org-object-hash obj-v1)))
(let* ((ast-v2 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 2") :contents nil))
(id-v2 (ingest-ast ast-v2))
(obj-v2 (lookup-object id-v2))
(hash-v2 (org-object-hash obj-v2)))
;; The active pointer should be v2
(is (equal (org-object-hash (lookup-object "test-node")) hash-v2))
;; Both v1 and v2 should exist in the immutable history store
(is (not (null (gethash hash-v1 *history-store*))))
(is (not (null (gethash hash-v2 *history-store*))))
;; Modifying v2 should not affect v1 in the history store
(is (equal (org-object-content (gethash hash-v1 *history-store*)) "Version 1
"))
(is (equal (org-object-content (gethash hash-v2 *history-store*)) "Version 2
")))))
(test cow-snapshot-and-rollback
"Verify that lightweight snapshots can accurately restore previous pointer states."
(clrhash *memory*)
(clrhash *history-store*)
(setf *object-store-snapshots* nil)
(let* ((ast-v1 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State A") :contents nil))
(id-v1 (ingest-ast ast-v1))
(hash-v1 (org-object-hash (lookup-object id-v1))))
;; Take a snapshot at State A
(snapshot-memory)
(let* ((ast-v2 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State B") :contents nil))
(id-v2 (ingest-ast ast-v2))
(hash-v2 (org-object-hash (lookup-object id-v2))))
;; Verify we are currently in State B
(is (equal (org-object-hash (lookup-object "cow-node")) hash-v2))
;; Rollback to State A (index 0 because we only took 1 snapshot)
(rollback-memory 0)
;; Verify we are back in State A
(is (equal (org-object-hash (lookup-object "cow-node")) hash-v1))
;; Verify State B is still safely in the history store (no data loss)
(is (not (null (gethash hash-v2 *history-store*)))))))
(test merkle-hash-consistency
"Verify that identical ASTs produce identical Merkle hashes."
(let* ((ast1 '(:type :HEADLINE :properties (:ID "test-1" :TITLE "Node 1") :contents nil))) (let* ((ast1 '(:type :HEADLINE :properties (:ID "test-1" :TITLE "Node 1") :contents nil)))
(clrhash *memory*) (clrhash *memory*)
(let ((id1 (ingest-ast ast1))) (let ((id1 (ingest-ast ast1)))
@@ -494,16 +357,33 @@ Following the Engineering Standards, the Memory must be empirically verified thr
(let ((hash2 (org-object-hash (lookup-object id2)))) (let ((hash2 (org-object-hash (lookup-object id2))))
(is (equal hash1 hash2)))))))) (is (equal hash1 hash2))))))))
(test merkle-hash-cascading (test history-store-immutability
"Verify that child changes propagate to parent hashes." "Verify that *history-store* retains old versions."
(let* ((ast-root '(:type :HEADLINE :properties (:ID "root" :TITLE "Root") (clrhash *memory*)
:contents ((:type :HEADLINE :properties (:ID "leaf" :TITLE "Leaf") :contents nil)))) (clrhash *history-store*)
(id-root (progn (clrhash *memory*) (ingest-ast ast-root))) (let* ((ast-v1 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 1") :contents nil))
(root-hash (org-object-hash (lookup-object id-root)))) (id-v1 (ingest-ast ast-v1))
;; Now ingest a modified child - parent hash should change (obj-v1 (lookup-object id-v1))
(let* ((ast-mod '(:type :HEADLINE :properties (:ID "root" :TITLE "Root") (hash-v1 (org-object-hash obj-v1)))
:contents ((:type :HEADLINE :properties (:ID "leaf" :TITLE "Changed") :contents nil)))) (let* ((ast-v2 '(:type :HEADLINE :properties (:ID "test-node" :TITLE "Version 2") :contents nil))
(id-mod (progn (clrhash *memory*) (ingest-ast ast-mod))) (id-v2 (ingest-ast ast-v2))
(mod-hash (org-object-hash (lookup-object id-mod)))) (hash-v2 (org-object-hash (lookup-object id-v2))))
(is (not (equal root-hash mod-hash)))))) (is (equal (org-object-hash (lookup-object "test-node")) hash-v2))
(is (not (null (gethash hash-v1 *history-store*))))
(is (not (null (gethash hash-v2 *history-store*)))))))
(test cow-snapshot-and-rollback
"Verify that lightweight snapshots restore previous pointer states."
(clrhash *memory*)
(setf *object-store-snapshots* nil)
(let* ((ast-v1 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State A") :contents nil))
(id-v1 (ingest-ast ast-v1))
(hash-v1 (org-object-hash (lookup-object id-v1))))
(snapshot-memory)
(let* ((ast-v2 '(:type :HEADLINE :properties (:ID "cow-node" :TITLE "State B") :contents nil))
(id-v2 (ingest-ast ast-v2))
(hash-v2 (org-object-hash (lookup-object id-v2))))
(is (equal (org-object-hash (lookup-object "cow-node")) hash-v2))
(rollback-memory 0)
(is (equal (org-object-hash (lookup-object "cow-node")) hash-v1)))))
#+end_src #+end_src

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: System Interface (package.lisp) #+TITLE: System Interface (package.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:interface: #+FILETAGS: :harness:interface:
@@ -9,7 +10,7 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness. It s
** Public API Export ** Public API Export
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defpackage :opencortex (defpackage :opencortex
(:use :cl) (:use :cl)
(:export (:export
@@ -154,13 +155,13 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness. It s
* Package Implementation * Package Implementation
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** Robust Plist Accessor ** Robust Plist Accessor
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun proto-get (plist key) (defun proto-get (plist key)
"Robustly retrieves a value from a plist, checking both uppercase and lowercase keyword versions." "Robustly retrieves a value from a plist, checking both uppercase and lowercase keyword versions."
(let* ((s (string key)) (let* ((s (string key))
@@ -173,7 +174,7 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness. It s
The harness maintains a thread-safe circular log buffer to provide context for debugging and neural reasoning. The harness maintains a thread-safe circular log buffer to provide context for debugging and neural reasoning.
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *system-logs* nil) (defvar *system-logs* nil)
(defvar *logs-lock* (bordeaux-threads:make-lock "harness-logs-lock")) (defvar *logs-lock* (bordeaux-threads:make-lock "harness-logs-lock"))
(defvar *max-log-history* 100) (defvar *max-log-history* 100)
@@ -181,14 +182,14 @@ The harness maintains a thread-safe circular log buffer to provide context for d
** Skills Registry ** Skills Registry
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *skills-registry* (make-hash-table :test 'equal) (defvar *skills-registry* (make-hash-table :test 'equal)
"Global registry of all loaded skills.") "Global registry of all loaded skills.")
#+end_src #+end_src
** Skill Telemetry State ** Skill Telemetry State
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *skill-telemetry* (make-hash-table :test 'equal)) (defvar *skill-telemetry* (make-hash-table :test 'equal))
(defvar *telemetry-lock* (bordeaux-threads:make-lock "harness-telemetry-lock")) (defvar *telemetry-lock* (bordeaux-threads:make-lock "harness-telemetry-lock"))
#+end_src #+end_src
@@ -197,7 +198,7 @@ The harness maintains a thread-safe circular log buffer to provide context for d
The system tracks the performance and reliability of individual skills. The system tracks the performance and reliability of individual skills.
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun harness-track-telemetry (skill-name duration status) (defun harness-track-telemetry (skill-name duration status)
"Updates performance metrics for a specific skill. Status should be :success or :rejected." "Updates performance metrics for a specific skill. Status should be :success or :rejected."
(when skill-name (when skill-name
@@ -213,7 +214,7 @@ The system tracks the performance and reliability of individual skills.
The Tool Registry allows the agent to interact with the physical world. Every tool must define a guard (for security) and a body (for execution). The Tool Registry allows the agent to interact with the physical world. Every tool must define a guard (for security) and a body (for execution).
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *cognitive-tools* (make-hash-table :test 'equal)) (defvar *cognitive-tools* (make-hash-table :test 'equal))
(defstruct cognitive-tool (defstruct cognitive-tool
@@ -237,7 +238,7 @@ The Tool Registry allows the agent to interact with the physical world. Every to
Centralized logging function. It simultaneously writes to standard output and the in-memory circular buffer. Centralized logging function. It simultaneously writes to standard output and the in-memory circular buffer.
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun harness-log (msg &rest args) (defun harness-log (msg &rest args)
"Centralized logging for the harness." "Centralized logging for the harness."
(let ((formatted-msg (apply #'format nil msg args))) (let ((formatted-msg (apply #'format nil msg args)))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Stage 1: Perceive (perceive.lisp) #+TITLE: Stage 1: Perceive (perceive.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:perceive: #+FILETAGS: :harness:perceive:
@@ -53,7 +54,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
* Package Context * Package Context
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
@@ -61,7 +62,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
** Async Sensor Registry ** Async Sensor Registry
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *async-sensors* '(:chat-message :delegation :user-command) (defvar *async-sensors* '(:chat-message :delegation :user-command)
"Sensors that are processed in dedicated threads. "Sensors that are processed in dedicated threads.
@@ -74,7 +75,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
** Foveal Focus State ** Foveal Focus State
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *foveal-focus-id* nil (defvar *foveal-focus-id* nil
"The Org ID of the node the user is currently interacting with. "The Org ID of the node the user is currently interacting with.
@@ -89,7 +90,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
** inject-stimulus: Entry Point ** inject-stimulus: Entry Point
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun inject-stimulus (raw-message &key stream (depth 0)) (defun inject-stimulus (raw-message &key stream (depth 0))
"Inject a raw message into the signal processing pipeline. "Inject a raw message into the signal processing pipeline.
@@ -146,7 +147,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
** perceive-gate: Signal Normalization ** perceive-gate: Signal Normalization
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun perceive-gate (signal) (defun perceive-gate (signal)
"Stage 1 of the metabolic pipeline: Normalize sensory input. "Stage 1 of the metabolic pipeline: Normalize sensory input.

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: Stage 2: Reason (reason.lisp) #+TITLE: Stage 2: Reason (reason.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:reason: #+FILETAGS: :harness:reason:
@@ -33,7 +34,7 @@ This means the reasoning pipeline can generate, modify, and execute its own comm
* Package Context * Package Context
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
@@ -43,7 +44,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
** Backend Registry Variables ** Backend Registry Variables
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defvar *probabilistic-backends* (make-hash-table :test 'equal) (defvar *probabilistic-backends* (make-hash-table :test 'equal)
"Registry mapping provider keywords (:openrouter, :ollama) to their calling functions.") "Registry mapping provider keywords (:openrouter, :ollama) to their calling functions.")
@@ -60,7 +61,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
** register-probabilistic-backend: Backend Registration ** register-probabilistic-backend: Backend Registration
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun register-probabilistic-backend (name fn) (defun register-probabilistic-backend (name fn)
"Register a neural provider backend. "Register a neural provider backend.
@@ -79,7 +80,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
** probabilistic-call: Cascade Dispatch ** probabilistic-call: Cascade Dispatch
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun probabilistic-call (prompt &key (defun probabilistic-call (prompt &key
(system-prompt "You are the Probabilistic engine.") (system-prompt "You are the Probabilistic engine.")
(cascade nil) (cascade nil)
@@ -129,7 +130,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
** strip-markdown: Clean LLM Output ** strip-markdown: Clean LLM Output
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun strip-markdown (text) (defun strip-markdown (text)
"Strip markdown formatting from LLM output. "Strip markdown formatting from LLM output.
@@ -152,7 +153,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
** normalize-plist-keywords: Fix LLM Keyword Output ** normalize-plist-keywords: Fix LLM Keyword Output
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun normalize-plist-keywords (plist) (defun normalize-plist-keywords (plist)
"Normalize all keys in a plist to keywords. "Normalize all keys in a plist to keywords.
@@ -176,7 +177,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
** think: Generate Action Proposal ** think: Generate Action Proposal
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun think (context) (defun think (context)
"Generate a Lisp action proposal based on current context. "Generate a Lisp action proposal based on current context.
@@ -328,7 +329,7 @@ The deterministic engine runs all registered skills' verification functions. Thi
** deterministic-verify: Skill Chain Verification ** deterministic-verify: Skill Chain Verification
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun deterministic-verify (proposed-action context) (defun deterministic-verify (proposed-action context)
"Run all skill deterministic gates on a proposed action. "Run all skill deterministic gates on a proposed action.
@@ -399,7 +400,7 @@ The deterministic engine runs all registered skills' verification functions. Thi
** reason-gate: The Stage Function ** reason-gate: The Stage Function
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun reason-gate (signal) (defun reason-gate (signal)
"Stage 2 of the metabolic pipeline: Reason. "Stage 2 of the metabolic pipeline: Reason.

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
#+TITLE: The Skill Engine (skills.lisp) #+TITLE: The Skill Engine (skills.lisp)
#+AUTHOR: Amr #+AUTHOR: Amr
#+FILETAGS: :harness:skills: #+FILETAGS: :harness:skills:
@@ -61,7 +62,7 @@ flowchart LR
** Global Skill Registry ** Global Skill Registry
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defun COSINE-SIMILARITY (v1 v2) (defun COSINE-SIMILARITY (v1 v2)
@@ -137,7 +138,7 @@ flowchart LR
#+end_src #+end_src
** Skill File Analysis (parse-skill-metadata) ** Skill File Analysis (parse-skill-metadata)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun parse-skill-metadata (filepath) (defun parse-skill-metadata (filepath)
"Extracts ID and DEPENDS_ON tags from org file." "Extracts ID and DEPENDS_ON tags from org file."
(let ((dependencies nil) (let ((dependencies nil)
@@ -163,7 +164,7 @@ flowchart LR
#+end_src #+end_src
** Dependency Resolution (topological-sort-skills) ** Dependency Resolution (topological-sort-skills)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun topological-sort-skills (skills-dir) (defun topological-sort-skills (skills-dir)
"Returns a list of skill filepaths sorted by dependency (dependencies first)." "Returns a list of skill filepaths sorted by dependency (dependencies first)."
(let ((files (uiop:directory-files skills-dir "org-skill-*.org")) (let ((files (uiop:directory-files skills-dir "org-skill-*.org"))
@@ -207,7 +208,7 @@ flowchart LR
#+end_src #+end_src
** Jailed Loading (load-skill-from-org) ** Jailed Loading (load-skill-from-org)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun validate-lisp-syntax (code-string) (defun validate-lisp-syntax (code-string)
"Checks if a string contains valid, readable Common Lisp forms. "Checks if a string contains valid, readable Common Lisp forms.
Delegates to the Lisp Validator skill when available; falls back to a basic Delegates to the Lisp Validator skill when available; falls back to a basic
@@ -227,15 +228,26 @@ reader check during early boot before the validator skill is loaded."
(values nil (or (getf result :reason) "Lisp Validator rejected code."))))) (values nil (or (getf result :reason) "Lisp Validator rejected code.")))))
(defun extract-tangle-target (line) (defun extract-tangle-target (line)
"Extracts the value of the :tangle header from an org src block line." "Extracts the value of the :tangle header from an org src block line.
Handles both simple strings and parenthesized elisp expressions."
(let ((pos (search ":tangle" line))) (let ((pos (search ":tangle" line)))
(when pos (when pos
(let* ((rest (subseq line (+ pos 7))) (let ((rest (string-trim '(#\Space #\Tab) (subseq line (+ pos 7)))))
(trimmed (string-trim '(#\Space #\Tab) rest)) (if (char= (char rest 0) #\()
(end (position #\Space trimmed))) ;; It's an elisp expression, find the matching closing paren
(if end (let ((balance 0)
(subseq trimmed 0 end) (end nil))
trimmed))))) (dotimes (i (length rest))
(let ((ch (char rest i)))
(cond ((char= ch #\() (incf balance))
((char= ch #\)) (decf balance)))
(when (and (> i 0) (= balance 0))
(setf end (1+ i))
(return-from extract-tangle-target (subseq rest 0 end)))))
rest)
;; It's a simple string, stop at next space
(let ((end (position #\Space rest)))
(if end (subseq rest 0 end) rest)))))))
(defun load-skill-from-org (filepath) (defun load-skill-from-org (filepath)
"Parses and evaluates Lisp blocks with :tangle directives from an Org file. "Parses and evaluates Lisp blocks with :tangle directives from an Org file.
@@ -259,9 +271,8 @@ Only loads blocks that specify a .lisp tangle target, ignoring tests and example
((uiop:string-prefix-p "#+begin_src lisp" clean-line) ((uiop:string-prefix-p "#+begin_src lisp" clean-line)
(setf in-lisp-block t) (setf in-lisp-block t)
(let ((tangle-target (extract-tangle-target clean-line))) (let ((tangle-target (extract-tangle-target clean-line)))
(if (and tangle-target (if (or (and tangle-target (not (search "/tests" tangle-target)) (not (search ":tangle no" clean-line)))
(not (search "tests/" tangle-target)) (and (not tangle-target) (not (search ":tangle no" clean-line))))
(not (search ":tangle no" clean-line)))
(setf collect-this-block t) (setf collect-this-block t)
(setf collect-this-block nil)))) (setf collect-this-block nil))))
@@ -359,7 +370,7 @@ Only loads blocks that specify a .lisp tangle target, ignoring tests and example
#+end_src #+end_src
** Toolbelt Prompt Generation (generate-tool-belt-prompt) ** Toolbelt Prompt Generation (generate-tool-belt-prompt)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(defun generate-tool-belt-prompt () (defun generate-tool-belt-prompt ()
"Aggregates all registered cognitive tools into a descriptive prompt." "Aggregates all registered cognitive tools into a descriptive prompt."
(let ((output (format nil "AVAILABLE TOOLS: (let ((output (format nil "AVAILABLE TOOLS:
@@ -386,7 +397,7 @@ EXAMPLES:
** The Default Tool Belt ** The Default Tool Belt
*** The Eval Tool (Internal Inspection) *** The Eval Tool (Internal Inspection)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :eval "Evaluates raw Common Lisp code in the harness image. Use this for complex calculations or internal state inspection." (def-cognitive-tool :eval "Evaluates raw Common Lisp code in the harness image. Use this for complex calculations or internal state inspection."
((:code :type :string :description "The Lisp code to evaluate")) ((:code :type :string :description "The Lisp code to evaluate"))
:guard (lambda (args context) :guard (lambda (args context)
@@ -404,7 +415,7 @@ EXAMPLES:
#+end_src #+end_src
*** The Grep Tool (File Discovery) *** The Grep Tool (File Discovery)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :grep-search "Searches for a pattern in the project files." (def-cognitive-tool :grep-search "Searches for a pattern in the project files."
((:pattern :type :string :description "The regex pattern to search for") ((:pattern :type :string :description "The regex pattern to search for")
(:dir :type :string :description "Directory to search in (default is project root)")) (:dir :type :string :description "Directory to search in (default is project root)"))
@@ -416,7 +427,7 @@ EXAMPLES:
#+end_src #+end_src
*** The Shell Tool (Machine Actuation) *** The Shell Tool (Machine Actuation)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :shell "Executes a shell command on the local machine. Use this for file operations, system checks, or running tests." (def-cognitive-tool :shell "Executes a shell command on the local machine. Use this for file operations, system checks, or running tests."
((:cmd :type :string :description "The full bash command to execute")) ((:cmd :type :string :description "The full bash command to execute"))
:guard (lambda (args context) :guard (lambda (args context)
@@ -431,7 +442,7 @@ EXAMPLES:
#+end_src #+end_src
*** The Reload-Skill Tool (Hot Reload) *** The Reload-Skill Tool (Hot Reload)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :reload-skill "Reloads a skill from its Org-mode source file, recompiling into the live image without restarting the daemon." (def-cognitive-tool :reload-skill "Reloads a skill from its Org-mode source file, recompiling into the live image without restarting the daemon."
((:skill :type :string :description "The skill name (e.g., \"org-skill-policy\") or full path to the .org file")) ((:skill :type :string :description "The skill name (e.g., \"org-skill-policy\") or full path to the .org file"))
:guard (lambda (args context) :guard (lambda (args context)
@@ -467,7 +478,7 @@ EXAMPLES:
#+end_src #+end_src
*** The File Read Tool (V 0.2.0 File I/O) *** The File Read Tool (V 0.2.0 File I/O)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :read-file "Reads the contents of a file as a string." (def-cognitive-tool :read-file "Reads the contents of a file as a string."
((:file :type :string :description "The path to the file to read")) ((:file :type :string :description "The path to the file to read"))
:guard (lambda (args context) :guard (lambda (args context)
@@ -486,7 +497,7 @@ EXAMPLES:
#+end_src #+end_src
*** The File Write Tool (V 0.2.0 File I/O) *** The File Write Tool (V 0.2.0 File I/O)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :write-file "Writes content to a file, creating it if it doesn't exist." (def-cognitive-tool :write-file "Writes content to a file, creating it if it doesn't exist."
((:file :type :string :description "The path to the file to write") ((:file :type :string :description "The path to the file to write")
(:content :type :string :description "The content to write") (:content :type :string :description "The content to write")
@@ -519,7 +530,7 @@ EXAMPLES:
#+end_src #+end_src
*** The String Replace Tool (V 0.2.0 File I/O) *** The String Replace Tool (V 0.2.0 File I/O)
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(def-cognitive-tool :replace-string "Replaces occurrences of old-string with new-string in a file." (def-cognitive-tool :replace-string "Replaces occurrences of old-string with new-string in a file."
((:file :type :string :description "The path to the file") ((:file :type :string :description "The path to the file")
(:old :type :string :description "The substring to find and replace") (:old :type :string :description "The substring to find and replace")

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "tui-client.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
:PROPERTIES: :PROPERTIES:
:ID: tui-client-spec :ID: tui-client-spec
:CREATED: [2026-04-17 Fri 11:00] :CREATED: [2026-04-17 Fri 11:00]
@@ -10,7 +11,7 @@
The OpenCortex TUI Client is a standalone Common Lisp application built on **Croatoan**. It provides a real-time, multi-window interface for interacting with the OpenCortex daemon. The OpenCortex TUI Client is a standalone Common Lisp application built on **Croatoan**. It provides a real-time, multi-window interface for interacting with the OpenCortex daemon.
* Implementation * Implementation
#+begin_src lisp :tangle (expand-file-name "tui-client.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) #+begin_src lisp
(in-package :cl-user) (in-package :cl-user)
(defpackage :opencortex.tui (defpackage :opencortex.tui
(:use :cl :croatoan) (:use :cl :croatoan)

View File

@@ -30,7 +30,7 @@ fi
# --- 1. BOOTSTRAP --- # --- 1. BOOTSTRAP ---
# If the script is run standalone, it clones the full repo and restarts itself. # If the script is run standalone, it clones the full repo and restarts itself.
if [ ! -d "$SCRIPT_DIR/.git" ] && [ ! -d "$HOME/.opencortex" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then if [ ! -d "$SCRIPT_DIR/.git" ] && [ ! -f "$SCRIPT_DIR/harness/package.org" ] && [ ! -d "$HOME/.opencortex" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}" echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
git clone ssh://git@10.10.10.201:2222/amr/opencortex.git ~/.opencortex git clone ssh://git@10.10.10.201:2222/amr/opencortex.git ~/.opencortex
cd ~/.opencortex && git submodule update --init --recursive cd ~/.opencortex && git submodule update --init --recursive
@@ -144,7 +144,7 @@ setup_system() {
fi fi
echo -e "${YELLOW}--- Finalizing: Awakening the Brain ---${NC}" echo -e "${YELLOW}--- Finalizing: Awakening the Brain ---${NC}"
"$I_DIR/opencortex.sh" --boot > "$I_DIR/brain.log" 2>&1 & export I_DIR="$I_DIR"; "$I_DIR/opencortex.sh" --boot > "$I_DIR/brain.log" 2>&1 &
success=false success=false
for i in {1..30}; do for i in {1..30}; do
@@ -188,7 +188,7 @@ case "$COMMAND" in
if [ -f "$SCRIPT_DIR/.env" ]; then if [ -f "$SCRIPT_DIR/.env" ]; then
export OPENROUTER_API_KEY=$(grep OPENROUTER_API_KEY "$SCRIPT_DIR/.env" | cut -d'"' -f2) export OPENROUTER_API_KEY=$(grep OPENROUTER_API_KEY "$SCRIPT_DIR/.env" | cut -d'"' -f2)
fi fi
exec sbcl --non-interactive --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format *error-output* "FATAL LISP ERROR: ~a~%" c) (uiop:print-backtrace :stream *error-output*) (uiop:quit 1)))' --eval '(push (truename (uiop:getenv "I_DIR")) asdf:*central-registry*)' --eval '(format t "--- Quickloading OpenCortex ---~%")' --eval "(ql:quickload '(:opencortex :croatoan))" --eval '(opencortex:main)' exec sbcl --non-interactive --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format *error-output* "FATAL LISP ERROR: ~a~%" c) (uiop:print-backtrace :stream *error-output*) (uiop:quit 1)))' --eval '(let ((path (or (uiop:getenv "I_DIR") (uiop:getenv "SCRIPT_DIR")))) (when path (push (truename path) asdf:*central-registry*)))' --eval '(format t "--- Quickloading OpenCortex ---~%")' --eval "(ql:quickload '(:opencortex :croatoan))" --eval '(opencortex:main)'
;; ;;
tui) tui)
@@ -205,7 +205,7 @@ case "$COMMAND" in
echo -e "Launching Croatoan TUI..." echo -e "Launching Croatoan TUI..."
export SKILLS_DIR="${SCRIPT_DIR}/skills" export SKILLS_DIR="${SCRIPT_DIR}/skills"
[ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex" [ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex"
exec sbcl --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(push (truename (uiop:getenv "I_DIR")) asdf:*central-registry*)' --eval '(ql:quickload :opencortex/tui)' --eval '(opencortex.tui:main)' exec sbcl --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(let ((path (or (uiop:getenv "I_DIR") (uiop:getenv "SCRIPT_DIR")))) (when path (push (truename path) asdf:*central-registry*)))' --eval '(ql:quickload :opencortex/tui)' --eval '(opencortex.tui:main)'
;; ;;
cli) cli)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: bouncer-agent-skill :ID: bouncer-agent-skill
:CREATED: [2026-04-11 Sat 15:20] :CREATED: [2026-04-11 Sat 15:20]
@@ -38,7 +39,7 @@ When something is blocked, the logs clearly show which layer blocked it and why.
* Package Context * Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
@@ -58,7 +59,7 @@ The Bouncer implements the 5-Vector security model:
The vault stores sensitive credentials. This check scans action text for vault secrets to prevent accidental exposure. The vault stores sensitive credentials. This check scans action text for vault secrets to prevent accidental exposure.
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun bouncer-scan-secrets (text) (defun bouncer-scan-secrets (text)
"Scans TEXT for known secrets from the vault. "Scans TEXT for known secrets from the vault.
@@ -91,7 +92,7 @@ The vault stores sensitive credentials. This check scans action text for vault s
Detects when shell commands try to send data to untrusted network destinations. Detects when shell commands try to send data to untrusted network destinations.
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *bouncer-network-whitelist* (defvar *bouncer-network-whitelist*
'("api.telegram.org" "matrix.org" "googleapis.com" "openai.com" "anthropic.com") '("api.telegram.org" "matrix.org" "googleapis.com" "openai.com" "anthropic.com")
"Domains that the Bouncer considers safe for outbound connections. "Domains that the Bouncer considers safe for outbound connections.
@@ -129,7 +130,7 @@ Detects when shell commands try to send data to untrusted network destinations.
** bouncer-check: Main Security Gate ** bouncer-check: Main Security Gate
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun bouncer-check (action context) (defun bouncer-check (action context)
"The 5-Vector security gate for high-risk actions. "The 5-Vector security gate for high-risk actions.
@@ -213,7 +214,7 @@ Detects when shell commands try to send data to untrusted network destinations.
When a flight plan is approved in Emacs, the Bouncer detects it and re-injects the action. When a flight plan is approved in Emacs, the Bouncer detects it and re-injects the action.
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun bouncer-process-approvals () (defun bouncer-process-approvals ()
"Scans the object store for APPROVED flight plans and re-injects them. "Scans the object store for APPROVED flight plans and re-injects them.
@@ -269,7 +270,7 @@ When a flight plan is approved in Emacs, the Bouncer detects it and re-injects t
When the Bouncer intercepts a high-risk action, it creates a flight plan node for manual approval. When the Bouncer intercepts a high-risk action, it creates a flight plan node for manual approval.
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun bouncer-create-flight-plan (blocked-action) (defun bouncer-create-flight-plan (blocked-action)
"Creates an Org node representing a pending flight plan for manual approval. "Creates an Org node representing a pending flight plan for manual approval.
@@ -306,7 +307,7 @@ When the Bouncer intercepts a high-risk action, it creates a flight plan node fo
** Main Gate Function ** Main Gate Function
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun bouncer-deterministic-gate (action context) (defun bouncer-deterministic-gate (action context)
"Main deterministic gate for the Bouncer skill. "Main deterministic gate for the Bouncer skill.
@@ -345,7 +346,7 @@ When the Bouncer intercepts a high-risk action, it creates a flight plan node fo
** Skill Registration ** Skill Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-bouncer.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-bouncer (defskill :skill-bouncer
:priority 150 :priority 150
:trigger (lambda (ctx) (declare (ignore ctx)) t) :trigger (lambda (ctx) (declare (ignore ctx)) t)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-cli-gateway.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: cli-gateway-skill :ID: cli-gateway-skill
:CREATED: [2026-04-13 Mon 17:00] :CREATED: [2026-04-13 Mon 17:00]
@@ -11,7 +12,7 @@ The *CLI Gateway* is the primary sensory and actuating interface for human inter
* Implementation * Implementation
#+begin_src lisp :tangle (expand-file-name "org-skill-cli-gateway.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *cli-port* 9105) (defvar *cli-port* 9105)
(defvar *cli-server-socket* nil) (defvar *cli-server-socket* nil)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: credentials-vault-skill :ID: credentials-vault-skill
:CREATED: [2026-04-09 Thu] :CREATED: [2026-04-09 Thu]
@@ -33,7 +34,7 @@ Securely manage all authentication tokens required for the opencortex to operate
The vault provides a secure lookup table in RAM, backed by the persistent Memory. Access is restricted to internal kernel requests and explicitly authorized deterministic gates. The vault provides a secure lookup table in RAM, backed by the persistent Memory. Access is restricted to internal kernel requests and explicitly authorized deterministic gates.
** 2. Semantic Interfaces ** 2. Semantic Interfaces
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun vault-get-secret (provider &key type) (defun vault-get-secret (provider &key type)
"Retrieves a secret (api-key or session) for a provider.") "Retrieves a secret (api-key or session) for a provider.")
@@ -61,13 +62,13 @@ Tests in `tests/vault-tests.lisp` will verify:
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
#+end_src #+end_src
** Vault State ** Vault State
We maintain an in-memory hash table for secrets, which is hydrated from and persisted to the Memory. We maintain an in-memory hash table for secrets, which is hydrated from and persisted to the Memory.
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar opencortex::*vault-memory* (make-hash-table :test 'equal) (defvar opencortex::*vault-memory* (make-hash-table :test 'equal)
"In-memory cache of sensitive credentials.") "In-memory cache of sensitive credentials.")
#+end_src #+end_src
@@ -75,7 +76,7 @@ We maintain an in-memory hash table for secrets, which is hydrated from and pers
** Helper: Secret Masking ** Helper: Secret Masking
The `vault-mask-string` function ensures that diagnostic output never contains the full plaintext of a sensitive token. The `vault-mask-string` function ensures that diagnostic output never contains the full plaintext of a sensitive token.
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun vault-mask-string (str) (defun vault-mask-string (str)
"Returns a masked version of a sensitive string." "Returns a masked version of a sensitive string."
(if (and str (> (length str) 8)) (if (and str (> (length str) 8))
@@ -86,7 +87,7 @@ The `vault-mask-string` function ensures that diagnostic output never contains t
** Retrieval (vault-get-secret) ** Retrieval (vault-get-secret)
This function is the secure getter for all system secrets. It prioritizes the Vault (Memory) and falls back to environment variables for legacy compatibility. This function is the secure getter for all system secrets. It prioritizes the Vault (Memory) and falls back to environment variables for legacy compatibility.
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun vault-get-secret (provider &key (type :api-key)) (defun vault-get-secret (provider &key (type :api-key))
"Retrieves a credential. Type can be :api-key or :session." "Retrieves a credential. Type can be :api-key or :session."
(let* ((key (format nil "~a-~a" provider type)) (let* ((key (format nil "~a-~a" provider type))
@@ -112,7 +113,7 @@ This function is the secure getter for all system secrets. It prioritizes the Va
** Persistence (vault-set-secret) ** Persistence (vault-set-secret)
When a secret is updated, we immediately snapshot the Memory to ensure the credential change is versioned and durable. When a secret is updated, we immediately snapshot the Memory to ensure the credential change is versioned and durable.
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun vault-set-secret (provider secret &key (type :api-key)) (defun vault-set-secret (provider secret &key (type :api-key))
"Securely stores a secret and triggers a Merkle snapshot." "Securely stores a secret and triggers a Merkle snapshot."
(let ((key (format nil "~a-~a" provider type))) (let ((key (format nil "~a-~a" provider type)))
@@ -125,7 +126,7 @@ When a secret is updated, we immediately snapshot the Memory to ensure the crede
** Onboarding Logic ** Onboarding Logic
Retained from the legacy Google skill, this provides the instructions for the autonomous cookie handshake. Retained from the legacy Google skill, this provides the instructions for the autonomous cookie handshake.
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun vault-onboard-gemini-web () (defun vault-onboard-gemini-web ()
"Instructions for the Autonomous Cookie Handshake." "Instructions for the Autonomous Cookie Handshake."
(harness-log "--- GEMINI WEB ONBOARDING ---") (harness-log "--- GEMINI WEB ONBOARDING ---")
@@ -137,7 +138,7 @@ Retained from the legacy Google skill, this provides the instructions for the au
#+end_src #+end_src
** Registration ** Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-credentials-vault.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(progn (progn
(defskill :skill-credentials-vault (defskill :skill-credentials-vault
:priority 200 ; High priority, foundational :priority 200 ; High priority, foundational

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: emacs-edit-skill :ID: emacs-edit-skill
:CREATED: [2026-04-23 Thu] :CREATED: [2026-04-23 Thu]
@@ -58,14 +59,14 @@ Single entry point `emacs-edit-modify` takes a file path, operation, and paramet
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** ID Generation ** ID Generation
Generate unique IDs for headlines. Generate unique IDs for headlines.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-generate-id () (defun emacs-edit-generate-id ()
"Generates a unique ID for org-mode headlines. "Generates a unique ID for org-mode headlines.
Format: 8-char hex + timestamp for uniqueness." Format: 8-char hex + timestamp for uniqueness."
@@ -84,7 +85,7 @@ Format: 8-char hex + timestamp for uniqueness."
** Org Printer (AST → Org Format) ** Org Printer (AST → Org Format)
Converts AST back to org format, preserving structure. Converts AST back to org format, preserving structure.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-print-headline (ast &key indent-level) (defun emacs-edit-print-headline (ast &key indent-level)
"Converts a HEADLINE AST node to org text. "Converts a HEADLINE AST node to org text.
INDENT-LEVEL is number of leading asterisks." INDENT-LEVEL is number of leading asterisks."
@@ -154,7 +155,7 @@ Preserves structure including #+begin_src blocks."
** Read Operation ** Read Operation
Parse org file to AST. Parse org file to AST.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *org-parser-cache* (make-hash-table :test 'equal) (defvar *org-parser-cache* (make-hash-table :test 'equal)
"Cache for parsed org files.") "Cache for parsed org files.")
@@ -180,7 +181,7 @@ Returns the parsed AST. Uses cache for performance."
** Write Operation ** Write Operation
Write AST back to file preserving structure. Write AST back to file preserving structure.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-write-file (file-path ast) (defun emacs-edit-write-file (file-path ast)
"Writes AST back to FILE-PATH, preserving org structure. "Writes AST back to FILE-PATH, preserving org structure.
Clears cache after write." Clears cache after write."
@@ -195,7 +196,7 @@ Clears cache after write."
** Add Headline Operation ** Add Headline Operation
Add a new headline to an existing AST. Add a new headline to an existing AST.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-add-headline (ast title &key todo properties) (defun emacs-edit-add-headline (ast title &key todo properties)
"Adds a new headline to AST. "Adds a new headline to AST.
Returns modified AST." Returns modified AST."
@@ -224,7 +225,7 @@ Returns modified AST."
** Set Property Operation ** Set Property Operation
Set a property on an existing headline (by ID or TITLE). Set a property on an existing headline (by ID or TITLE).
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-find-headline-by-id (ast target-id) (defun emacs-edit-find-headline-by-id (ast target-id)
"Recursively finds headline with matching :ID: property." "Recursively finds headline with matching :ID: property."
(when (eq (getf ast :type) :headline) (when (eq (getf ast :type) :headline)
@@ -268,7 +269,7 @@ Returns modified AST."
** Set TODO State Operation ** Set TODO State Operation
Change TODO state (TODO → DONE → etc). Change TODO state (TODO → DONE → etc).
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-set-todo (ast target new-state) (defun emacs-edit-set-todo (ast target new-state)
"Sets TODO state on headline matching TARGET. "Sets TODO state on headline matching TARGET.
NEW-STATE should be 'TODO', 'DONE', 'IN-PROGRESS', etc." NEW-STATE should be 'TODO', 'DONE', 'IN-PROGRESS', etc."
@@ -279,7 +280,7 @@ NEW-STATE should be 'TODO', 'DONE', 'IN-PROGRESS', etc."
** Unified Entry Point ** Unified Entry Point
Main operation dispatcher. Main operation dispatcher.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun emacs-edit-modify (file-path operation &key params) (defun emacs-edit-modify (file-path operation &key params)
"Main entry point for org-mode file manipulation. "Main entry point for org-mode file manipulation.
OPERATIONS: OPERATIONS:
@@ -322,7 +323,7 @@ OPERATIONS:
** Cognitive Tools ** Cognitive Tools
Exposes operations to the Probabilistic Engine. Exposes operations to the Probabilistic Engine.
#+begin_src lisp :tangle (expand-file-name "org-skill-emacs-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(def-cognitive-tool :org-read (def-cognitive-tool :org-read
"Reads an org-mode file and parses it to structured AST. "Reads an org-mode file and parses it to structured AST.
Use this BEFORE modifying org files to understand their structure." Use this BEFORE modifying org files to understand their structure."

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: 37f2b59f-4537-4cca-ac7f-5c24b9e2e773 :ID: 37f2b59f-4537-4cca-ac7f-5c24b9e2e773
:CREATED: [2026-03-30 Mon 21:16] :CREATED: [2026-03-30 Mon 21:16]
@@ -105,16 +106,16 @@ You are forbidden from considering a task complete without updating ~gtd.org~. R
The engineering standards skill is a HARD BLOCK gate. Violations are rejected, not warned. The engineering standards skill is a HARD BLOCK gate. Violations are rejected, not warned.
** Pre-Task Enforcement (Blocking) ** Global Configuration
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(in-package :opencortex) (in-package :opencortex)
(defvar *engineering-std-*project-root* nil (defvar *engineering-std-project-root* nil
"Path to the project root for enforcement checks.") "Path to the project root for enforcement checks.")
(defun engineering-std-set-project-root (path) (defun engineering-std-set-project-root (path)
(setf *engineering-std-*project-root* (uiop:ensure-directory-pathname path))) (setf *engineering-std-project-root* (uiop:ensure-directory-pathname path)))
(defstruct engineering-violation (defstruct engineering-violation
(phase nil) (phase nil)
@@ -133,12 +134,14 @@ The engineering standards skill is a HARD BLOCK gate. Violations are rejected, n
(:post-task (:post-task
(:tests-pass "All tests must pass") (:tests-pass "All tests must pass")
(:no-artifacts "No orphaned .bak, .log, .tmp files")))) (:no-artifacts "No orphaned .bak, .log, .tmp files"))))
(defvar *engineering-std-initialized* nil)
#+end_src #+end_src
** Git Clean Check (Blocking) ** Git Clean Check (Blocking)
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defun verify-git-clean-p (&optional (dir *engineering-std-*project-root*)) (defun verify-git-clean-p (&optional (dir *engineering-std-project-root*))
"Returns T if the git repository at DIR has no uncommitted changes." "Returns T if the git repository at DIR has no uncommitted changes."
(when dir (when dir
(let ((status (uiop:run-program (list "git" "-C" (namestring dir) "status" "--porcelain") (let ((status (uiop:run-program (list "git" "-C" (namestring dir) "status" "--porcelain")
@@ -146,7 +149,7 @@ The engineering standards skill is a HARD BLOCK gate. Violations are rejected, n
:ignore-error-status t))) :ignore-error-status t)))
(string= "" (string-trim '(#\Space #\Newline #\Tab) status))))) (string= "" (string-trim '(#\Space #\Newline #\Tab) status)))))
(defun check-git-clean (&optional (dir *engineering-std-*project-root*)) (defun check-git-clean (&optional (dir *engineering-std-project-root*))
"Returns violation if git is dirty, nil if clean." "Returns violation if git is dirty, nil if clean."
(unless (verify-git-clean-p dir) (unless (verify-git-clean-p dir)
(make-engineering-violation (make-engineering-violation
@@ -156,11 +159,69 @@ The engineering standards skill is a HARD BLOCK gate. Violations are rejected, n
:severity :blocker))) :severity :blocker)))
#+end_src #+end_src
** Blocking Gate (Hard Enforcement)
** Test Suite #+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defun engineering-standards-gate (action context)
"The deterministic HARD BLOCK gate for Engineering Standards.
These tests verify the enforcement logic. Run with: BLOCKING checks (return :LOG on violation):
~(fiveam:run! 'engineering-standards-suite)~ - Git tree must be clean before file modifications
WARNING checks (log only):
- Skill catalog should be queried first
Returns modified action, or :LOG/:EVENT on violation."
(let* ((payload (getf action :payload))
(tool (getf payload :tool))
(file (getf payload :file))
(code (getf payload :code))
(modifies-files-p (or file code tool)))
;; BLOCKING: Git clean required for file modifications
(when modifies-files-p
(let ((git-check (check-git-clean *engineering-std-project-root*)))
(when git-check
(harness-log "~a" (engineering-violation-message git-check))
(return-from engineering-standards-gate
(list :type :log
:payload (list :text (engineering-violation-message git-check)))))))
action))
#+end_src
** Skill Registration
The skill runs at highest priority (1000) to block violations before any other skill.
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defskill :skill-engineering-standards
:priority 1000
:trigger (lambda (ctx)
(declare (ignore ctx))
t)
:probabilistic nil
:deterministic #'engineering-standards-gate)
#+end_src
** Initialize Project Root
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defun engineering-std-init ()
"Initialize the enforcement system with project root."
(unless *engineering-std-initialized*
(let ((env-root (or (uiop:getenv "OPENCORTEX_ROOT")
(uiop:getenv "MEMEX_DIR")
"/home/user/memex/projects/opencortex")))
(engineering-std-set-project-root env-root)
(setf *engineering-std-initialized* t)
(harness-log "ENGINEERING STANDARDS: Initialized with root ~a" *engineering-std-project-root*))))
;; Auto-initialize on load
(engineering-std-init)
#+end_src
* Test Suite
#+begin_src lisp :tangle (expand-file-name "engineering-standards-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/tests")) #+begin_src lisp :tangle (expand-file-name "engineering-standards-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/tests"))
(defpackage :opencortex-engineering-standards-tests (defpackage :opencortex-engineering-standards-tests
@@ -227,70 +288,6 @@ These tests verify the enforcement logic. Run with:
(is (eq :request (getf result :type)))))) (is (eq :request (getf result :type))))))
#+end_src #+end_src
** Blocking Gate (Hard Enforcement)
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defun engineering-standards-gate (action context)
"The deterministic HARD BLOCK gate for Engineering Standards.
BLOCKING checks (return :LOG on violation):
- Git tree must be clean before file modifications
WARNING checks (log only):
- Skill catalog should be queried first
Returns modified action, or :LOG/:EVENT on violation."
(let* ((payload (getf action :payload))
(tool (getf payload :tool))
(file (getf payload :file))
(code (getf payload :code))
(modifies-files-p (or file code tool)))
;; BLOCKING: Git clean required for file modifications
(when modifies-files-p
(let ((git-check (check-git-clean *engineering-std-*project-root*)))
(when git-check
(harness-log "~a" (engineering-violation-message git-check))
(return-from engineering-standards-gate
(list :type :log
:payload (list :text (engineering-violation-message git-check)))))))
action))
#+end_src
** Skill Registration
The skill runs at highest priority (1000) to block violations before any other skill.
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defskill :skill-engineering-standards
:priority 1000
:trigger (lambda (ctx)
(declare (ignore ctx))
t)
:probabilistic nil
:deterministic #'engineering-standards-gate)
#+end_src
** Initialize Project Root
#+begin_src lisp :tangle (expand-file-name "org-skill-engineering-standards.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defvar *engineering-std-initialized* nil)
(defun engineering-std-init ()
"Initialize the enforcement system with project root."
(unless *engineering-std-initialized*
(let ((env-root (or (uiop:getenv "OPENCORTEX_ROOT")
(uiop:getenv "MEMEX_DIR")
"/home/user/memex/projects/opencortex")))
(engineering-std-set-project-root env-root)
(setf *engineering-std-initialized* t)
(harness-log "ENGINEERING STANDARDS: Initialized with root ~a" *engineering-std-*project-root*))))
;; Auto-initialize on load
(engineering-std-init)
#+end_src
* See Also * See Also
- [[file:org-skill-literate-programming.org][Literate Programming Skill]] - Structural validation and tangle rules - [[file:org-skill-literate-programming.org][Literate Programming Skill]] - Structural validation and tangle rules
- [[file:org-skill-policy.org][Policy Skill]] - Constitutional constraints - [[file:org-skill-policy.org][Policy Skill]] - Constitutional constraints

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: gardener-skill :ID: gardener-skill
:CREATED: [2026-04-13 Mon 18:50] :CREATED: [2026-04-13 Mon 18:50]
@@ -37,14 +38,14 @@ The Gardener runs on a low-priority heartbeat. It performs a "Deep Audit" of the
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** State: Maintenance Cycle ** State: Maintenance Cycle
We track the last audit time to ensure the Gardener doesn't over-consume resources. We track the last audit time to ensure the Gardener doesn't over-consume resources.
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *gardener-last-audit* 0 (defvar *gardener-last-audit* 0
"The universal-time of the last full Memex audit.") "The universal-time of the last full Memex audit.")
#+end_src #+end_src
@@ -52,7 +53,7 @@ We track the last audit time to ensure the Gardener doesn't over-consume resourc
** Audit: Broken Links ** Audit: Broken Links
Scans the content of all objects for `id:` links and verifies the targets exist. Scans the content of all objects for `id:` links and verifies the targets exist.
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun gardener-find-broken-links () (defun gardener-find-broken-links ()
"Returns a list of broken ID links found in the Memex." "Returns a list of broken ID links found in the Memex."
(let ((broken nil)) (let ((broken nil))
@@ -69,7 +70,7 @@ Scans the content of all objects for `id:` links and verifies the targets exist.
** Audit: Orphaned Nodes ** Audit: Orphaned Nodes
Identifies nodes that are not linked to and do not link to anything else. Identifies nodes that are not linked to and do not link to anything else.
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun gardener-find-orphans () (defun gardener-find-orphans ()
"Returns a list of IDs for headlines that are structurally isolated." "Returns a list of IDs for headlines that are structurally isolated."
(let ((inbound (make-hash-table :test 'equal)) (let ((inbound (make-hash-table :test 'equal))
@@ -95,7 +96,7 @@ Identifies nodes that are not linked to and do not link to anything else.
** Skill Logic: The Audit Pass ** Skill Logic: The Audit Pass
The Gardener's deterministic gate performs the actual analysis and logs the results. In future versions, it will generate probabilistic repair proposals. The Gardener's deterministic gate performs the actual analysis and logs the results. In future versions, it will generate probabilistic repair proposals.
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun gardener-deterministic-gate (action context) (defun gardener-deterministic-gate (action context)
"Main gate for the Gardener skill. Audits graph integrity." "Main gate for the Gardener skill. Audits graph integrity."
(declare (ignore action context)) (declare (ignore action context))
@@ -118,7 +119,7 @@ The Gardener's deterministic gate performs the actual analysis and logs the resu
#+end_src #+end_src
** Skill Registration ** Skill Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-gardener.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-gardener (defskill :skill-gardener
:priority 40 :priority 40
:trigger (lambda (ctx) :trigger (lambda (ctx)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-homoiconic-memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: homoiconic-memory-skill :ID: homoiconic-memory-skill
:CREATED: [2026-04-10 Fri] :CREATED: [2026-04-10 Fri]
@@ -11,7 +12,7 @@ The *Homoiconic Memory* skill provides the core persistence layer for OpenCortex
* Implementation * Implementation
#+begin_src lisp :tangle (expand-file-name "org-skill-homoiconic-memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun memory-org-to-json (source) (defun memory-org-to-json (source)
"Converts Org-mode source to JSON AST." "Converts Org-mode source to JSON AST."

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-lisp-utils.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: lisp-utils-skill :ID: lisp-utils-skill
:CREATED: [2026-04-23 Thu] :CREATED: [2026-04-23 Thu]
@@ -16,7 +17,7 @@ The *Lisp Utils* skill provides general-purpose Lisp utilities for the entire sy
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
#+begin_src lisp :tangle (expand-file-name "org-skill-lisp-utils.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defun count-char (char string) (defun count-char (char string)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: literate-programming-skill-2026 :ID: literate-programming-skill-2026
:CREATED: [2026-04-25 Sat] :CREATED: [2026-04-25 Sat]
@@ -57,7 +58,7 @@ Code without surrounding prose is a bug report waiting to happen.
** Block Balance Checker ** Block Balance Checker
#+begin_src lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defun literate-check-block-balance (code-string) (defun literate-check-block-balance (code-string)
@@ -94,7 +95,7 @@ Code without surrounding prose is a bug report waiting to happen.
** File-Level Balance Audit ** File-Level Balance Audit
#+begin_src lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun literate-audit-org-file (filepath) (defun literate-audit-org-file (filepath)
"Audits all tangled lisp blocks in an Org file for structural balance. "Audits all tangled lisp blocks in an Org file for structural balance.
@@ -145,7 +146,7 @@ Code without surrounding prose is a bug report waiting to happen.
Verifies that tangled `.lisp` files are in sync with their Org source. Violation: edited .lisp directly instead of through Org. Verifies that tangled `.lisp` files are in sync with their Org source. Violation: edited .lisp directly instead of through Org.
#+begin_src lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *tangle-targets* (defvar *tangle-targets*
'(("skills/org-skill-engineering-standards.org" . "library/gen/org-skill-engineering-standards.lisp") '(("skills/org-skill-engineering-standards.org" . "library/gen/org-skill-engineering-standards.lisp")
("skills/org-skill-literate-programming.org" . "library/gen/org-skill-literate-programming.lisp") ("skills/org-skill-literate-programming.org" . "library/gen/org-skill-literate-programming.lisp")
@@ -184,7 +185,7 @@ This detects direct .lisp edits (which violate the LP workflow)."
The LP skill runs at priority 1100 (just below engineering-standards at 1000). The LP skill runs at priority 1100 (just below engineering-standards at 1000).
#+begin_src lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-literate-programming (defskill :skill-literate-programming
:priority 1100 :priority 1100
:trigger (lambda (ctx) :trigger (lambda (ctx)
@@ -218,7 +219,7 @@ The LP skill runs at priority 1100 (just below engineering-standards at 1000).
** Initialize Project Root ** Initialize Project Root
#+begin_src lisp :tangle (expand-file-name "org-skill-literate-programming.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *lp-initialized* nil) (defvar *lp-initialized* nil)
(defun lp-init () (defun lp-init ()

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-llama-backend.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: llama-backend-skill :ID: llama-backend-skill
:CREATED: [2026-04-17 Fri 20:00] :CREATED: [2026-04-17 Fri 20:00]
@@ -21,12 +22,12 @@ This skill acts as a proxy between the OpenCortex kernel and the Lisp-agnostic `
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-llama-backend.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** The Inference Engine (llama-inference) ** The Inference Engine (llama-inference)
#+begin_src lisp :tangle (expand-file-name "org-skill-llama-backend.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun llama-inference (prompt system-prompt &key (model "local-model")) (defun llama-inference (prompt system-prompt &key (model "local-model"))
"Sends a completion request to the local llama.cpp server." "Sends a completion request to the local llama.cpp server."
(let ((endpoint (uiop:getenv "LLAMACPP_ENDPOINT"))) (let ((endpoint (uiop:getenv "LLAMACPP_ENDPOINT")))
@@ -51,7 +52,7 @@ This skill acts as a proxy between the OpenCortex kernel and the Lisp-agnostic `
#+end_src #+end_src
** Registration ** Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-llama-backend.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(progn (progn
(register-probabilistic-backend :llama #'llama-inference) (register-probabilistic-backend :llama #'llama-inference)
(harness-log "LLAMA: Local backend registered and active.")) (harness-log "LLAMA: Local backend registered and active."))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-llm-gateway.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: llm-gateway-skill :ID: llm-gateway-skill
:CREATED: [2026-04-09 Thu] :CREATED: [2026-04-09 Thu]
@@ -19,7 +20,7 @@ The gateway utilizes a functional dispatch pattern. A single entry point, `execu
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Implementation ** Implementation
#+begin_src lisp :tangle (expand-file-name "org-skill-llm-gateway.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun get-nested (alist &rest keys) (defun get-nested (alist &rest keys)
"Recursively extracts nested values from an alist, handling both objects and arrays." "Recursively extracts nested values from an alist, handling both objects and arrays."

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-peripheral-vision.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: org-skill-peripheral-vision :ID: org-skill-peripheral-vision
:CREATED: [2026-04-12 Sun 14:15] :CREATED: [2026-04-12 Sun 14:15]
@@ -39,10 +40,10 @@ Move context pruning and rendering logic out of `context.lisp` to allow for more
* Package Context * Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-peripheral-vision.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
\n#+begin_src lisp :tangle (expand-file-name "org-skill-peripheral-vision.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) \n#+begin_src lisp
(defun context-render-to-org (obj &key depth foveal-id semantic-threshold foveal-vector) (defun context-render-to-org (obj &key depth foveal-id semantic-threshold foveal-vector)
"Recursively renders an org-object with foveal-peripheral pruning.") "Recursively renders an org-object with foveal-peripheral pruning.")
@@ -53,7 +54,7 @@ Move context pruning and rendering logic out of `context.lisp` to allow for more
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Foveal-Peripheral Pruning ** Foveal-Peripheral Pruning
#+begin_src lisp :tangle (expand-file-name "org-skill-peripheral-vision.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun context-render-to-org (obj &key (depth 1) (foveal-id nil) (semantic-threshold 0.75) (foveal-vector nil)) (defun context-render-to-org (obj &key (depth 1) (foveal-id nil) (semantic-threshold 0.75) (foveal-vector nil))
"Recursively renders an org-object and its children to an Org string using a Foveal-Peripheral Hybrid model." "Recursively renders an org-object and its children to an Org string using a Foveal-Peripheral Hybrid model."
@@ -117,7 +118,7 @@ Move context pruning and rendering logic out of `context.lisp` to allow for more
#+end_src #+end_src
* Registration * Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-peripheral-vision.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-peripheral-vision (defskill :skill-peripheral-vision
:priority 90 :priority 90
:dependencies ("org-skill-embedding") :dependencies ("org-skill-embedding")

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: 47425a43-2be0-423c-8509-22592cfe9c9e :ID: 47425a43-2be0-423c-8509-22592cfe9c9e
:CREATED: [2026-04-07 Tue 12:57] :CREATED: [2026-04-07 Tue 12:57]
@@ -44,23 +45,11 @@ Therefore, Policy encodes not just rules, but *values*:
Every skill executes within its own jailed package namespace, inheriting core harness symbols while maintaining isolation from other skills. Every skill executes within its own jailed package namespace, inheriting core harness symbols while maintaining isolation from other skills.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
* The Override Hierarchy * Global Policy Configuration
When two invariants conflict, resolution follows a strict priority order. This prevents the agent from freezing on ethical edge cases.
| Priority | Invariant | Philosophy |
|----------|-----------|------------|
| 500 | Transparency | If you can't explain it, you can't do it |
| 400 | Autonomy | Independence from proprietary control is the primary goal |
| 300 | Zero-Bloat | Complexity must be earned, not imported |
| 250 | Modularity | Complexity belongs at the edges, not the core |
| 200 | Mentorship | Teaching increases capability; doing removes it |
| 100 | Sustainability | Offline capability today enables 100-year survival |
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
(defvar *policy-invariant-priorities* (defvar *policy-invariant-priorities*
'((:transparency . 500) '((:transparency . 500)
@@ -76,6 +65,75 @@ When two invariants conflict, the higher priority wins.
Example: Modularity (250) takes precedence over Mentorship (200), Example: Modularity (250) takes precedence over Mentorship (200),
meaning a change that would fatten the harness is blocked meaning a change that would fatten the harness is blocked
even if it would be educational.") even if it would be educational.")
(defvar *proprietary-domain-watchlist*
'("googleapis.com" "api.openai.com" "anthropic.com" "api.groq.com" "openrouter.ai")
"Domains representing centralized, proprietary control.
Actions targeting these are logged as autonomy debt, not hard-blocked.
This is because tactical gateway usage (Telegram, Signal, OpenRouter)
is permitted under the strategic mandate for autonomy.
Strategic goal: Replace all proprietary APIs with local alternatives.
Tactical reality: Use what's available while building toward that goal.")
(defvar *policy-max-skill-size-chars* 50000
"Maximum recommended size for a skill file tangled from an Org note.
This is a soft limit—the check warns but does not block.
A large, well-documented skill is acceptable; a small, poorly-documented
one that adds unnecessary complexity is not.")
(defvar *modularity-protected-paths*
'("harness/" "opencortex.asd")
"Paths that constitute the unbreakable core of the system.
Any action targeting these paths must include a :modularity-justification
explaining why the change cannot be implemented as a skill.
The Thin Harness principle: What belongs in the harness?
- Core signal processing (Perceive-Reason-Act loop)
- Memory and persistence primitives
- Protocol definition and validation
- Skills register and dispatch
What belongs in skills?
- Policy and security
- LLM integration
- Domain-specific functionality
- New actuators")
(defvar *mentorship-required-actions*
'(:create-skill :eval :modify-file :write-file :replace
:rename-file :delete-file :shell :create-note)
"Actions that trigger the Mentorship invariant.
These are high-impact actions that should come with explanations
not just for the user, but for future debugging and maintenance.")
(defvar *cloud-only-backends* '(:openrouter :openai :anthropic :groq :gemini-api)
"Backends requiring internet connection and external infrastructure.
These are acceptable as fallbacks when local inference is unavailable,
but should be logged as sustainability debt for tracking purposes.")
#+end_src
* The Override Hierarchy
When two invariants conflict, resolution follows a strict priority order. This prevents the agent from freezing on ethical edge cases.
| Priority | Invariant | Philosophy |
|----------|-----------|------------|
| 500 | Transparency | If you can't explain it, you can't do it |
| 400 | Autonomy | Independence from proprietary control is the primary goal |
| 300 | Zero-Bloat | Complexity must be earned, not imported |
| 250 | Modularity | Complexity belongs at the edges, not the core |
| 200 | Mentorship | Teaching increases capability; doing removes it |
| 100 | Sustainability | Offline capability today enables 100-year survival |
#+begin_src lisp
#+end_src #+end_src
* The Core Invariants * The Core Invariants
@@ -91,7 +149,7 @@ At the gate:
- Every user-facing action must carry an `:explanation` - Every user-facing action must carry an `:explanation`
- Log messages must include the triggering invariant - Log messages must include the triggering invariant
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun policy-check-transparency (action context) (defun policy-check-transparency (action context)
(defun policy-check-transparency (action context) (defun policy-check-transparency (action context)
"Ensures the action is inspectable and user-facing actions carry an explanation. "Ensures the action is inspectable and user-facing actions carry an explanation.
@@ -138,17 +196,8 @@ At the gate:
Every action should increase the user's independence from centralized, proprietary platforms. When the system uses a proprietary API, it's logged as "autonomy debt"—acceptable tactically, but flagged for eventual replacement. Every action should increase the user's independence from centralized, proprietary platforms. When the system uses a proprietary API, it's logged as "autonomy debt"—acceptable tactically, but flagged for eventual replacement.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *proprietary-domain-watchlist*
'("googleapis.com" "api.openai.com" "anthropic.com" "api.groq.com" "openrouter.ai")
"Domains representing centralized, proprietary control.
Actions targeting these are logged as autonomy debt, not hard-blocked.
This is because tactical gateway usage (Telegram, Signal, OpenRouter)
is permitted under the strategic mandate for autonomy.
Strategic goal: Replace all proprietary APIs with local alternatives.
Tactical reality: Use what's available while building toward that goal.")
(defun policy-scan-proprietary-references (action) (defun policy-scan-proprietary-references (action)
"Scans ACTION text fields for proprietary domain references. "Scans ACTION text fields for proprietary domain references.
@@ -205,13 +254,8 @@ Every action should increase the user's independence from centralized, proprieta
The system harness must remain minimalist. "Just-in-case" code is a security vulnerability. Complexity must be earned through demonstrated need, not anticipation of future use. The system harness must remain minimalist. "Just-in-case" code is a security vulnerability. Complexity must be earned through demonstrated need, not anticipation of future use.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *policy-max-skill-size-chars* 50000
"Maximum recommended size for a skill file tangled from an Org note.
This is a soft limit—the check warns but does not block.
A large, well-documented skill is acceptable; a small, poorly-documented
one that adds unnecessary complexity is not.")
(defun policy-check-bloat (action context) (defun policy-check-bloat (action context)
"Warns if a :create-skill action exceeds the bloat threshold. "Warns if a :create-skill action exceeds the bloat threshold.
@@ -256,25 +300,8 @@ This is the most important invariant for system stability. If the harness grows
- Harder to debug when things go wrong - Harder to debug when things go wrong
- Harder to maintain across versions - Harder to maintain across versions
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *modularity-protected-paths*
'("harness/" "opencortex.asd")
"Paths that constitute the unbreakable core of the system.
Any action targeting these paths must include a :modularity-justification
explaining why the change cannot be implemented as a skill.
The Thin Harness principle: What belongs in the harness?
- Core signal processing (Perceive-Reason-Act loop)
- Memory and persistence primitives
- Protocol definition and validation
- Skills register and dispatch
What belongs in skills?
- Policy and security
- LLM integration
- Domain-specific functionality
- New actuators")
(defun policy-check-modularity (action context) (defun policy-check-modularity (action context)
"Blocks modifications to the system's protected core unless justified. "Blocks modifications to the system's protected core unless justified.
@@ -323,14 +350,8 @@ This is the most important invariant for system stability. If the harness grows
The agent's goal is not to "do it for the user," but to "empower the user." Every autonomous action must be explained at a level that increases the user's technical understanding. The agent's goal is not to "do it for the user," but to "empower the user." Every autonomous action must be explained at a level that increases the user's technical understanding.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *mentorship-required-actions*
'(:create-skill :eval :modify-file :write-file :replace
:rename-file :delete-file :shell :create-note)
"Actions that trigger the Mentorship invariant.
These are high-impact actions that should come with explanations
not just for the user, but for future debugging and maintenance.")
(defun policy-check-mentorship (action context) (defun policy-check-mentorship (action context)
"Blocks high-impact actions that lack a mentorship note. "Blocks high-impact actions that lack a mentorship note.
@@ -380,12 +401,8 @@ The Memex should be functional even when:
This means preferring local, energy-efficient architectures over cloud-dependent ones. This means preferring local, energy-efficient architectures over cloud-dependent ones.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *cloud-only-backends* '(:openrouter :openai :anthropic :groq :gemini-api)
"Backends requiring internet connection and external infrastructure.
These are acceptable as fallbacks when local inference is unavailable,
but should be logged as sustainability debt for tracking purposes.")
(defun policy-check-sustainability (action context) (defun policy-check-sustainability (action context)
"Logs sustainability debt when action relies on cloud-only infrastructure. "Logs sustainability debt when action relies on cloud-only infrastructure.
@@ -417,7 +434,7 @@ This means preferring local, energy-efficient architectures over cloud-dependent
When the policy gate blocks or modifies an action, it must tell the user *why*. This creates an auditable log of every policy decision. When the policy gate blocks or modifies an action, it must tell the user *why*. This creates an auditable log of every policy decision.
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun policy-explain (invariant-key message &optional original-action) (defun policy-explain (invariant-key message &optional original-action)
"Formats a policy decision into an auditable explanation plist. "Formats a policy decision into an auditable explanation plist.
@@ -446,7 +463,7 @@ When the policy gate blocks or modifies an action, it must tell the user *why*.
** Running Invariant Checks ** Running Invariant Checks
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun policy-run-invariant-checks (action context) (defun policy-run-invariant-checks (action context)
"Runs all invariant checks in priority order. "Runs all invariant checks in priority order.
@@ -509,7 +526,7 @@ When the policy gate blocks or modifies an action, it must tell the user *why*.
** Main Policy Gate ** Main Policy Gate
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun policy-deterministic-gate (action context) (defun policy-deterministic-gate (action context)
"The main policy gate entry point. "The main policy gate entry point.
@@ -541,7 +558,7 @@ When the policy gate blocks or modifies an action, it must tell the user *why*.
* Skill Registration * Skill Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-policy.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-policy (defskill :skill-policy
:priority 500 :priority 500
:trigger (lambda (ctx) (declare (ignore ctx)) t) :trigger (lambda (ctx) (declare (ignore ctx)) t)

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-protocol-validator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: org-skill-communication-protocol-validator :ID: org-skill-communication-protocol-validator
:CREATED: [2026-04-12 Sun 14:35] :CREATED: [2026-04-12 Sun 14:35]
@@ -45,7 +46,7 @@ Decouple protocol parsing (framing/unframing) from semantic validation.
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Schema Enforcement ** Schema Enforcement
#+begin_src lisp :tangle (expand-file-name "org-skill-protocol-validator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defun validate-communication-protocol-schema (msg) (defun validate-communication-protocol-schema (msg)
@@ -84,7 +85,7 @@ Decouple protocol parsing (framing/unframing) from semantic validation.
#+end_src #+end_src
* Registration * Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-protocol-validator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-communication-protocol-validator (defskill :skill-communication-protocol-validator
:priority 95 :priority 95
:trigger (lambda (ctx) (member (getf (getf ctx :payload) :sensor) '(:protocol-received))) :trigger (lambda (ctx) (member (getf (getf ctx :payload) :sensor) '(:protocol-received)))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: scribe-skill :ID: scribe-skill
:CREATED: [2026-04-13 Mon 18:40] :CREATED: [2026-04-13 Mon 18:40]
@@ -41,14 +42,14 @@ The Scribe reacts to the `:heartbeat` sensor. It maintains a state file (`scribe
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** State: Checkpoint Management ** State: Checkpoint Management
We track the last processed universal time to avoid redundant distillation. We track the last processed universal time to avoid redundant distillation.
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *scribe-last-checkpoint* 0 (defvar *scribe-last-checkpoint* 0
"The universal-time of the last successful distillation run.") "The universal-time of the last successful distillation run.")
@@ -70,7 +71,7 @@ We track the last processed universal time to avoid redundant distillation.
** Filtering: Privacy & Relevance ** Filtering: Privacy & Relevance
The Scribe only cares about non-personal, non-distilled headlines. The Scribe only cares about non-personal, non-distilled headlines.
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun scribe-get-distillable-nodes () (defun scribe-get-distillable-nodes ()
"Returns a list of org-objects from the daily/ folder that require distillation." "Returns a list of org-objects from the daily/ folder that require distillation."
(let ((results nil)) (let ((results nil))
@@ -91,7 +92,7 @@ The Scribe only cares about non-personal, non-distilled headlines.
** Probabilistic: Extraction Prompt ** Probabilistic: Extraction Prompt
The LLM is tasked with identifying atomic concepts within the raw text. The LLM is tasked with identifying atomic concepts within the raw text.
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun probabilistic-skill-scribe (context) (defun probabilistic-skill-scribe (context)
"Generates the extraction prompt for the Scribe." "Generates the extraction prompt for the Scribe."
(let* ((payload (getf context :payload)) (let* ((payload (getf context :payload))
@@ -122,7 +123,7 @@ TEXT:
** Deterministic: Note Committal ** Deterministic: Note Committal
The deterministic gate receives the list of proposed notes and writes them to the filesystem. The deterministic gate receives the list of proposed notes and writes them to the filesystem.
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun scribe-commit-notes (proposals) (defun scribe-commit-notes (proposals)
"Writes proposed atomic notes to the notes/ directory. Appends if the note exists." "Writes proposed atomic notes to the notes/ directory. Appends if the note exists."
(let ((notes-dir (uiop:merge-pathnames* "notes/" (asdf:system-source-directory :opencortex)))) (let ((notes-dir (uiop:merge-pathnames* "notes/" (asdf:system-source-directory :opencortex))))
@@ -159,7 +160,7 @@ The deterministic gate receives the list of proposed notes and writes them to th
#+end_src #+end_src
** Skill Registration ** Skill Registration
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-scribe (defskill :skill-scribe
:priority 50 :priority 50
:trigger (lambda (ctx) :trigger (lambda (ctx)
@@ -174,6 +175,6 @@ The deterministic gate receives the list of proposed notes and writes them to th
#+end_src #+end_src
** Initialization ** Initialization
#+begin_src lisp :tangle (expand-file-name "org-skill-scribe.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(scribe-load-state) (scribe-load-state)
#+end_src #+end_src

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: self-edit-001 :ID: self-edit-001
:END: :END:
@@ -14,14 +15,14 @@ The *Self-Edit Agent* enables the agent to modify its own code and files with sa
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Package Context ** Package Context
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
** Deterministic Paren Repair ** Deterministic Paren Repair
Fast paren balancing for syntax errors. Fast paren balancing for syntax errors.
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun self-edit-count-char (char string) (defun self-edit-count-char (char string)
"Counts occurrences of CHAR in STRING." "Counts occurrences of CHAR in STRING."
(loop for c across string count (char= c char))) (loop for c across string count (char= c char)))
@@ -41,7 +42,7 @@ Fast paren balancing for syntax errors.
** Parse Target Location ** Parse Target Location
Extract file and line info from error context. Extract file and line info from error context.
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun self-edit-parse-location (context) (defun self-edit-parse-location (context)
"Extracts file and line from error context payload." "Extracts file and line from error context payload."
(let* ((payload (getf context :payload)) (let* ((payload (getf context :payload))
@@ -58,7 +59,7 @@ Extract file and line info from error context.
** Apply Surgical Edit ** Apply Surgical Edit
Apply a find/replace to a file with rollback on failure. Apply a find/replace to a file with rollback on failure.
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun self-edit-apply (target-file old-code new-code) (defun self-edit-apply (target-file old-code new-code)
"Applies surgical edit to TARGET-FILE: replace OLD-CODE with NEW-CODE. "Applies surgical edit to TARGET-FILE: replace OLD-CODE with NEW-CODE.
Returns list with :status and :message keys." Returns list with :status and :message keys."
@@ -90,7 +91,7 @@ Returns list with :status and :message keys."
#+end_src #+end_src
** Cognitive Tool: Edit File ** Cognitive Tool: Edit File
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(def-cognitive-tool :self-edit (def-cognitive-tool :self-edit
"Applies a surgical code modification to a file with automatic rollback on failure." "Applies a surgical code modification to a file with automatic rollback on failure."
((:file :type :string :description "Path to the target file") ((:file :type :string :description "Path to the target file")
@@ -106,7 +107,7 @@ Returns list with :status and :message keys."
** Skill Definition ** Skill Definition
Hooks into syntax-error events for self-repair. Hooks into syntax-error events for self-repair.
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-self-edit (defskill :skill-self-edit
:priority 95 :priority 95
:trigger (lambda (ctx) :trigger (lambda (ctx)
@@ -146,7 +147,7 @@ Provide a fixed version of the code as a lisp form.")
#+end_src #+end_src
** Tool: Quick Paren Fix ** Tool: Quick Paren Fix
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(def-cognitive-tool :balance-parens (def-cognitive-tool :balance-parens
"Balances parentheses in a code string." "Balances parentheses in a code string."
((:code :type :string :description "The code to balance")) ((:code :type :string :description "The code to balance"))
@@ -164,7 +165,7 @@ Provide a fixed version of the code as a lisp form.")
** Skill Hot-Reload ** Skill Hot-Reload
Swap compiled skill files without breaking active sockets. Swap compiled skill files without breaking active sockets.
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defvar *self-edit-skills-backup* nil (defvar *self-edit-skills-backup* nil
"Backup of skill registry before hot-reload.") "Backup of skill registry before hot-reload.")
@@ -217,7 +218,7 @@ Swap compiled skill files without breaking active sockets.
** Cognitive Tool: Reload Skill ** Cognitive Tool: Reload Skill
#+begin_src lisp :tangle (expand-file-name "org-skill-self-edit.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(def-cognitive-tool :reload-skill (def-cognitive-tool :reload-skill
"Hot-reloads a skill from its compiled source file without restarting the system." "Hot-reloads a skill from its compiled source file without restarting the system."
((:skill-name :type :string :description "Name of the skill to reload (e.g. :skill-engineering-standards)") ((:skill-name :type :string :description "Name of the skill to reload (e.g. :skill-engineering-standards)")

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-self-fix.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: 65891ce2-a465-49e6-a0c1-be13d3288d55 :ID: 65891ce2-a465-49e6-a0c1-be13d3288d55
:CREATED: [2026-03-30 Mon 21:16] :CREATED: [2026-03-30 Mon 21:16]
@@ -15,11 +16,11 @@ This skill enables self-editing by applying surgical fixes to files (including s
* Phase D: Build (Implementation) * Phase D: Build (Implementation)
** Repair Logic ** Repair Logic
#+begin_src lisp :tangle (expand-file-name "org-skill-self-fix.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
#+end_src #+end_src
#+begin_src lisp :tangle (expand-file-name "org-skill-self-fix.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defun self-fix-apply (action context) (defun self-fix-apply (action context)
"Applies a surgical code fix and reloads the modified skill." "Applies a surgical code fix and reloads the modified skill."
(declare (ignore context)) (declare (ignore context))
@@ -66,7 +67,7 @@ This skill enables self-editing by applying surgical fixes to files (including s
#+end_src #+end_src
** Cognitive Tool ** Cognitive Tool
#+begin_src lisp :tangle (expand-file-name "org-skill-self-fix.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(def-cognitive-tool :repair-file (def-cognitive-tool :repair-file
"Applies a surgical code modification to a file and reloads the skill if applicable." "Applies a surgical code modification to a file and reloads the skill if applicable."
((:file :type :string :description "Path to the target file") ((:file :type :string :description "Path to the target file")
@@ -79,7 +80,7 @@ This skill enables self-editing by applying surgical fixes to files (including s
#+end_src #+end_src
** Skill Definition ** Skill Definition
#+begin_src lisp :tangle (expand-file-name "org-skill-self-fix.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defskill :skill-self-fix (defskill :skill-self-fix
:priority 95 :priority 95
:trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :repair-request)) :trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :repair-request))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-shell-actuator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: shell-actuator-skill :ID: shell-actuator-skill
:CREATED: [2026-04-12 Sun] :CREATED: [2026-04-12 Sun]
@@ -11,7 +12,7 @@ The *Shell Actuator* provides a controlled interface for the OpenCortex to execu
* Implementation * Implementation
#+begin_src lisp :tangle (expand-file-name "org-skill-shell-actuator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(defparameter *allowed-commands* '("ls" "git" "rg" "grep" "date" "echo" "cat" "node" "python3" "sbcl")) (defparameter *allowed-commands* '("ls" "git" "rg" "grep" "date" "echo" "cat" "node" "python3" "sbcl"))

View File

@@ -1,3 +1,4 @@
#+PROPERTY: header-args:lisp :tangle (expand-file-name "org-skill-tool-permissions.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills"))
:PROPERTIES: :PROPERTIES:
:ID: tool-permissions-skill-001 :ID: tool-permissions-skill-001
:CREATED: [2026-04-23 Thu] :CREATED: [2026-04-23 Thu]
@@ -27,7 +28,7 @@ Also provides vector embeddings via Ollama or llama.cpp.
* Implementation * Implementation
Tool permissions and embedding generation via multiple providers. Tool permissions and embedding generation via multiple providers.
#+begin_src lisp :tangle (expand-file-name "org-skill-tool-permissions.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/skills")) #+begin_src lisp
(in-package :opencortex) (in-package :opencortex)
(defvar *tool-permissions* (make-hash-table :test 'equal) (defvar *tool-permissions* (make-hash-table :test 'equal)