build: dynamically tangle to INSTALL_DIR without copying .org files
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s
- Updated all 150+ :tangle headers across harness/ and skills/ to use elisp (expand-file-name) to target INSTALL_DIR dynamically. - Cleaned up environment/ directory depth by moving memory-image.lisp to state/. - Moved test scripts to tests/ and deleted redundant chat scripts.
This commit is contained in:
@@ -35,7 +35,7 @@ Example feedback chain:
|
||||
|
||||
* Package Context
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
@@ -43,7 +43,7 @@ Example feedback chain:
|
||||
|
||||
** Actuator Registry Variables
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *default-actuator* :cli
|
||||
"The actuator used when no explicit target is specified.
|
||||
Override with DEFAULT_ACTUATOR environment variable.")
|
||||
@@ -55,7 +55,7 @@ Example feedback chain:
|
||||
|
||||
** initialize-actuators: System Bootstrap
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun initialize-actuators ()
|
||||
"Load actuator configuration from environment and register core actuators.
|
||||
|
||||
@@ -102,7 +102,7 @@ Example feedback chain:
|
||||
|
||||
** dispatch-action: The Router
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun dispatch-action (action context)
|
||||
"Route an approved action to its registered actuator.
|
||||
|
||||
@@ -149,7 +149,7 @@ Example feedback chain:
|
||||
|
||||
** execute-system-action: Internal Commands
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun execute-system-action (action context)
|
||||
"Execute internal harness commands.
|
||||
|
||||
@@ -198,7 +198,7 @@ Example feedback chain:
|
||||
|
||||
** execute-tool-action: Cognitive Tool Execution
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun execute-tool-action (action context)
|
||||
"Execute a registered cognitive tool.
|
||||
|
||||
@@ -267,7 +267,7 @@ Example feedback chain:
|
||||
|
||||
** format-tool-result: Human-Readable Output
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun format-tool-result (tool-name result)
|
||||
"Format a tool result for human-readable display.
|
||||
|
||||
@@ -295,7 +295,7 @@ Example feedback chain:
|
||||
|
||||
** act-gate: Final Pipeline Stage
|
||||
|
||||
#+begin_src lisp :tangle ./act.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "act.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun act-gate (signal)
|
||||
"Final stage of the metabolic pipeline: Actuation.
|
||||
|
||||
@@ -392,7 +392,7 @@ Example feedback chain:
|
||||
These tests verify the Act pipeline. Run with:
|
||||
~(fiveam:run! 'pipeline-act-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/pipeline-act-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/pipeline-act-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-pipeline-act-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:pipeline-act-suite))
|
||||
|
||||
@@ -10,7 +10,7 @@ The ~communication.lisp~ module defines the low-level transport and framing logi
|
||||
|
||||
* Implementation (communication.lisp)
|
||||
|
||||
#+begin_src lisp :tangle ./communication.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
|
||||
(defun proto-get (plist key)
|
||||
@@ -21,7 +21,7 @@ The ~communication.lisp~ module defines the low-level transport and framing logi
|
||||
(or (getf plist up) (getf plist dn))))
|
||||
#+end_src
|
||||
|
||||
#+begin_src lisp :tangle ./communication.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
|
||||
(defvar *actuator-registry* (make-hash-table :test 'equalp)
|
||||
@@ -78,7 +78,7 @@ The ~communication.lisp~ module defines the low-level transport and framing logi
|
||||
** Structural Validation (communication-validator.lisp)
|
||||
The validator ensures that incoming messages adhere to the strict property list schema of the communication protocol.
|
||||
|
||||
#+begin_src lisp :tangle ./communication-validator.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "communication-validator.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
|
||||
(defun validate-communication-protocol-schema (msg)
|
||||
@@ -128,7 +128,7 @@ The validator ensures that incoming messages adhere to the strict property list
|
||||
** Message Framing (communication.lisp)
|
||||
Frames a message with a hex length prefix and ensures all data is serializable.
|
||||
|
||||
#+begin_src lisp :tangle ./communication.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "communication.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun sanitize-protocol-message (msg)
|
||||
"Recursively strips non-serializable objects from a protocol plist."
|
||||
(if (and msg (listp msg))
|
||||
@@ -153,7 +153,7 @@ Frames a message with a hex length prefix and ensures all data is serializable.
|
||||
These tests verify the communication protocol functions. Run with:
|
||||
~(fiveam:run! 'communication-protocol-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./communication-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "communication-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-communication-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:communication-protocol-suite))
|
||||
|
||||
@@ -37,14 +37,14 @@ The ~context.lisp~ module provides the deterministic functional layer for queryi
|
||||
** Package Context
|
||||
We begin by ensuring we are executing within the correct isolated package namespace.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-query-store (&key tag todo-state type)
|
||||
"Filters the Memory based on tags, todo states, or types."
|
||||
(let ((results nil))
|
||||
@@ -62,7 +62,7 @@ A generalized filter for the Memory. This function allows skills to perform high
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-get-active-projects ()
|
||||
"Returns headlines tagged as 'project' that are not yet marked DONE."
|
||||
(remove-if (lambda (obj) (equal (getf (org-object-attributes obj) :TODO-STATE) "DONE"))
|
||||
@@ -72,7 +72,7 @@ Identifies headlines tagged with ~project~ that have not yet reached a terminal
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-get-recent-completed-tasks ()
|
||||
"Retrieves recently finished tasks from the store."
|
||||
(context-query-store :todo-state "DONE" :type :HEADLINE))
|
||||
@@ -81,7 +81,7 @@ Retrieves a list of tasks that have reached the terminal ~DONE~ state. This is u
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-list-all-skills ()
|
||||
"Provides a sorted overview of currently loaded system capabilities."
|
||||
(let ((results nil))
|
||||
@@ -95,7 +95,7 @@ Provides a sorted list of all currently loaded skills. In a "Self-Writing" envir
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-get-skill-source (skill-name)
|
||||
"Reads the raw literate source of a specific skill for inspection."
|
||||
(let* ((filename (format nil "~a.org" skill-name))
|
||||
@@ -108,7 +108,7 @@ Reads the raw literate Org source of a specific skill. This is a foundational ca
|
||||
** 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`.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-get-system-logs (&optional limit)
|
||||
"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)))
|
||||
@@ -128,7 +128,7 @@ It implements the following deterministic logic:
|
||||
|
||||
The semantic threshold is externalized to `CONTEXT_SEMANTIC_THRESHOLD`.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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."
|
||||
(let* ((id (org-object-id obj))
|
||||
@@ -177,7 +177,7 @@ The semantic threshold is externalized to `CONTEXT_SEMANTIC_THRESHOLD`.
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-resolve-path (path-string)
|
||||
"Expands environment variables and strips literal quotes from a path string."
|
||||
(let ((path (if (stringp path-string)
|
||||
@@ -196,7 +196,7 @@ A utility function that expands environment variables (like ~$HOME~ or ~$MEMEX_R
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./context.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "context.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun context-assemble-global-awareness (&optional signal)
|
||||
"Produces a high-level skeletal outline of the current Memory for the LLM."
|
||||
(let* ((foveal-id (or (getf signal :foveal-focus)
|
||||
@@ -216,7 +216,7 @@ The primary entry point for context generation. This function identifies active
|
||||
Following the Engineering Standards, the peripheral vision extraction and rendering logic must be empirically verified.
|
||||
|
||||
** Test Suite Context
|
||||
#+begin_src lisp :tangle ./tests/peripheral-vision-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/peripheral-vision-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-peripheral-vision-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:vision-suite))
|
||||
@@ -230,7 +230,7 @@ Following the Engineering Standards, the peripheral vision extraction and render
|
||||
** Foveal Rendering Test
|
||||
Verify that the foveal target is rendered with content, while siblings are skeletal.
|
||||
|
||||
#+begin_src lisp :tangle ./tests/peripheral-vision-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/peripheral-vision-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(test test-foveal-rendering
|
||||
"Verify that the foveal target is rendered with content, while siblings are skeletal."
|
||||
(clrhash opencortex::*memory*)
|
||||
@@ -250,7 +250,7 @@ Verify that the foveal target is rendered with content, while siblings are skele
|
||||
** Awareness Budget Test
|
||||
Verify that context-assemble-global-awareness handles multiple projects correctly.
|
||||
|
||||
#+begin_src lisp :tangle ./tests/peripheral-vision-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/peripheral-vision-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(test test-awareness-budget
|
||||
"Verify that context-assemble-global-awareness handles multiple projects."
|
||||
(clrhash opencortex::*memory*)
|
||||
|
||||
@@ -67,7 +67,7 @@ The loop operates in a multi-threaded environment:
|
||||
|
||||
* Package and Thread-Safe Variables
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
|
||||
(defvar *interrupt-flag* nil
|
||||
@@ -90,7 +90,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.
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun process-signal (signal)
|
||||
"The entry point to the Metabolic Pipeline: Perceive -> Reason -> Act.
|
||||
|
||||
@@ -184,7 +184,7 @@ The heartbeat thread ensures the agent remains alive even without external input
|
||||
|
||||
** Heartbeat Configuration Variables
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *auto-save-interval* 300
|
||||
"Interval in seconds between automatic memory saves.
|
||||
Defaults to 300 seconds (5 minutes). Set via MEMORY_AUTO_SAVE_INTERVAL env var.")
|
||||
@@ -195,7 +195,7 @@ The heartbeat thread ensures the agent remains alive even without external input
|
||||
|
||||
** start-heartbeat: The Pulsing Heart
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun start-heartbeat ()
|
||||
"Starts the background heartbeat thread.
|
||||
|
||||
@@ -241,7 +241,7 @@ The heartbeat thread ensures the agent remains alive even without external input
|
||||
|
||||
** Shutdown Configuration
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *shutdown-save-enabled* t
|
||||
"When T, save memory to disk on graceful shutdown.
|
||||
Disable for testing or when memory persistence is handled externally.")
|
||||
@@ -258,7 +258,7 @@ The main function orchestrates system startup:
|
||||
5. Register SIGINT handler for graceful Ctrl+C shutdown
|
||||
6. Enter idle loop (sleeping in 1-hour increments)
|
||||
|
||||
#+begin_src lisp :tangle ./loop.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "loop.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun main ()
|
||||
"Entry point for OpenCortex. Initializes the system and enters idle loop.
|
||||
|
||||
@@ -323,7 +323,7 @@ The main function orchestrates system startup:
|
||||
These tests verify the metabolic loop and error recovery. Run with:
|
||||
~(fiveam:run! 'immune-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/immune-system-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/immune-system-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-immune-system-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:immune-suite))
|
||||
|
||||
@@ -79,7 +79,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
|
||||
|
||||
** Main Harness System
|
||||
|
||||
#+begin_src lisp :tangle ../opencortex.asd
|
||||
#+begin_src lisp :tangle (expand-file-name "../opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defsystem :opencortex
|
||||
:name "opencortex"
|
||||
:author "Amr"
|
||||
@@ -119,7 +119,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
|
||||
|
||||
** Test System
|
||||
|
||||
#+begin_src lisp :tangle ../opencortex.asd
|
||||
#+begin_src lisp :tangle (expand-file-name "../opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defsystem :opencortex/tests
|
||||
:depends-on (:opencortex ; The harness we're testing
|
||||
:fiveam) ; Testing framework
|
||||
@@ -154,7 +154,7 @@ The testing system (~:opencortex/tests~) is separate from the production system
|
||||
|
||||
** TUI Client System
|
||||
|
||||
#+begin_src lisp :tangle ../opencortex.asd
|
||||
#+begin_src lisp :tangle (expand-file-name "../opencortex.asd" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defsystem :opencortex/tui
|
||||
:depends-on (:opencortex ; The daemon we're connecting to
|
||||
:croatoan ; Terminal UI library
|
||||
|
||||
@@ -31,14 +31,14 @@ flowchart TD
|
||||
#+end_src
|
||||
|
||||
** Package Context
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** The Object Repository
|
||||
The `*memory*` is the global hash table that holds every Org element by its unique ID. This is the "live RAM" of the agent's memory.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *memory* (make-hash-table :test 'equal))
|
||||
|
||||
(defvar *history-store* (make-hash-table :test 'equal)
|
||||
@@ -48,7 +48,7 @@ The `*memory*` is the global hash table that holds every Org element by its uniq
|
||||
** The Data Structure (org-object)
|
||||
Every element in the Memex (headlines, paragraphs, etc.) is represented by an `org-object` structure. It contains both semantic metadata (attributes, content) and structural metadata (parent/child pointers, Merkle hashes).
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defstruct org-object
|
||||
id type attributes content vector parent-id children version last-sync hash)
|
||||
|
||||
@@ -60,7 +60,7 @@ Every element in the Memex (headlines, paragraphs, etc.) is represented by an `o
|
||||
** Merkle Tree Integrity (compute-merkle-hash)
|
||||
The `compute-merkle-hash` function ensures the cryptographic integrity of the knowledge graph. A node's hash depends on its own properties and the hashes of all its children. This creates a recursive fingerprint where any change to a single note propagates up to the root hash.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun compute-merkle-hash (id type attributes content child-hashes)
|
||||
"Computes a SHA-256 Merkle hash for a node based on its core properties and children's hashes."
|
||||
(let* ((alist (loop for (k v) on attributes by #'cddr collect (cons k v)))
|
||||
@@ -77,7 +77,7 @@ The `compute-merkle-hash` function ensures the cryptographic integrity of the kn
|
||||
** Ingesting the AST (ingest-ast)
|
||||
The `ingest-ast` function is the primary bridge between the external world (Emacs/JSON) and the internal Lisp machine. It recursively parses an Org-mode Abstract Syntax Tree (AST) into `org-object` structures and registers them in the store.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun ingest-ast (ast &optional parent-id)
|
||||
"Parses an Org AST into the recursive Lisp Memory with Merkle hashing."
|
||||
(let* ((type (getf ast :type))
|
||||
@@ -116,7 +116,7 @@ The `ingest-ast` function is the primary bridge between the external world (Emac
|
||||
** Memory Snapshots (snapshot-memory)
|
||||
Because objects are stored immutably in the `*history-store*`, a snapshot is a lightweight shallow copy of the active `*memory*` pointers. The system maintains a rolling buffer of 20 snapshots, allowing for near-instant, zero-cost rollback.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *object-store-snapshots* nil)
|
||||
|
||||
(defun copy-hash-table (hash-table)
|
||||
@@ -138,7 +138,7 @@ Because objects are stored immutably in the `*history-store*`, a snapshot is a l
|
||||
** Memory Rollback (rollback-memory)
|
||||
Restores the state of the Memex from one of the previous snapshots.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun rollback-memory (&optional (index 0))
|
||||
"Restores the Memory to a previously captured snapshot using immutable history pointers."
|
||||
(let ((snapshot (nth index *object-store-snapshots*)))
|
||||
@@ -153,7 +153,7 @@ Restores the state of the Memex from one of the previous snapshots.
|
||||
These tests verify the Memory system. Run with:
|
||||
~(fiveam:run! 'memory-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/memory-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/memory-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-memory-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:memory-suite))
|
||||
@@ -206,7 +206,7 @@ These tests verify the Memory system. Run with:
|
||||
** 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.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *memory-snapshot-path* nil
|
||||
"Path to the memory snapshot file. Set from MEMORY_SNAPSHOT_PATH env or default.")
|
||||
|
||||
@@ -261,7 +261,7 @@ Support for vector embeddings via Ollama and semantic search with cosine similar
|
||||
|
||||
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 ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *embedding-cache* (make-hash-table :test 'equal)
|
||||
"Cache for embeddings to avoid redundant API calls.")
|
||||
|
||||
@@ -321,7 +321,7 @@ Returns up to LIMIT objects with similarity >= MIN-SIMILARITY, sorted by similar
|
||||
** Cognitive Tool: Generate Embeddings
|
||||
Provided for the Probabilistic Engine to invoke embedding generation on demand.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(def-cognitive-tool :generate-embeddings
|
||||
"Generates vector embeddings for given text via the configured embedding backend (Ollama)."
|
||||
((:texts :type :list :description "List of text strings to embed."))
|
||||
@@ -345,7 +345,7 @@ Provided for the Probabilistic Engine to invoke embedding generation on demand.
|
||||
** Lookup Utilities
|
||||
Basic functions for retrieving objects by ID or type.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun org-id-new ()
|
||||
"Generates a new UUID string for Org-mode identification."
|
||||
(string-downcase (format nil "~a" (uuid:make-v4-uuid))))
|
||||
@@ -374,7 +374,7 @@ Basic functions for retrieving objects by ID or type.
|
||||
** Structural Helpers
|
||||
Utility functions for AST traversal and path resolution.
|
||||
|
||||
#+begin_src lisp :tangle ./memory.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "memory.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun find-headline-missing-id (ast)
|
||||
"Traverses an AST to find headlines that lack an :ID: property."
|
||||
(when (listp ast)
|
||||
@@ -390,7 +390,7 @@ Utility functions for AST traversal and path resolution.
|
||||
* Phase E: Chaos (Verification)
|
||||
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 ./tests/memory-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/memory-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-memory-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:memory-suite))
|
||||
|
||||
@@ -9,7 +9,7 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness. It s
|
||||
|
||||
** Public API Export
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex
|
||||
(:use :cl)
|
||||
(:export
|
||||
@@ -131,13 +131,13 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness. It s
|
||||
|
||||
* Package Implementation
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** Robust Plist Accessor
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun proto-get (plist key)
|
||||
"Robustly retrieves a value from a plist, checking both uppercase and lowercase keyword versions."
|
||||
(let* ((s (string key))
|
||||
@@ -150,7 +150,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.
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *system-logs* nil)
|
||||
(defvar *logs-lock* (bordeaux-threads:make-lock "harness-logs-lock"))
|
||||
(defvar *max-log-history* 100)
|
||||
@@ -158,14 +158,14 @@ The harness maintains a thread-safe circular log buffer to provide context for d
|
||||
|
||||
** Skills Registry
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *skills-registry* (make-hash-table :test 'equal)
|
||||
"Global registry of all loaded skills.")
|
||||
#+end_src
|
||||
|
||||
** Skill Telemetry State
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *skill-telemetry* (make-hash-table :test 'equal))
|
||||
(defvar *telemetry-lock* (bordeaux-threads:make-lock "harness-telemetry-lock"))
|
||||
#+end_src
|
||||
@@ -174,7 +174,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.
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun harness-track-telemetry (skill-name duration status)
|
||||
"Updates performance metrics for a specific skill. Status should be :success or :rejected."
|
||||
(when skill-name
|
||||
@@ -190,7 +190,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).
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *cognitive-tools* (make-hash-table :test 'equal))
|
||||
|
||||
(defstruct cognitive-tool
|
||||
@@ -214,7 +214,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.
|
||||
|
||||
#+begin_src lisp :tangle ./package.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "package.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun harness-log (msg &rest args)
|
||||
"Centralized logging for the harness."
|
||||
(let ((formatted-msg (apply #'format nil msg args)))
|
||||
|
||||
@@ -53,7 +53,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
|
||||
* Package Context
|
||||
|
||||
#+begin_src lisp :tangle ./perceive.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
@@ -61,7 +61,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
|
||||
** Async Sensor Registry
|
||||
|
||||
#+begin_src lisp :tangle ./perceive.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *async-sensors* '(:chat-message :delegation :user-command)
|
||||
"Sensors that are processed in dedicated threads.
|
||||
|
||||
@@ -74,7 +74,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
|
||||
** Foveal Focus State
|
||||
|
||||
#+begin_src lisp :tangle ./perceive.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *foveal-focus-id* nil
|
||||
"The Org ID of the node the user is currently interacting with.
|
||||
|
||||
@@ -89,7 +89,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
|
||||
** inject-stimulus: Entry Point
|
||||
|
||||
#+begin_src lisp :tangle ./perceive.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun inject-stimulus (raw-message &key stream (depth 0))
|
||||
"Inject a raw message into the signal processing pipeline.
|
||||
|
||||
@@ -146,7 +146,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
|
||||
** perceive-gate: Signal Normalization
|
||||
|
||||
#+begin_src lisp :tangle ./perceive.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "perceive.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun perceive-gate (signal)
|
||||
"Stage 1 of the metabolic pipeline: Normalize sensory input.
|
||||
|
||||
@@ -226,7 +226,7 @@ Other sensors (heartbeats, interrupts) are processed synchronously to maintain o
|
||||
These tests verify the Perceive pipeline. Run with:
|
||||
~(fiveam:run! 'pipeline-perceive-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/pipeline-perceive-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/pipeline-perceive-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-pipeline-perceive-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:pipeline-perceive-suite))
|
||||
|
||||
@@ -33,7 +33,7 @@ This means the reasoning pipeline can generate, modify, and execute its own comm
|
||||
|
||||
* Package Context
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
@@ -43,7 +43,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
|
||||
|
||||
** Backend Registry Variables
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defvar *probabilistic-backends* (make-hash-table :test 'equal)
|
||||
"Registry mapping provider keywords (:openrouter, :ollama) to their calling functions.")
|
||||
|
||||
@@ -60,7 +60,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
|
||||
|
||||
** register-probabilistic-backend: Backend Registration
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun register-probabilistic-backend (name fn)
|
||||
"Register a neural provider backend.
|
||||
|
||||
@@ -79,7 +79,7 @@ The probabilistic engine is responsible for all neural/LLM operations. It mainta
|
||||
|
||||
** probabilistic-call: Cascade Dispatch
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun probabilistic-call (prompt &key
|
||||
(system-prompt "You are the Probabilistic engine.")
|
||||
(cascade nil)
|
||||
@@ -129,7 +129,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
|
||||
|
||||
** strip-markdown: Clean LLM Output
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun strip-markdown (text)
|
||||
"Strip markdown formatting from LLM output.
|
||||
|
||||
@@ -152,7 +152,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
|
||||
|
||||
** normalize-plist-keywords: Fix LLM Keyword Output
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun normalize-plist-keywords (plist)
|
||||
"Normalize all keys in a plist to keywords.
|
||||
|
||||
@@ -176,7 +176,7 @@ The `think` function is the heart of the probabilistic engine. It constructs a p
|
||||
|
||||
** think: Generate Action Proposal
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun think (context)
|
||||
"Generate a Lisp action proposal based on current context.
|
||||
|
||||
@@ -320,7 +320,7 @@ The deterministic engine runs all registered skills' verification functions. Thi
|
||||
|
||||
** deterministic-verify: Skill Chain Verification
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun deterministic-verify (proposed-action context)
|
||||
"Run all skill deterministic gates on a proposed action.
|
||||
|
||||
@@ -391,7 +391,7 @@ The deterministic engine runs all registered skills' verification functions. Thi
|
||||
|
||||
** reason-gate: The Stage Function
|
||||
|
||||
#+begin_src lisp :tangle ./reason.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "reason.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun reason-gate (signal)
|
||||
"Stage 2 of the metabolic pipeline: Reason.
|
||||
|
||||
@@ -448,7 +448,7 @@ The deterministic engine runs all registered skills' verification functions. Thi
|
||||
These tests verify the Reason (cognitive) pipeline. Run with:
|
||||
~(fiveam:run! 'pipeline-reason-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/pipeline-reason-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/pipeline-reason-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-pipeline-reason-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:pipeline-reason-suite))
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
The ~setup.org~ file defines the automated installation and initialization sequence for the OpenCortex.
|
||||
|
||||
** The Installer Script (opencortex.sh)
|
||||
#+begin_src bash :tangle ../opencortex.sh
|
||||
#+begin_src bash :tangle (expand-file-name "../opencortex.sh" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
@@ -244,7 +244,7 @@ esac
|
||||
#+end_src
|
||||
|
||||
** Metabolic Docker Infrastructure (Dockerfile)
|
||||
#+begin_src dockerfile :tangle ../infrastructure/docker/Dockerfile
|
||||
#+begin_src dockerfile :tangle (expand-file-name "../infrastructure/docker/Dockerfile" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -61,7 +61,7 @@ flowchart LR
|
||||
|
||||
** Global Skill Registry
|
||||
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :opencortex)
|
||||
|
||||
(defun COSINE-SIMILARITY (v1 v2)
|
||||
@@ -137,7 +137,7 @@ flowchart LR
|
||||
#+end_src
|
||||
|
||||
** Skill File Analysis (parse-skill-metadata)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun parse-skill-metadata (filepath)
|
||||
"Extracts ID and DEPENDS_ON tags from org file."
|
||||
(let ((dependencies nil)
|
||||
@@ -160,7 +160,7 @@ flowchart LR
|
||||
#+end_src
|
||||
|
||||
** Dependency Resolution (topological-sort-skills)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun topological-sort-skills (skills-dir)
|
||||
"Returns a list of skill filepaths sorted by dependency (dependencies first)."
|
||||
(let ((files (uiop:directory-files skills-dir "org-skill-*.org"))
|
||||
@@ -204,7 +204,7 @@ flowchart LR
|
||||
#+end_src
|
||||
|
||||
** Jailed Loading (load-skill-from-org)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun validate-lisp-syntax (code-string)
|
||||
"Checks if a string contains valid, readable Common Lisp forms.
|
||||
Delegates to the Lisp Validator skill when available; falls back to a basic
|
||||
@@ -224,7 +224,7 @@ reader check during early boot before the validator skill is loaded."
|
||||
(values nil (or (getf result :reason) "Lisp Validator rejected code.")))))
|
||||
|
||||
(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 (expand-file-name "directives" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) from an Org file.
|
||||
Only loads blocks that specify a .lisp tangle target, ignoring tests and examples."
|
||||
(let* ((skill-base-name (pathname-name filepath))
|
||||
(entry (or (gethash skill-base-name *skill-catalog*) (make-skill-entry :filename skill-base-name))))
|
||||
@@ -243,12 +243,12 @@ Only loads blocks that specify a .lisp tangle target, ignoring tests and example
|
||||
(let ((clean-line (string-trim '(#\Space #\Tab #\Return) line)))
|
||||
(cond ((uiop:string-prefix-p "#+begin_src lisp" (string-downcase clean-line))
|
||||
(setf in-lisp-block t)
|
||||
;; Only collect blocks with a :tangle directive pointing to a
|
||||
;; Only collect blocks with a :tangle (expand-file-name "directive" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) pointing to a
|
||||
;; runtime .lisp file (exclude tests and :tangle no)
|
||||
(let ((tl (string-downcase clean-line)))
|
||||
(setf collect-this-block
|
||||
(and (search ":tangle" tl)
|
||||
(not (search ":tangle no" tl))
|
||||
(not (search ":tangle (expand-file-name "no"" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) tl))
|
||||
(search ".lisp" tl)
|
||||
(not (search "tests/" tl))
|
||||
(not (search "test/" tl))))))
|
||||
@@ -303,7 +303,7 @@ Only loads blocks that specify a .lisp tangle target, ignoring tests and example
|
||||
#+end_src
|
||||
|
||||
** Initializing All Skills (initialize-all-skills)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun initialize-all-skills ()
|
||||
"Scans the directory defined by SKILLS_DIR and hot-loads skills using topological order."
|
||||
(let* ((env-path (uiop:getenv "SKILLS_DIR"))
|
||||
@@ -349,7 +349,7 @@ Only loads blocks that specify a .lisp tangle target, ignoring tests and example
|
||||
#+end_src
|
||||
|
||||
** Toolbelt Prompt Generation (generate-tool-belt-prompt)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defun generate-tool-belt-prompt ()
|
||||
"Aggregates all registered cognitive tools into a descriptive prompt."
|
||||
(let ((output (format nil "AVAILABLE TOOLS:
|
||||
@@ -374,7 +374,7 @@ EXAMPLES:
|
||||
|
||||
** The Default Tool Belt
|
||||
*** The Eval Tool (Internal Inspection)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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"))
|
||||
:guard (lambda (args context)
|
||||
@@ -392,7 +392,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The Grep Tool (File Discovery)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(def-cognitive-tool :grep-search "Searches for a pattern in the project files."
|
||||
((:pattern :type :string :description "The regex pattern to search for")
|
||||
(:dir :type :string :description "Directory to search in (default is project root)"))
|
||||
@@ -404,7 +404,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The Shell Tool (Machine Actuation)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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"))
|
||||
:guard (lambda (args context)
|
||||
@@ -419,7 +419,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The Reload-Skill Tool (Hot Reload)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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"))
|
||||
:guard (lambda (args context)
|
||||
@@ -455,7 +455,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The File Read Tool (V 0.2.0 File I/O)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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"))
|
||||
:guard (lambda (args context)
|
||||
@@ -474,7 +474,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The File Write Tool (V 0.2.0 File I/O)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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")
|
||||
(:content :type :string :description "The content to write")
|
||||
@@ -506,7 +506,7 @@ EXAMPLES:
|
||||
#+end_src
|
||||
|
||||
*** The String Replace Tool (V 0.2.0 File I/O)
|
||||
#+begin_src lisp :tangle ./skills.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "skills.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(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")
|
||||
(:old :type :string :description "The substring to find and replace")
|
||||
@@ -541,7 +541,7 @@ EXAMPLES:
|
||||
These tests verify the Skill Engine and loader. Run with:
|
||||
~(fiveam:run! 'boot-suite)~
|
||||
|
||||
#+begin_src lisp :tangle ./tests/boot-sequence-tests.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tests/boot-sequence-tests.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(defpackage :opencortex-boot-tests
|
||||
(:use :cl :fiveam :opencortex)
|
||||
(:export #:boot-suite))
|
||||
@@ -583,7 +583,7 @@ These tests verify the Skill Engine and loader. Run with:
|
||||
"Verify that skills are loaded into their own packages."
|
||||
(let ((tmp-skill "/tmp/org-skill-jail-test.org"))
|
||||
(with-open-file (out tmp-skill :direction :output :if-exists :supersede)
|
||||
(format out ":PROPERTIES:~%:ID: jail-test-id~%:END:~%#+TITLE: Jail Test Skill~%#+begin_src lisp :tangle no~(defun jail-test-fn () t)~#+end_src"))
|
||||
(format out ":PROPERTIES:~%:ID: jail-test-id~%:END:~%#+TITLE: Jail Test Skill~%#+begin_src lisp :tangle (expand-file-name "no~(defun" (concat (or (getenv "INSTALL_DIR") ".") "/harness")) jail-test-fn () t)~#+end_src"))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(opencortex::load-skill-from-org tmp-skill)
|
||||
|
||||
@@ -10,7 +10,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.
|
||||
|
||||
* Implementation
|
||||
#+begin_src lisp :tangle ./tui-client.lisp
|
||||
#+begin_src lisp :tangle (expand-file-name "tui-client.lisp" (concat (or (getenv "INSTALL_DIR") ".") "/harness"))
|
||||
(in-package :cl-user)
|
||||
(defpackage :opencortex.tui
|
||||
(:use :cl :croatoan)
|
||||
|
||||
Reference in New Issue
Block a user