refactor(harness): centralize mandates, fix TUI reader structure, and enhance memory/perceive
This commit is contained in:
@@ -84,8 +84,8 @@
|
||||
(format t "==================================================~%")
|
||||
(handler-case
|
||||
(progn
|
||||
(when (fboundp 'doctor-run-all)
|
||||
(let ((result (doctor-run-all :auto-install nil)))
|
||||
(when (fboundp 'doctor-run-all)
|
||||
(let ((result (doctor-run-all)))
|
||||
(setf *health-check-ran* t)
|
||||
(if result
|
||||
(progn
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
(defvar *history-store* (make-hash-table :test 'equal)
|
||||
"Immutable Merkle-Tree versioning store mapping hashes to objects.")
|
||||
|
||||
(defun lookup-object (id)
|
||||
(gethash id *memory*))
|
||||
|
||||
(defstruct org-object
|
||||
id type attributes content vector parent-id children version last-sync hash)
|
||||
|
||||
(defmethod make-load-form ((obj org-object) &optional env)
|
||||
(make-load-form-saving-slots obj :environment env))
|
||||
|
||||
(defun copy-org-object (obj)
|
||||
(defun deep-copy-org-object (obj)
|
||||
(make-org-object :id (org-object-id obj)
|
||||
:type (org-object-type obj)
|
||||
:attributes (copy-list (org-object-attributes obj))
|
||||
@@ -71,7 +74,7 @@
|
||||
|
||||
(defun snapshot-memory ()
|
||||
(let ((snapshot (make-hash-table :test 'equal :size (hash-table-size *memory*))))
|
||||
(maphash (lambda (k v) (setf (gethash k snapshot) (copy-org-object v))) *memory*)
|
||||
(maphash (lambda (k v) (setf (gethash k snapshot) (deep-copy-org-object v))) *memory*)
|
||||
(push (list :timestamp (get-universal-time) :data snapshot) *object-store-snapshots*)
|
||||
(when (> (length *object-store-snapshots*) 20) (setf *object-store-snapshots* (subseq *object-store-snapshots* 0 20)))
|
||||
(harness-log "MEMORY - CoW Memory snapshot created.")))
|
||||
|
||||
@@ -21,6 +21,12 @@ The Memory module is the cognitive bedrock of the opencortex. It is not a databa
|
||||
"Immutable Merkle-Tree versioning store mapping hashes to objects.")
|
||||
#+end_src
|
||||
|
||||
** Object Lookup
|
||||
#+begin_src lisp
|
||||
(defun lookup-object (id)
|
||||
(gethash id *memory*))
|
||||
#+end_src
|
||||
|
||||
** The Data Structure (org-object)
|
||||
#+begin_src lisp
|
||||
(defstruct org-object
|
||||
@@ -29,7 +35,7 @@ The Memory module is the cognitive bedrock of the opencortex. It is not a databa
|
||||
(defmethod make-load-form ((obj org-object) &optional env)
|
||||
(make-load-form-saving-slots obj :environment env))
|
||||
|
||||
(defun copy-org-object (obj)
|
||||
(defun deep-copy-org-object (obj)
|
||||
(make-org-object :id (org-object-id obj)
|
||||
:type (org-object-type obj)
|
||||
:attributes (copy-list (org-object-attributes obj))
|
||||
@@ -99,7 +105,7 @@ The Memory module is the cognitive bedrock of the opencortex. It is not a databa
|
||||
|
||||
(defun snapshot-memory ()
|
||||
(let ((snapshot (make-hash-table :test 'equal :size (hash-table-size *memory*))))
|
||||
(maphash (lambda (k v) (setf (gethash k snapshot) (copy-org-object v))) *memory*)
|
||||
(maphash (lambda (k v) (setf (gethash k snapshot) (deep-copy-org-object v))) *memory*)
|
||||
(push (list :timestamp (get-universal-time) :data snapshot) *object-store-snapshots*)
|
||||
(when (> (length *object-store-snapshots*) 20) (setf *object-store-snapshots* (subseq *object-store-snapshots* 0 20)))
|
||||
(harness-log "MEMORY - CoW Memory snapshot created.")))
|
||||
|
||||
@@ -254,6 +254,7 @@
|
||||
;; --- Debugger Hook ---
|
||||
(setf *debugger-hook* (lambda (condition hook)
|
||||
"Friendly error handler - shows diagnostic message instead of raw debugger."
|
||||
(declare (ignore hook))
|
||||
(format t "~%")
|
||||
(format t "┌─────────────────────────────────────────────┐~%")
|
||||
(format t "│ ERROR: ~A~%" (type-of condition))
|
||||
|
||||
@@ -268,8 +268,10 @@ The ~package.lisp~ file defines the public API of the ~opencortex~ harness.
|
||||
(finish-output)))
|
||||
|
||||
;; --- Debugger Hook ---
|
||||
#+begin_src lisp :tangle package.lisp
|
||||
(setf *debugger-hook* (lambda (condition hook)
|
||||
"Friendly error handler - shows diagnostic message instead of raw debugger."
|
||||
(declare (ignore hook))
|
||||
(format t "~%")
|
||||
(format t "┌─────────────────────────────────────────────┐~%")
|
||||
(format t "│ ERROR: ~A~%" (type-of condition))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(in-package :opencortex)
|
||||
|
||||
(defvar *interrupt-flag* nil)
|
||||
(defvar *async-sensors* '(:chat-message :delegation :user-command)
|
||||
"Sensors that are processed in dedicated threads.")
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ The Perceive stage is the "sensory cortex" of OpenCortex. Its job is to take raw
|
||||
(in-package :opencortex)
|
||||
#+end_src
|
||||
|
||||
** Interrupt Handling
|
||||
#+begin_src lisp
|
||||
(defvar *interrupt-flag* nil)
|
||||
#+end_src
|
||||
|
||||
** Sensor Configuration
|
||||
#+begin_src lisp
|
||||
(defvar *async-sensors* '(:chat-message :delegation :user-command)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(in-package :cl-user)
|
||||
(defpackage :opencortex.tui
|
||||
(:use :cl :croatoan :usocket)
|
||||
(:use :cl :croatoan :usocket :bordeaux-threads)
|
||||
(:export :main))
|
||||
(in-package :opencortex.tui)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
(defvar *stream* nil)
|
||||
(defvar *chat-history* nil)
|
||||
(defvar *scroll-index* 0)
|
||||
(defvar *input-buffer* (make-array 0 :element-type 'char :fill-pointer 0 :adjustable t))
|
||||
(defvar *input-buffer* (make-array 0 :element-type 'character :fill-pointer 0 :adjustable t))
|
||||
(defvar *is-running* t)
|
||||
(defvar *queue-lock* (bt:make-lock))
|
||||
(defvar *incoming-msgs* nil)
|
||||
@@ -70,10 +70,10 @@
|
||||
(enqueue-msg "✓ Sent"))
|
||||
(error (c)
|
||||
(format t "Send error: ~a~%" c)
|
||||
(enqueue-msg "ERROR: Connection to daemon lost.")
|
||||
(setf *is-running* nil))))
|
||||
(when (string= cmd "/exit") (setf *is-running* nil))
|
||||
(when (string= cmd "/clear") (setf *chat-history* nil))))
|
||||
(enqueue-msg "ERROR: Connection to daemon lost.")
|
||||
(setf *is-running* nil))))
|
||||
(when (string= cmd "/exit") (setf *is-running* nil))
|
||||
(when (string= cmd "/clear") (setf *chat-history* nil))))
|
||||
|
||||
(defun start-background-reader (stream)
|
||||
"Starts a thread that reads framed messages from the daemon stream."
|
||||
@@ -98,12 +98,13 @@
|
||||
(getf payload :message))))
|
||||
(t
|
||||
(let ((text (or (getf payload :text) (format nil "~a" payload))))
|
||||
(enqueue-msg (format nil "⬇ ~a" text)))))))))
|
||||
(enqueue-msg (format nil "⬇ ~a" text))))))))))
|
||||
(error (c)
|
||||
(when *is-running*
|
||||
(enqueue-msg (format nil "ERROR: Connection lost (~a)" c))
|
||||
(setf *is-running* nil))))))
|
||||
:name "opencortex-tui-reader"))
|
||||
:name "opencortex-tui-reader")))
|
||||
)
|
||||
|
||||
(defun main ()
|
||||
(handler-case
|
||||
@@ -144,4 +145,4 @@
|
||||
(error (c)
|
||||
(format t "TUI Error: ~a~%" c)))
|
||||
(setf *is-running* nil)
|
||||
(when *socket* (ignore-errors (usocket:socket-close *socket*)))))
|
||||
(when *socket* (ignore-errors (usocket:socket-close *socket*))))
|
||||
|
||||
@@ -23,7 +23,7 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
(fiveam:test test-tui-connection-drop
|
||||
"Tier 2 Chaos: Verify that handle-return degrades gracefully when the daemon connection is lost."
|
||||
(let ((opencortex.tui::*incoming-msgs* nil)
|
||||
(opencortex.tui::*input-buffer* (make-array 5 :element-type 'char :initial-contents "hello" :fill-pointer 5 :adjustable t))
|
||||
(opencortex.tui::*input-buffer* (make-array 5 :element-type 'character :initial-contents "hello" :fill-pointer 5 :adjustable t))
|
||||
;; Create a closed stream to simulate connection drop
|
||||
(mock-stream (make-string-output-stream)))
|
||||
(close mock-stream)
|
||||
@@ -38,7 +38,7 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
#+begin_src lisp
|
||||
(in-package :cl-user)
|
||||
(defpackage :opencortex.tui
|
||||
(:use :cl :croatoan :usocket)
|
||||
(:use :cl :croatoan :usocket :bordeaux-threads)
|
||||
(:export :main))
|
||||
(in-package :opencortex.tui)
|
||||
#+end_src
|
||||
@@ -51,7 +51,7 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
(defvar *stream* nil)
|
||||
(defvar *chat-history* nil)
|
||||
(defvar *scroll-index* 0)
|
||||
(defvar *input-buffer* (make-array 0 :element-type 'char :fill-pointer 0 :adjustable t))
|
||||
(defvar *input-buffer* (make-array 0 :element-type 'character :fill-pointer 0 :adjustable t))
|
||||
(defvar *is-running* t)
|
||||
(defvar *queue-lock* (bt:make-lock))
|
||||
(defvar *incoming-msgs* nil)
|
||||
@@ -120,10 +120,10 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
(enqueue-msg "✓ Sent"))
|
||||
(error (c)
|
||||
(format t "Send error: ~a~%" c)
|
||||
(enqueue-msg "ERROR: Connection to daemon lost.")
|
||||
(setf *is-running* nil))))
|
||||
(when (string= cmd "/exit") (setf *is-running* nil))
|
||||
(when (string= cmd "/clear") (setf *chat-history* nil))))
|
||||
(enqueue-msg "ERROR: Connection to daemon lost.")
|
||||
(setf *is-running* nil))))
|
||||
(when (string= cmd "/exit") (setf *is-running* nil))
|
||||
(when (string= cmd "/clear") (setf *chat-history* nil))))
|
||||
#+end_src
|
||||
|
||||
** Background Reader
|
||||
@@ -151,12 +151,13 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
(getf payload :message))))
|
||||
(t
|
||||
(let ((text (or (getf payload :text) (format nil "~a" payload))))
|
||||
(enqueue-msg (format nil "⬇ ~a" text)))))))))
|
||||
(enqueue-msg (format nil "⬇ ~a" text))))))))))
|
||||
(error (c)
|
||||
(when *is-running*
|
||||
(enqueue-msg (format nil "ERROR: Connection lost (~a)" c))
|
||||
(setf *is-running* nil))))))
|
||||
:name "opencortex-tui-reader"))
|
||||
:name "opencortex-tui-reader")))
|
||||
)
|
||||
#+end_src
|
||||
|
||||
** Main Entry Point
|
||||
@@ -200,5 +201,5 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
||||
(error (c)
|
||||
(format t "TUI Error: ~a~%" c)))
|
||||
(setf *is-running* nil)
|
||||
(when *socket* (ignore-errors (usocket:socket-close *socket*)))))
|
||||
(when *socket* (ignore-errors (usocket:socket-close *socket*))))
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user